Skip to content

Commit

Permalink
Review feedback: re-structuring
Browse files Browse the repository at this point in the history
  • Loading branch information
e40pud committed Nov 21, 2024
1 parent 438de58 commit 0d2f181
Show file tree
Hide file tree
Showing 40 changed files with 350 additions and 235 deletions.
2 changes: 1 addition & 1 deletion packages/deeplinks/security/deep_links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export enum SecurityPageName {
rulesAdd = 'rules-add',
rulesCreate = 'rules-create',
rulesLanding = 'rules-landing',
rulesSiemMigrations = 'rules-siem-migrations',
siemMigrationsRules = 'siem_migrations-rules',
/*
* Warning: Computed values are not permitted in an enum with string valued members
* All threat intelligence page names must match `TIPageId` in x-pack/plugins/threat_intelligence/public/common/navigation/types.ts
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/security_solution/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ export const RULES_LANDING_PATH = `${RULES_PATH}/landing` as const;
export const RULES_ADD_PATH = `${RULES_PATH}/add_rules` as const;
export const RULES_UPDATES = `${RULES_PATH}/updates` as const;
export const RULES_CREATE_PATH = `${RULES_PATH}/create` as const;
export const SIEM_MIGRATIONS_PATH = `${RULES_PATH}/siem_migrations` as const;
export const EXCEPTIONS_PATH = '/exceptions' as const;
export const EXCEPTION_LIST_DETAIL_PATH = `${EXCEPTIONS_PATH}/details/:detailName` as const;
export const HOSTS_PATH = '/hosts' as const;
Expand Down Expand Up @@ -139,6 +138,8 @@ export const APP_BLOCKLIST_PATH = `${APP_PATH}${BLOCKLIST_PATH}` as const;
export const APP_RESPONSE_ACTIONS_HISTORY_PATH =
`${APP_PATH}${RESPONSE_ACTIONS_HISTORY_PATH}` as const;
export const NOTES_PATH = `${MANAGEMENT_PATH}/notes` as const;
export const SIEM_MIGRATIONS_PATH = '/siem_migrations' as const;
export const SIEM_MIGRATIONS_RULES_PATH = `${SIEM_MIGRATIONS_PATH}/rules` as const;

// cloud logs to exclude from default index pattern
export const EXCLUDE_ELASTIC_CLOUD_INDICES = ['-*elastic-cloud-logs-*'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ import { INTERNAL_ALERTING_API_FIND_RULES_PATH } from '@kbn/alerting-plugin/comm
import { BASE_ACTION_API_PATH } from '@kbn/actions-plugin/common';
import type { ActionType, AsApiContract } from '@kbn/actions-plugin/common';
import type { ActionResult } from '@kbn/actions-plugin/server';
import { replaceParams } from '@kbn/openapi-common/shared';
import type {
GetAllStatsRuleMigrationResponse,
GetRuleMigrationResponse,
} from '../../../../common/siem_migrations/model/api/rules/rule_migration.gen';
import {
SIEM_RULE_MIGRATIONS_ALL_STATS_PATH,
SIEM_RULE_MIGRATION_PATH,
} from '../../../../common/siem_migrations/constants';
import { convertRulesFilterToKQL } from '../../../../common/detection_engine/rule_management/rule_filtering';
import type {
UpgradeSpecificRulesRequest,
Expand Down Expand Up @@ -707,56 +698,3 @@ export const bootstrapPrebuiltRules = async (): Promise<BootstrapPrebuiltRulesRe
method: 'POST',
version: '1',
});

/**
* SIEM Rules Migration routes
*/

/**
* Retrieves the stats for all the existing migrations, aggregated by `migration_id`.
*
* @param signal AbortSignal for cancelling request
*
* @throws An error if response is not OK
*/
export const getRuleMigrationsStatsAll = async ({
signal,
}: {
signal: AbortSignal | undefined;
}): Promise<GetAllStatsRuleMigrationResponse> =>
KibanaServices.get().http.fetch<GetAllStatsRuleMigrationResponse>(
SIEM_RULE_MIGRATIONS_ALL_STATS_PATH,
{
method: 'GET',
version: '1',
signal,
}
);

/**
* Retrieves all the migration rule documents of a specific migration.
*
* @param migrationId `id` of the migration to retrieve rule documents for
* @param signal AbortSignal for cancelling request
*
* @throws An error if response is not OK
*/
export const getRuleMigrations = async ({
migrationId,
signal,
}: {
migrationId?: string;
signal: AbortSignal | undefined;
}): Promise<GetRuleMigrationResponse> => {
if (!migrationId) {
return [];
}
return KibanaServices.get().http.fetch<GetRuleMigrationResponse>(
replaceParams(SIEM_RULE_MIGRATION_PATH, { migration_id: migrationId }),
{
method: 'GET',
version: '1',
signal,
}
);
};

This file was deleted.

2 changes: 2 additions & 0 deletions x-pack/plugins/security_solution/public/lazy_sub_plugins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { EntityAnalytics } from './entity_analytics';
import { Assets } from './assets';
import { Investigations } from './investigations';
import { MachineLearning } from './machine_learning';
import { SiemMigrations } from './siem_migrations';

/**
* The classes used to instantiate the sub plugins. These are grouped into a single object for the sake of bundling them in a single dynamic import.
Expand All @@ -53,5 +54,6 @@ const subPluginClasses = {
Assets,
Investigations,
MachineLearning,
SiemMigrations,
};
export { subPluginClasses };
4 changes: 4 additions & 0 deletions x-pack/plugins/security_solution/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, S
assets: new subPluginClasses.Assets(),
investigations: new subPluginClasses.Investigations(),
machineLearning: new subPluginClasses.MachineLearning(),
siemMigrations: new subPluginClasses.SiemMigrations(),
};
}
return this._subPlugins;
Expand Down Expand Up @@ -279,6 +280,9 @@ export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, S
assets: subPlugins.assets.start(),
investigations: subPlugins.investigations.start(),
machineLearning: subPlugins.machineLearning.start(),
siemMigrations: subPlugins.siemMigrations.start(
this.experimentalFeatures.siemMigrationsEnabled
),
};
}

Expand Down
24 changes: 3 additions & 21 deletions x-pack/plugins/security_solution/public/rules/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
RULES_CREATE_PATH,
RULES_LANDING_PATH,
RULES_PATH,
SIEM_MIGRATIONS_PATH,
SERVER_APP_ID,
} from '../../common/constants';
import {
Expand All @@ -22,7 +21,6 @@ import {
CREATE_NEW_RULE,
EXCEPTIONS,
RULES,
SIEM_MIGRATIONS,
SIEM_RULES,
} from '../app/translations';
import { SecurityPageName } from '../app/types';
Expand All @@ -31,6 +29,7 @@ import type { LinkItem } from '../common/links';
import { IconConsoleCloud } from '../common/icons/console_cloud';
import { IconRollup } from '../common/icons/rollup';
import { IconDashboards } from '../common/icons/dashboards';
import { siemMigrationsLinks } from '../siem_migrations/links';

export const links: LinkItem = {
id: SecurityPageName.rulesLanding,
Expand Down Expand Up @@ -108,24 +107,7 @@ export const links: LinkItem = {
}),
],
},
{
id: SecurityPageName.rulesSiemMigrations,
title: SIEM_MIGRATIONS,
description: i18n.translate('xpack.securitySolution.appLinks.siemMigrationsDescription', {
defaultMessage: 'SIEM Rules Migrations.',
}),
landingIcon: IconConsoleCloud,
path: SIEM_MIGRATIONS_PATH,
capabilities: [`${SERVER_APP_ID}.show`],
skipUrlState: true,
hideTimeline: true,
globalSearchKeywords: [
i18n.translate('xpack.securitySolution.appLinks.siemMigrations', {
defaultMessage: 'SIEM Rules Migrations',
}),
],
experimentalKey: 'siemMigrationsEnabled',
},
siemMigrationsLinks,
],
categories: [
{
Expand All @@ -136,7 +118,7 @@ export const links: LinkItem = {
SecurityPageName.rules,
SecurityPageName.cloudSecurityPostureBenchmarks,
SecurityPageName.exceptions,
SecurityPageName.rulesSiemMigrations,
SecurityPageName.siemMigrationsRules,
],
},
{
Expand Down
72 changes: 28 additions & 44 deletions x-pack/plugins/security_solution/public/rules/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,54 +30,38 @@ import type { SecuritySubPluginRoutes } from '../app/types';
import { RulesLandingPage } from './landing';
import { CoverageOverviewPage } from '../detection_engine/rule_management_ui/pages/coverage_overview';
import { RuleDetailTabs } from '../detection_engine/rule_details_ui/pages/rule_details/use_rule_details_tabs';
import { SiemMigrationsPage } from '../detection_engine/rule_management_ui/pages/siem_migrations';
import { useIsSiemMigrationsEnabled } from '../detection_engine/rule_management_ui/hooks/use_is_siem_migrations_enabled';

const getRulesSubRoutes = (isSiemMigrationsEnabled: boolean) => {
return [
{
path: '/rules/id/:detailName/edit',
main: EditRulePage,
exact: true,
},
{
path: `/rules/id/:detailName/:tabName(${RuleDetailTabs.alerts}|${RuleDetailTabs.exceptions}|${RuleDetailTabs.endpointExceptions}|${RuleDetailTabs.executionResults}|${RuleDetailTabs.executionEvents})`,
main: RuleDetailsPage,
exact: true,
},
{
path: '/rules/create',
main: CreateRulePage,
exact: true,
},
{
path: `/rules/:tabName(${AllRulesTabs.management}|${AllRulesTabs.monitoring}|${AllRulesTabs.updates})`,
main: RulesPage,
exact: true,
},
{
path: '/rules/add_rules',
main: AddRulesPage,
exact: true,
},
...(isSiemMigrationsEnabled
? [
{
path: '/rules/siem_migrations',
main: SiemMigrationsPage,
exact: true,
},
]
: []),
];
};
const RulesSubRoutes = [
{
path: '/rules/id/:detailName/edit',
main: EditRulePage,
exact: true,
},
{
path: `/rules/id/:detailName/:tabName(${RuleDetailTabs.alerts}|${RuleDetailTabs.exceptions}|${RuleDetailTabs.endpointExceptions}|${RuleDetailTabs.executionResults}|${RuleDetailTabs.executionEvents})`,
main: RuleDetailsPage,
exact: true,
},
{
path: '/rules/create',
main: CreateRulePage,
exact: true,
},
{
path: `/rules/:tabName(${AllRulesTabs.management}|${AllRulesTabs.monitoring}|${AllRulesTabs.updates})`,
main: RulesPage,
exact: true,
},
{
path: '/rules/add_rules',
main: AddRulesPage,
exact: true,
},
];

const RulesContainerComponent: React.FC = () => {
useReadonlyHeader(i18n.READ_ONLY_BADGE_TOOLTIP);

const isSiemMigrationsEnabled = useIsSiemMigrationsEnabled();
const rulesSubRoutes = getRulesSubRoutes(isSiemMigrationsEnabled);

return (
<PluginTemplateWrapper>
<TrackApplicationView viewId={SecurityPageName.rules}>
Expand All @@ -103,7 +87,7 @@ const RulesContainerComponent: React.FC = () => {
<Route path="/rules" exact>
<Redirect to={`/rules/${AllRulesTabs.management}`} />
</Route>
{rulesSubRoutes.map((route) => (
{RulesSubRoutes.map((route) => (
<Route
key={`rules-route-${route.path}`}
path={route.path}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
export const PAGE_CONTENT_WIDTH = '1150px';

export enum OnboardingCardId {
integrations = 'integrations',
dashboards = 'dashboards',
rules = 'rules',
alerts = 'alerts',
assistant = 'assistant',
attackDiscovery = 'attack_discovery',
}
19 changes: 19 additions & 0 deletions x-pack/plugins/security_solution/public/siem_migrations/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { SecuritySubPlugin } from '../app/types';
import { routes } from './routes';

export class SiemMigrations {
public setup() {}

public start(isEnabled = false): SecuritySubPlugin {
return {
routes: isEnabled ? routes : [],
};
}
}
Loading

0 comments on commit 0d2f181

Please sign in to comment.