Skip to content

Commit

Permalink
clean external dependencies to security
Browse files Browse the repository at this point in the history
  • Loading branch information
semd committed May 23, 2023
1 parent 9c66663 commit eb7da12
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 201 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { cloudDefendPages } from './constants';
import { getSecuritySolutionLink, getSecuritySolutionNavTab } from './security_solution_links';
import { getSecuritySolutionLink } from './security_solution_links';
import { Chance } from 'chance';
import type { CloudDefendPage } from './types';

Expand All @@ -23,17 +23,3 @@ describe('getSecuritySolutionLink', () => {
expect(link.title).toEqual(cloudDefendPages[cloudDefendPage].name);
});
});

describe('getSecuritySolutionNavTab', () => {
it('gets the correct nav tab properties', () => {
const cloudDefendPage = chance.pickone<CloudDefendPage>(['policies']);
const basePath = chance.word();

const navTab = getSecuritySolutionNavTab(cloudDefendPage, basePath);

expect(navTab.id).toEqual(cloudDefendPages[cloudDefendPage].id);
expect(navTab.name).toEqual(cloudDefendPages[cloudDefendPage].name);
expect(navTab.href).toEqual(`${basePath}${cloudDefendPages[cloudDefendPage].path}`);
expect(navTab.disabled).toEqual(!!cloudDefendPages[cloudDefendPage].disabled);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ interface CloudDefendLinkItem<TId extends string = CloudDefendPageId> {
path: string;
}

interface CloudDefendNavTab<TId extends string = CloudDefendPageId> {
id: TId;
name: string;
href: string;
disabled: boolean;
}

/**
* Gets the cloud_defend link properties of a Cloud Defend page for navigation in the security solution.
* @param cloudDefendPage the name of the cloud defend page.
Expand All @@ -34,18 +27,3 @@ export const getSecuritySolutionLink = <TId extends string = CloudDefendPageId>(
path: cloudDefendPages[cloudDefendPage].path,
};
};

/**
* Gets the link properties of a Cloud Defend page for navigation in the old security solution navigation.
* @param cloudDefendPage the name of the cloud defend page.
* @param basePath the base path for links.
*/
export const getSecuritySolutionNavTab = <TId extends string = CloudDefendPageId>(
cloudDefendPage: CloudDefendPage,
basePath: string
): CloudDefendNavTab<TId> => ({
id: cloudDefendPages[cloudDefendPage].id as TId,
name: cloudDefendPages[cloudDefendPage].name,
href: `${basePath}${cloudDefendPages[cloudDefendPage].path}`,
disabled: !!cloudDefendPages[cloudDefendPage].disabled,
});
5 changes: 1 addition & 4 deletions x-pack/plugins/cloud_defend/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import { CloudDefendPlugin } from './plugin';

export type { CloudDefendSecuritySolutionContext } from './types';
export {
getSecuritySolutionLink,
getSecuritySolutionNavTab,
} from './common/navigation/security_solution_links';
export { getSecuritySolutionLink } from './common/navigation/security_solution_links';
export { CLOUD_DEFEND_BASE_PATH } from './common/navigation/constants';
export type { CloudDefendPageId } from './common/navigation/types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { cloudPosturePages } from './constants';
import { getSecuritySolutionLink, getSecuritySolutionNavTab } from './security_solution_links';
import { getSecuritySolutionLink } from './security_solution_links';
import { Chance } from 'chance';
import type { CspPage } from './types';

Expand All @@ -23,17 +23,3 @@ describe('getSecuritySolutionLink', () => {
expect(link.title).toEqual(cloudPosturePages[cspPage].name);
});
});

describe('getSecuritySolutionNavTab', () => {
it('gets the correct nav tab properties', () => {
const cspPage = chance.pickone<CspPage>(['dashboard', 'findings', 'benchmarks']);
const basePath = chance.word();

const navTab = getSecuritySolutionNavTab(cspPage, basePath);

expect(navTab.id).toEqual(cloudPosturePages[cspPage].id);
expect(navTab.name).toEqual(cloudPosturePages[cspPage].name);
expect(navTab.href).toEqual(`${basePath}${cloudPosturePages[cspPage].path}`);
expect(navTab.disabled).toEqual(!!cloudPosturePages[cspPage].disabled);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ interface CloudSecurityPostureLinkItem<TId extends string = CloudSecurityPosture
path: string;
}

interface CloudSecurityPostureNavTab<TId extends string = CloudSecurityPosturePageId> {
id: TId;
name: string;
href: string;
disabled: boolean;
}

/**
* Gets the cloud security posture link properties of a CSP page for navigation in the security solution.
* @param cloudSecurityPosturePage the name of the cloud posture page.
Expand All @@ -32,18 +25,3 @@ export const getSecuritySolutionLink = <TId extends string = CloudSecurityPostur
title: cloudPosturePages[cloudSecurityPosturePage].name,
path: cloudPosturePages[cloudSecurityPosturePage].path,
});

/**
* Gets the cloud security posture link properties of a CSP page for navigation in the old security solution navigation.
* @param cloudSecurityPosturePage the name of the cloud posture page.
* @param basePath the base path for links.
*/
export const getSecuritySolutionNavTab = <TId extends string = CloudSecurityPosturePageId>(
cloudSecurityPosturePage: CspPage,
basePath: string
): CloudSecurityPostureNavTab<TId> => ({
id: cloudPosturePages[cloudSecurityPosturePage].id as TId,
name: cloudPosturePages[cloudSecurityPosturePage].name,
href: `${basePath}${cloudPosturePages[cloudSecurityPosturePage].path}`,
disabled: !!cloudPosturePages[cloudSecurityPosturePage].disabled,
});
5 changes: 1 addition & 4 deletions x-pack/plugins/cloud_security_posture/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import { CspPlugin } from './plugin';
export type { CspSecuritySolutionContext } from './types';
export { CLOUD_SECURITY_POSTURE_BASE_PATH } from './common/navigation/constants';
export type { CloudSecurityPosturePageId } from './common/navigation/types';
export {
getSecuritySolutionLink,
getSecuritySolutionNavTab,
} from './common/navigation/security_solution_links';
export { getSecuritySolutionLink } from './common/navigation/security_solution_links';

export type { CspClientPluginSetup, CspClientPluginStart } from './types';

Expand Down
6 changes: 1 addition & 5 deletions x-pack/plugins/threat_intelligence/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ export { THREAT_INTELLIGENCE_BASE_PATH } from './constants/navigation';

export type { TIPageId } from './types';

export {
getSecuritySolutionDeepLink,
getSecuritySolutionLink,
getSecuritySolutionNavTab,
} from './utils/security_solution_links';
export { getSecuritySolutionLink } from './utils/security_solution_links';

export function plugin() {
return new ThreatIntelligencePlugin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,7 @@
*/

import { threatIntelligencePages } from '../constants/navigation';
import {
getSecuritySolutionDeepLink,
getSecuritySolutionLink,
getSecuritySolutionNavTab,
} from './security_solution_links';

describe('getSecuritySolutionDeepLink', () => {
it('gets the correct deeplink properties', () => {
const threatIntelligencePage = 'indicators';

const link = getSecuritySolutionDeepLink(threatIntelligencePage);

expect(link.id).toEqual(threatIntelligencePages[threatIntelligencePage].id);
expect(link.keywords).toEqual(threatIntelligencePages[threatIntelligencePage].keywords);
expect(link.path).toEqual(threatIntelligencePages[threatIntelligencePage].path);
expect(link.title).toEqual(threatIntelligencePages[threatIntelligencePage].newNavigationName);
});
});
import { getSecuritySolutionLink } from './security_solution_links';

describe('getSecuritySolutionLink', () => {
it('gets the correct link properties', () => {
Expand All @@ -40,19 +23,3 @@ describe('getSecuritySolutionLink', () => {
expect(link.title).toEqual(threatIntelligencePages[threatIntelligencePage].newNavigationName);
});
});

describe('getSecuritySolutionNavTab', () => {
it('gets the correct navtab properties', () => {
const threatIntelligencePage = 'indicators';
const basePath = 'threat_intelligence/';

const navTab = getSecuritySolutionNavTab(threatIntelligencePage, basePath);

expect(navTab.disabled).toEqual(threatIntelligencePages[threatIntelligencePage].disabled);
expect(navTab.href).toEqual(
`${basePath}${threatIntelligencePages[threatIntelligencePage].path}`
);
expect(navTab.id).toEqual(threatIntelligencePages[threatIntelligencePage].id);
expect(navTab.name).toEqual(threatIntelligencePages[threatIntelligencePage].oldNavigationName);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,6 @@
import { TIPage, TIPageId } from '../types';
import { threatIntelligencePages } from '../constants/navigation';

/**
* Properties used in the Security Solution plugin to enable deep linking.
* The properties come from SecuritySolutionDeepLink (x-pack/plugins/security_solution/public/app/deep_links/index.ts).
*
* If we want to control more from within the Threat Intelligence plugin, we can keep growing this interface.
*/
interface TIDeepLink<TId extends string = TIPageId> {
/**
* Optional keywords to match with in deep links search. Omit if this part of the hierarchy does not have a page URL.
*/
keywords?: string[];
/**
* Identifier to represent this sublink, should be unique for this application.
*/
id: TId;
/**
* URL path to access this link, relative to the application's appRoute.
*/
path: string;
/**
* Title to label represent this deep link.
**/
title: string;
}

/**
* Properties used in the Security Solution plugin to add links to the navigation.
* The properties come from LinkItem (x-pack/plugins/security_solution/public/common/links/types.ts).
Expand Down Expand Up @@ -62,45 +37,6 @@ interface TILinkItem<TId extends string = TIPageId> {
title: string;
}

/**
* Properties used in the Security Solution plugin to add links to the old navigation.
* The properties comes from NavTab (x-pack/plugins/security_solution/public/common/components/navigation/types.ts).
*
* If we want to control more from within the Threat Intelligence plugin, we can keep growing this interface.
*/
interface TINavTab<TId extends string = TIPageId> {
/**
* Nav tab id.
*/
id: TId;
/**
* Name displayed in the sidenav.
*/
name: string;
/**
* Page's path to navigate to when clicked.
*/
href: string;
/**
* Disables nav tab.
*/
disabled: boolean;
}

/**
* Gets the threat intelligence properties of a TI page for deep linking in the security solution.
* @param threatIntelligencePage the name of the threat intelligence page.
* @returns a {@link TIDeepLink}
*/
export const getSecuritySolutionDeepLink = <TId extends string = TIPageId>(
threatIntelligencePage: TIPage
): TIDeepLink<TId> => ({
id: threatIntelligencePages[threatIntelligencePage].id as TId,
title: threatIntelligencePages[threatIntelligencePage].newNavigationName,
path: threatIntelligencePages[threatIntelligencePage].path,
keywords: threatIntelligencePages[threatIntelligencePage].keywords,
});

/**
* Gets the threat intelligence properties of a TI page for navigation in the security solution.
* @param threatIntelligencePage the name of the threat intelligence page.
Expand All @@ -115,19 +51,3 @@ export const getSecuritySolutionLink = <TId extends string = TIPageId>(
description: threatIntelligencePages[threatIntelligencePage].description,
globalSearchKeywords: threatIntelligencePages[threatIntelligencePage].globalSearchKeywords,
});

/**
* Gets the threat intelligence properties of a TI page for navigation in the old security solution navigation.
* @param threatIntelligencePage the name of the threat intelligence page.
* @param basePath the base path for links.
* @returns a {@link TINavTab}
*/
export const getSecuritySolutionNavTab = <TId extends string = TIPageId>(
threatIntelligencePage: TIPage,
basePath: string
): TINavTab<TId> => ({
id: threatIntelligencePages[threatIntelligencePage].id as TId,
name: threatIntelligencePages[threatIntelligencePage].oldNavigationName,
href: `${basePath}${threatIntelligencePages[threatIntelligencePage].path}`,
disabled: threatIntelligencePages[threatIntelligencePage].disabled,
});

0 comments on commit eb7da12

Please sign in to comment.