Skip to content

Commit

Permalink
[TIP] Simplified TI plugin logic
Browse files Browse the repository at this point in the history
Plugin is now loaded all the time, and the logic to show the indicators page or route back to the Get Started page from Security is handled within the Threat Intelligence folder
  • Loading branch information
PhilippeOberti committed Aug 4, 2022
1 parent 346e397 commit 815f876
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
18 changes: 3 additions & 15 deletions x-pack/plugins/security_solution/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import type {
import { DEFAULT_APP_CATEGORIES, AppNavLinkStatus } from '@kbn/core/public';
import { Storage } from '@kbn/kibana-utils-plugin/public';
import type { TimelineState } from '@kbn/timelines-plugin/public';
import type { ThreatIntelligence } from './threat_intelligence';
import type {
PluginSetup,
PluginStart,
Expand Down Expand Up @@ -332,11 +331,8 @@ export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, S
management: new subPluginClasses.Management(),
landingPages: new subPluginClasses.LandingPages(),
cloudSecurityPosture: new subPluginClasses.CloudSecurityPosture(),
threatIntelligence: new subPluginClasses.ThreatIntelligence(),
};

if (this.experimentalFeatures.threatIntelligenceEnabled) {
this._subPlugins.threatIntelligence = new subPluginClasses.ThreatIntelligence();
}
}
return this._subPlugins;
}
Expand All @@ -350,8 +346,7 @@ export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, S
plugins: StartPlugins
): Promise<StartedSubPlugins> {
const subPlugins = await this.subPlugins();

const startPlugins: StartedSubPlugins = {
return {
overview: subPlugins.overview.start(),
alerts: subPlugins.alerts.start(storage),
cases: subPlugins.cases.start(),
Expand All @@ -365,15 +360,8 @@ export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, S
management: subPlugins.management.start(core, plugins),
landingPages: subPlugins.landingPages.start(),
cloudSecurityPosture: subPlugins.cloudSecurityPosture.start(),
threatIntelligence: subPlugins.threatIntelligence.start(),
};

if (this.experimentalFeatures.threatIntelligenceEnabled) {
startPlugins.threatIntelligence = (
subPlugins.threatIntelligence as ThreatIntelligence
).start();
}

return startPlugins;
}
/**
* Lazily instantiate a `SecurityAppStore`. We lazily instantiate this because it requests large dynamic imports. We instantiate it once because each subPlugin needs to share the same reference.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,29 @@
*/

import React from 'react';
import { Redirect } from 'react-router-dom';
import { TrackApplicationView } from '@kbn/usage-collection-plugin/public';
import { ThreatIntelligencePage } from './pages/threat_intelligence';
import { SecurityPageName, THREAT_INTELLIGENCE_PATH } from '../../common/constants';
import type { SecuritySubPluginRoutes } from '../app/types';
import { useIsExperimentalFeatureEnabled } from '../common/hooks/use_experimental_features';

const ThreatIntelligenceRoutes = () => (
<TrackApplicationView viewId={SecurityPageName.threatIntelligence}>
<ThreatIntelligencePage />
</TrackApplicationView>
);
const ThreatIntelligenceRoutes = () => {
const enabled = useIsExperimentalFeatureEnabled('threatIntelligenceEnabled');
if (!enabled) {
return <Redirect to="/" />;
}

return (
<TrackApplicationView viewId={SecurityPageName.threatIntelligence}>
<ThreatIntelligencePage />
</TrackApplicationView>
);
};

export const routes: SecuritySubPluginRoutes = [
{
path: THREAT_INTELLIGENCE_PATH,
render: ThreatIntelligenceRoutes,
component: ThreatIntelligenceRoutes,
},
];
4 changes: 2 additions & 2 deletions x-pack/plugins/security_solution/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export interface SubPlugins {
management: Management;
landingPages: LandingPages;
cloudSecurityPosture: CloudSecurityPosture;
threatIntelligence?: ThreatIntelligence; // the Threat Intelligence plugin is temporarily hidden behind a feature flag
threatIntelligence: ThreatIntelligence;
}

// TODO: find a better way to defined these types
Expand All @@ -148,5 +148,5 @@ export interface StartedSubPlugins {
management: ReturnType<Management['start']>;
landingPages: ReturnType<LandingPages['start']>;
cloudSecurityPosture: ReturnType<CloudSecurityPosture['start']>;
threatIntelligence?: ReturnType<ThreatIntelligence['start']>;
threatIntelligence: ReturnType<ThreatIntelligence['start']>;
}

0 comments on commit 815f876

Please sign in to comment.