Skip to content

Commit

Permalink
fix(serverSecurity): lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Desvelao committed Dec 10, 2024
1 parent c99104a commit 0f4be1d
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,10 @@ export const PromptCheckIndex = (props: {
);
};

const mapStateToProps = state => {
return {
vulnerabilitiesStatesindexPatternID:
state.appConfig.data['vulnerabilities.pattern'],
};
};
const mapStateToProps = state => ({
vulnerabilitiesStatesindexPatternID:
state.appConfig.data['vulnerabilities.pattern'],
});

export const withVulnerabilitiesStateDataSource = compose(
connect(mapStateToProps),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const initializationTask = {
export const INITIALIZATION_TASK = {
RUN_STATUS: {
NOT_STARTED: 'not_started',
RUNNING: 'running',
Expand Down
8 changes: 4 additions & 4 deletions plugins/wazuh-core/common/services/initialization/types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { initializationTask } from './constants';
import { INITIALIZATION_TASK } from './constants';

type RunStatusEnum = (typeof initializationTask)['RUN_STATUS'];
type RunStatusEnum = (typeof INITIALIZATION_TASK)['RUN_STATUS'];

export type InitializationTaskRunStatus = RunStatusEnum[keyof RunStatusEnum];

type RunResultEnum = (typeof initializationTask)['RUN_RESULT'];
type RunResultEnum = (typeof INITIALIZATION_TASK)['RUN_RESULT'];

export type InitializationTaskRunResult = RunResultEnum[keyof RunResultEnum];

type ContextEnum = (typeof initializationTask)['CONTEXT'];
type ContextEnum = (typeof INITIALIZATION_TASK)['CONTEXT'];

export type InitializationTaskContext = ContextEnum[keyof ContextEnum];
21 changes: 7 additions & 14 deletions plugins/wazuh-core/public/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { API_USER_STATUS_RUN_AS } from '../common/api-user-status-run-as';
import { Configuration } from '../common/services/configuration';
import { ServerSecurity } from './services';
import { ServerSecurity, ServerSecuritySetupReturn } from './services';
import { TableDataProps } from './components';
import { UseStateStorageHook } from './hooks';
import { UseDockedSideNav } from './hooks/use-docked-side-nav';
Expand All @@ -19,11 +19,8 @@ export interface WazuhCorePluginSetup {
serverSecurity: ServerSecurity;
hooks: {
useDockedSideNav: () => boolean;
// TODO: missing serverSecurity hooks
};
hocs: {
// TODO: missing serverSecurity hocs
};
} & ServerSecuritySetupReturn['hooks'];
hocs: {} & ServerSecuritySetupReturn['hocs'];
ui: {
TableData: <T>(
prop: TableDataProps<T>,
Expand All @@ -32,7 +29,7 @@ export interface WazuhCorePluginSetup {
ServerTable: <T>(
prop: ServerDataProps<T>,
) => React.ComponentType<ServerDataProps<T>>;
};
} & ServerSecuritySetupReturn['ui'];
}

export interface WazuhCorePluginStart {
Expand All @@ -45,11 +42,8 @@ export interface WazuhCorePluginStart {
hooks: {
useDockedSideNav: UseDockedSideNav;
useStateStorage: UseStateStorageHook; // TODO: enhance
// TODO: missing serverSecurity hooks
};
hocs: {
// TODO: missing serverSecurity hocs
};
} & ServerSecuritySetupReturn['hooks'];
hocs: {} & ServerSecuritySetupReturn['hocs'];
ui: {
TableData: <T>(
prop: TableDataProps<T>,
Expand All @@ -58,8 +52,7 @@ export interface WazuhCorePluginStart {
ServerTable: <T>(
prop: ServerDataProps<T>,
) => React.ComponentType<ServerDataProps<T>>;
// TODO: missing serverSecurity UI
};
} & ServerSecuritySetupReturn['ui'];
}

export type AppPluginStartDependencies = object;
60 changes: 29 additions & 31 deletions plugins/wazuh-core/server/initialization/index-patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,34 +221,32 @@ export const initializationTaskCreatorIndexPattern = ({
taskName: string;
options: object;
configurationSettingKey: string;
}) => {
return {
name: taskName,
async run(ctx: InitializationTaskRunContext) {
let indexPatternID;

try {
ctx.logger.debug('Starting index pattern saved object');
indexPatternID = await getIndexPatternID(ctx, ctx.scope, rest);

// Get clients depending on the scope
const savedObjectsClient = getSavedObjectsClient(ctx, ctx.scope);
const indexPatternsClient = getIndexPatternsClient(ctx, ctx.scope);

return await ensureIndexPatternExistence(
{ ...ctx, indexPatternsClient, savedObjectsClient },
{
indexPatternID,
options,
configurationSettingKey,
},
);
} catch (error) {
const message = `Error initilizating index pattern with ID [${indexPatternID}]: ${error.message}`;

ctx.logger.error(message);
throw new Error(message);
}
},
};
};
}) => ({
name: taskName,
async run(ctx: InitializationTaskRunContext) {
let indexPatternID;

try {
ctx.logger.debug('Starting index pattern saved object');
indexPatternID = await getIndexPatternID(ctx, ctx.scope, rest);

// Get clients depending on the scope
const savedObjectsClient = getSavedObjectsClient(ctx, ctx.scope);
const indexPatternsClient = getIndexPatternsClient(ctx, ctx.scope);

return await ensureIndexPatternExistence(
{ ...ctx, indexPatternsClient, savedObjectsClient },
{
indexPatternID,
options,
configurationSettingKey,
},
);
} catch (error) {
const message = `Error initilizating index pattern with ID [${indexPatternID}]: ${error.message}`;

ctx.logger.error(message);
throw new Error(message);
}
},
});
12 changes: 5 additions & 7 deletions plugins/wazuh-core/server/initialization/server-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,11 @@ describe('serverAPIConnectionCompatibility', () => {
},
serverAPIClient: {
asInternalUser: {
request: () => {
return {
data: {
data: apiVersionResponse,
},
};
},
request: () => ({
data: {
data: apiVersionResponse,
},
}),
},
},
},
Expand Down
48 changes: 23 additions & 25 deletions plugins/wazuh-core/server/initialization/server-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,28 +108,26 @@ export const initializationTaskCreatorServerAPIConnectionCompatibility = ({
taskName,
}: {
taskName: string;
}) => {
return {
name: taskName,
async run(ctx: InitializationTaskRunContext) {
try {
ctx.logger.debug(
'Starting check server API connection and compatibility',
);

const results = await serversAPIConnectionCompatibility(ctx);

ctx.logger.info(
'Start check server API connection and compatibility finished',
);

return results;
} catch (error) {
const message = `Error checking server API connection and compatibility: ${error.message}`;

ctx.logger.error(message);
throw new Error(message);
}
},
};
};
}) => ({
name: taskName,
async run(ctx: InitializationTaskRunContext) {
try {
ctx.logger.debug(
'Starting check server API connection and compatibility',
);

const results = await serversAPIConnectionCompatibility(ctx);

ctx.logger.info(
'Start check server API connection and compatibility finished',
);

return results;
} catch (error) {
const message = `Error checking server API connection and compatibility: ${error.message}`;

ctx.logger.error(message);
throw new Error(message);
}
},
});
72 changes: 35 additions & 37 deletions plugins/wazuh-core/server/initialization/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,41 +167,39 @@ function getUiSettingsClient(
export const initializationTaskCreatorSetting = (
setting: { key: string; value: any; configurationSetting: string },
taskName: string,
) => {
return {
name: taskName,
async run(ctx: InitializationTaskRunContext) {
try {
ctx.logger.debug('Starting setting');

// Get clients depending on the scope
const savedObjectsClient = getSavedObjectsClient(ctx, ctx.scope);
const uiSettingsClient = getUiSettingsClient(
ctx,
ctx.scope,
savedObjectsClient,
);
const { key, value, configurationSetting } = setting;

await checkPluginPlatformSettings(
{
logger: ctx.logger,
uiSettingsClient,
configuration: ctx.configuration,
},
{
key,
value,
configurationSetting,
},
);
ctx.logger.info('Start setting finished');
} catch (error) {
const message = `Error initilizating setting [${setting.key}]: ${error.message}`;
) => ({
name: taskName,
async run(ctx: InitializationTaskRunContext) {
try {
ctx.logger.debug('Starting setting');

// Get clients depending on the scope
const savedObjectsClient = getSavedObjectsClient(ctx, ctx.scope);
const uiSettingsClient = getUiSettingsClient(
ctx,
ctx.scope,
savedObjectsClient,
);
const { key, value, configurationSetting } = setting;

ctx.logger.error(message);
throw new Error(message);
}
},
};
};
await checkPluginPlatformSettings(
{
logger: ctx.logger,
uiSettingsClient,
configuration: ctx.configuration,
},
{
key,
value,
configurationSetting,
},
);
ctx.logger.info('Start setting finished');
} catch (error) {
const message = `Error initilizating setting [${setting.key}]: ${error.message}`;

ctx.logger.error(message);
throw new Error(message);
}
},
});
50 changes: 24 additions & 26 deletions plugins/wazuh-core/server/initialization/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,29 +82,27 @@ export const initializationTaskCreatorExistTemplate = ({
getOpenSearchClient: (ctx: InitializationTaskRunContext) => any;
getIndexPatternTitle: (ctx: InitializationTaskRunContext) => Promise<string>;
taskName: string;
}) => {
return {
name: taskName,
async run(ctx: InitializationTaskRunContext) {
let indexPatternTitle;

try {
ctx.logger.debug('Starting check of existent template');

const opensearchClient = getOpenSearchClient(ctx);

indexPatternTitle = await getIndexPatternTitle(ctx);
await checkIndexPatternHasTemplate(ctx, {
opensearchClient,
indexPatternTitle,
});
ctx.logger.info('Start check of existent template finished');
} catch (error) {
const message = `Error checking of existent template for index pattern with title [${indexPatternTitle}]: ${error.message}`;

ctx.logger.error(message);
throw new Error(message);
}
},
};
};
}) => ({
name: taskName,
async run(ctx: InitializationTaskRunContext) {
let indexPatternTitle;

try {
ctx.logger.debug('Starting check of existent template');

const opensearchClient = getOpenSearchClient(ctx);

indexPatternTitle = await getIndexPatternTitle(ctx);
await checkIndexPatternHasTemplate(ctx, {
opensearchClient,
indexPatternTitle,
});
ctx.logger.info('Start check of existent template finished');
} catch (error) {
const message = `Error checking of existent template for index pattern with title [${indexPatternTitle}]: ${error.message}`;

ctx.logger.error(message);
throw new Error(message);
}
},
});
Loading

0 comments on commit 0f4be1d

Please sign in to comment.