Skip to content

Commit 89c7749

Browse files
committed
feat: create connstant for security config
1 parent efecdb2 commit 89c7749

File tree

5 files changed

+61
-50
lines changed

5 files changed

+61
-50
lines changed

src/Shared/Components/Security/SecurityDetailsCards/SecurityDetailsCards.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const SecurityDetailsCards = ({ scanResult, Sidebar }: SecurityDetailsCardsProps
3636
}
3737
}
3838

39-
const handleCardClick = (
39+
const handleOpenModal = (
4040
category: SecurityCardProps['category'],
4141
subCategory: SecurityCardProps['subCategory'],
4242
) => {
@@ -48,17 +48,18 @@ const SecurityDetailsCards = ({ scanResult, Sidebar }: SecurityDetailsCardsProps
4848
})
4949
}
5050

51+
const handleCardClick =
52+
(category: SecurityCardProps['category'], subCategory: SecurityCardProps['subCategory']) => () =>
53+
handleOpenModal(category, subCategory)
54+
5155
const handleModalClose = () => {
5256
setShowSecurityModal(false)
5357
}
5458

5559
return (
5660
<>
5761
<div className="flexbox-col dc__gap-20">
58-
{Object.values(CATEGORIES).map((category: ScanCategories) => {
59-
if (!SECURITY_CONFIG[category]) {
60-
return null
61-
}
62+
{Object.keys(SECURITY_CONFIG).map((category: ScanCategories) => {
6263
const scanToolId = getScanToolId(category)
6364
return (
6465
<div className="flexbox-col dc__gap-12" key={category}>
@@ -78,7 +79,7 @@ const SecurityDetailsCards = ({ scanResult, Sidebar }: SecurityDetailsCardsProps
7879
category={category}
7980
subCategory={subCategory}
8081
severityCount={severityCount}
81-
handleCardClick={() => handleCardClick(category, subCategory)}
82+
handleCardClick={handleCardClick(category, subCategory)}
8283
/>
8384
)
8485
})}

src/Shared/Components/Security/Vulnerabilities/Vulnerabilities.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,29 @@ const Vulnerabilities = ({
5555
)
5656
}
5757

58-
if (!isScanEnabled || !scanResultResponse?.result?.isImageScanEnabled) {
58+
if (scanResultError) {
5959
return (
6060
<div className="security-tab-empty">
61-
<p className="security-tab-empty__title">Scan is Disabled</p>
61+
<p className="security-tab-empty__title">Failed to fetch vulnerabilities</p>
62+
<button className="cta secondary" type="button" onClick={reloadScanResult}>
63+
Reload
64+
</button>
6265
</div>
6366
)
6467
}
6568

66-
if (!isScanned || (scanResultResponse && !scanResultResponse.result.scanned)) {
69+
if (!isScanEnabled || !scanResultResponse.result?.isImageScanEnabled) {
6770
return (
6871
<div className="security-tab-empty">
69-
<p className="security-tab-empty__title">Image was not scanned</p>
72+
<p className="security-tab-empty__title">Scan is Disabled</p>
7073
</div>
7174
)
7275
}
7376

74-
if (scanResultError) {
77+
if (!isScanned || !scanResultResponse.result?.scanned) {
7578
return (
7679
<div className="security-tab-empty">
77-
<p className="security-tab-empty__title">Failed to fetch vulnerabilities</p>
78-
<button className="cta secondary" type="button" onClick={reloadScanResult}>
79-
Reload
80-
</button>
80+
<p className="security-tab-empty__title">Image was not scanned</p>
8181
</div>
8282
)
8383
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { CATEGORY_LABELS } from './SecurityModal'
2+
import { CATEGORIES, SUB_CATEGORIES } from './SecurityModal/types'
3+
import { SecurityConfigType } from './types'
4+
5+
export const SECURITY_CONFIG: SecurityConfigType = {
6+
[CATEGORIES.IMAGE_SCAN]: {
7+
label: CATEGORY_LABELS.IMAGE_SCAN,
8+
subCategories: [SUB_CATEGORIES.VULNERABILITIES, SUB_CATEGORIES.LICENSE],
9+
},
10+
[CATEGORIES.CODE_SCAN]: {
11+
label: CATEGORY_LABELS.CODE_SCAN,
12+
subCategories: [
13+
SUB_CATEGORIES.VULNERABILITIES,
14+
SUB_CATEGORIES.LICENSE,
15+
SUB_CATEGORIES.MISCONFIGURATIONS,
16+
SUB_CATEGORIES.EXPOSED_SECRETS,
17+
],
18+
},
19+
[CATEGORIES.KUBERNETES_MANIFEST]: {
20+
label: CATEGORY_LABELS.KUBERNETES_MANIFEST,
21+
subCategories: [SUB_CATEGORIES.MISCONFIGURATIONS, SUB_CATEGORIES.EXPOSED_SECRETS],
22+
},
23+
}

src/Shared/Components/Security/types.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface SecurityConfigCategoryType {
1414
subCategories: ScanSubCategories[]
1515
}
1616

17-
export interface GetSecurityConfigReturnType {
17+
export interface SecurityConfigType {
1818
imageScan?: SecurityConfigCategoryType
1919
codeScan?: SecurityConfigCategoryType
2020
kubernetesManifest?: SecurityConfigCategoryType

src/Shared/Components/Security/utils.tsx

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { CATEGORY_LABELS, ScanResultDTO, SeveritiesDTO } from './SecurityModal'
1+
import { SECURITY_CONFIG } from './constants'
2+
import { ScanResultDTO, SeveritiesDTO } from './SecurityModal'
23
import { CATEGORIES, SUB_CATEGORIES } from './SecurityModal/types'
3-
import { CategoriesConfig, GetSecurityConfigReturnType, ScanCategories, ScanSubCategories } from './types'
4+
import { CategoriesConfig, SecurityConfigType, ScanCategories, ScanSubCategories } from './types'
45

56
export const getCVEUrlFromCVEName = (cveName: string): string =>
67
`https://cve.mitre.org/cgi-bin/cvename.cgi?name=${cveName}`
@@ -10,48 +11,34 @@ export const getTotalSeverities = (severityCount: Partial<Record<SeveritiesDTO,
1011
.filter(([key]) => key !== SeveritiesDTO.SUCCESSES)
1112
.reduce((acc, [, value]) => acc + value, 0)
1213

13-
export const getSecurityConfig = (categoriesConfig: CategoriesConfig): GetSecurityConfigReturnType => {
14-
const { imageScan, codeScan, kubernetesManifest } = categoriesConfig
15-
16-
return {
17-
...(imageScan && {
18-
[CATEGORIES.IMAGE_SCAN]: {
19-
label: CATEGORY_LABELS.IMAGE_SCAN,
20-
subCategories: [SUB_CATEGORIES.VULNERABILITIES, SUB_CATEGORIES.LICENSE],
21-
},
22-
}),
23-
...(codeScan && {
24-
[CATEGORIES.CODE_SCAN]: {
25-
label: CATEGORY_LABELS.CODE_SCAN,
26-
subCategories: [
27-
SUB_CATEGORIES.VULNERABILITIES,
28-
SUB_CATEGORIES.LICENSE,
29-
SUB_CATEGORIES.MISCONFIGURATIONS,
30-
SUB_CATEGORIES.EXPOSED_SECRETS,
31-
],
32-
},
33-
}),
34-
...(kubernetesManifest && {
35-
[CATEGORIES.KUBERNETES_MANIFEST]: {
36-
label: CATEGORY_LABELS.KUBERNETES_MANIFEST,
37-
subCategories: [SUB_CATEGORIES.MISCONFIGURATIONS, SUB_CATEGORIES.EXPOSED_SECRETS],
38-
},
39-
}),
40-
}
41-
}
14+
export const getSecurityConfig = ({
15+
imageScan,
16+
codeScan,
17+
kubernetesManifest,
18+
}: CategoriesConfig): SecurityConfigType => ({
19+
...(imageScan && {
20+
[CATEGORIES.IMAGE_SCAN]: SECURITY_CONFIG.imageScan,
21+
}),
22+
...(codeScan && {
23+
[CATEGORIES.CODE_SCAN]: SECURITY_CONFIG.codeScan,
24+
}),
25+
...(kubernetesManifest && {
26+
[CATEGORIES.KUBERNETES_MANIFEST]: SECURITY_CONFIG.kubernetesManifest,
27+
}),
28+
})
4229

4330
export const getSecurityThreatsArray = (scanResult: ScanResultDTO): Partial<Record<SeveritiesDTO, number>>[] => {
4431
const { imageScan, codeScan, kubernetesManifest } = scanResult
45-
const SECURITY_CONFIG = getSecurityConfig({
32+
const DYNAMIC_SECURITY_CONFIG = getSecurityConfig({
4633
imageScan: !!imageScan,
4734
codeScan: !!codeScan,
4835
kubernetesManifest: !!kubernetesManifest,
4936
})
5037

5138
const threatsArray: Partial<Record<SeveritiesDTO, number>>[] = []
5239

53-
Object.keys(SECURITY_CONFIG).forEach((category: ScanCategories) => {
54-
SECURITY_CONFIG[category].subCategories.forEach((subCategory: ScanSubCategories) => {
40+
Object.keys(DYNAMIC_SECURITY_CONFIG).forEach((category: ScanCategories) => {
41+
DYNAMIC_SECURITY_CONFIG[category].subCategories.forEach((subCategory: ScanSubCategories) => {
5542
const severity =
5643
subCategory === SUB_CATEGORIES.MISCONFIGURATIONS
5744
? scanResult[category][subCategory]?.misConfSummary?.status

0 commit comments

Comments
 (0)