Skip to content

Commit

Permalink
feat(ThreatPacks): Add threat packs and mitigation packs support
Browse files Browse the repository at this point in the history
  • Loading branch information
jessieweiyi committed Jul 9, 2024
1 parent 61022ac commit 13be704
Show file tree
Hide file tree
Showing 22 changed files with 3,505 additions and 229 deletions.
14 changes: 12 additions & 2 deletions .projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 3 additions & 11 deletions packages/threat-composer-app/src/containers/AppLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
******************************************************************************************************************** */
import {
DEFAULT_WORKSPACE_ID,
useGlobalSetupContext,
} from '@aws/threat-composer';
import { SideNavigationProps } from '@cloudscape-design/components/side-navigation';
import { FC, PropsWithChildren, useMemo } from 'react';
Expand Down Expand Up @@ -46,12 +45,6 @@ const AppLayout: FC<PropsWithChildren<{}>> = ({
const notifications = useNotifications();
const [searchParams] = useSearchParams();

const { features } = useGlobalSetupContext();

const isThreatPackFeatureOn = useMemo(() => {
return features.includes('threatPacks');
}, [features]);

const navigationItems: SideNavigationProps.Item[] = useMemo(() => {
const navItems: SideNavigationProps.Item[] = [
{
Expand Down Expand Up @@ -95,8 +88,6 @@ const AppLayout: FC<PropsWithChildren<{}>> = ({
href: generateUrl(ROUTE_VIEW_THREAT_MODEL_PATH, searchParams, workspaceId),
type: 'link',
},
];
return isThreatPackFeatureOn ? navItems.concat([
{ type: 'divider' },
{
type: 'section',
Expand All @@ -114,9 +105,10 @@ const AppLayout: FC<PropsWithChildren<{}>> = ({
},
],
},
]) : navItems;
];

}, [searchParams, workspaceId, isThreatPackFeatureOn]);
return navItems;
}, [searchParams, workspaceId]);

return (<AppLayoutComponent
title='threat-composer'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
limitations under the License.
******************************************************************************************************************** */
import Container from '@cloudscape-design/components/container';
import Header from '@cloudscape-design/components/header';
import { FC } from 'react';
import { MitigationPack } from '../../../../../customTypes';

Expand All @@ -25,15 +24,7 @@ export interface GeneralInfoProps {
const GeneralInfo: FC<GeneralInfoProps> = ({
mitigationPack,
}) => {
return (<Container
header={
<Header
variant="h2"
>
Mitigation Pack - {mitigationPack.name}
</Header>
}
>
return (<Container>
{mitigationPack.description}
</Container>);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
limitations under the License.
******************************************************************************************************************** */
import Button from '@cloudscape-design/components/button';
import ContentLayout from '@cloudscape-design/components/content-layout';
import Header from '@cloudscape-design/components/header';
import SpaceBetween from '@cloudscape-design/components/space-between';
import { useMemo, FC, useCallback, useState } from 'react';
import GeneralInfo from './components/GeneralInfo';
Expand Down Expand Up @@ -92,18 +94,24 @@ const MitigationPack: FC<MitigationPackProp> = ({
return null;
}

return (<SpaceBetween direction='vertical' size='s'>
<GeneralInfo mitigationPack={mitigationPack} />
<Table
columnDefinitions={colDef}
actions={actions}
header="Mitigations"
items={mitigationPack.mitigations || []}
wrapLines={true}
isItemDisabled={isItemDisabled}
selectedItems={totalSelectedItems}
onSelectionChange={({ detail }) => setSelectedItems([...detail.selectedItems])}
/></SpaceBetween>);
return (<ContentLayout header={
<Header
variant="h2"
>
Mitigation Pack - {mitigationPack.name}
</Header>
}><SpaceBetween direction='vertical' size='s'>
<GeneralInfo mitigationPack={mitigationPack} />
<Table
columnDefinitions={colDef}
actions={actions}
header="Mitigations"
items={mitigationPack.mitigations || []}
wrapLines={true}
isItemDisabled={isItemDisabled}
selectedItems={totalSelectedItems}
onSelectionChange={({ detail }) => setSelectedItems([...detail.selectedItems])}
/></SpaceBetween></ContentLayout>);
};

export default MitigationPack;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
******************************************************************************************************************** */
import Box from '@cloudscape-design/components/box';
import Button from '@cloudscape-design/components/button';
import ContentLayout from '@cloudscape-design/components/content-layout';
import Header from '@cloudscape-design/components/header';
import SpaceBetween from '@cloudscape-design/components/space-between';
import { FC, useMemo } from 'react';
import GeneralInfo from './components/GeneralInfo';
import { useMitigationPacksContext } from '../../../contexts/MitigationPacksContext';
import { MitigationPack } from '../../../customTypes/referencePacks';
import Table, { ColumnDefinition } from '../../generic/Table';


export interface MitigationPacksProps {
onMitigationPackLinkClicked?: (id: string) => void;
}
Expand All @@ -34,7 +36,7 @@ const MitigationPacks: FC<MitigationPacksProps> = ({
const colDef: ColumnDefinition<MitigationPack>[] = useMemo(() => [
{
id: 'id',
minWidth: 100,
minWidth: 150,
header: 'Id',
cell: (data) => (<Button variant="inline-link" onClick={() => onMitigationPackLinkClicked?.(data.id)}>
{data.id}
Expand Down Expand Up @@ -68,16 +70,21 @@ const MitigationPacks: FC<MitigationPacksProps> = ({
},
], [mitigationPackUsage, onMitigationPackLinkClicked]);

return (<SpaceBetween direction='vertical' size='s'>
<GeneralInfo />
<Table
columnDefinitions={colDef}
header="Mitigation packs"
items={mitigationPacks}
disableRowSelect={true}
wrapLines={true}

/></SpaceBetween>);
return (<ContentLayout header={<Header
variant="h2"
description="Allow you to quickly find and add bulk or selected mitigation candidates to your current workspace"
counter={`(${mitigationPacks.length})`}
>
Mitigation Packs
</Header>}>
<SpaceBetween direction='vertical' size='s'>
<Table
columnDefinitions={colDef}
items={mitigationPacks}
disableRowSelect={true}
wrapLines={true}
/></SpaceBetween>
</ContentLayout>);
};

export default MitigationPacks;
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
limitations under the License.
******************************************************************************************************************** */
import Container from '@cloudscape-design/components/container';
import Header from '@cloudscape-design/components/header';
import { FC } from 'react';
import { ThreatPack } from '../../../../../customTypes';

Expand All @@ -25,15 +24,7 @@ export interface GeneralInfoProps {
const GeneralInfo: FC<GeneralInfoProps> = ({
threatPack,
}) => {
return (<Container
header={
<Header
variant="h2"
>
Threat Pack - {threatPack.name}
</Header>
}
>
return (<Container>
{threatPack.description}
</Container>);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
limitations under the License.
******************************************************************************************************************** */
import Button from '@cloudscape-design/components/button';
import ContentLayout from '@cloudscape-design/components/content-layout';
import Header from '@cloudscape-design/components/header';
import SpaceBetween from '@cloudscape-design/components/space-between';
import TextContent from '@cloudscape-design/components/text-content';
import { useMemo, FC, useCallback, useState } from 'react';
Expand Down Expand Up @@ -137,18 +139,28 @@ const ThreatPack: FC<ThreatPackProp> = ({
return null;
}

return (<SpaceBetween direction='vertical' size='s'>
<GeneralInfo threatPack={threatPack} />
<Table
columnDefinitions={colDef}
actions={actions}
header="Threats"
items={threatPack.threats || []}
wrapLines={true}
isItemDisabled={isItemDisabled}
selectedItems={totalSelectedItems}
onSelectionChange={({ detail }) => setSelectedItems([...detail.selectedItems])}
/></SpaceBetween>);
return (<ContentLayout
header={
<Header
variant="h2"
>
Threat Pack - {threatPack.name}
</Header>
}
>
<SpaceBetween direction='vertical' size='s'>
<GeneralInfo threatPack={threatPack} />
<Table
columnDefinitions={colDef}
actions={actions}
header="Threats"
items={threatPack.threats || []}
wrapLines={true}
isItemDisabled={isItemDisabled}
selectedItems={totalSelectedItems}
onSelectionChange={({ detail }) => setSelectedItems([...detail.selectedItems])}
/></SpaceBetween>
</ContentLayout>);
};

export default ThreatPack;

This file was deleted.

Loading

0 comments on commit 13be704

Please sign in to comment.