@@ -6,18 +6,35 @@ import { CATEGORIES, SecurityModalStateType, SUB_CATEGORIES } from '../SecurityM
6
6
import { SecurityCardProps , SecurityDetailsCardsProps } from './types'
7
7
import { SecurityModal } from '../SecurityModal'
8
8
import { DEFAULT_SECURITY_MODAL_IMAGE_STATE } from '../SecurityModal/constants'
9
- import { ScanSubCategories } from '../types'
9
+ import { ScanCategories , ScanSubCategories } from '../types'
10
10
import './securityCard.scss'
11
+ import { getSecurityConfig } from '../utils'
11
12
12
13
const SecurityDetailsCards = ( { scanResult, Sidebar } : SecurityDetailsCardsProps ) => {
13
14
const [ showSecurityModal , setShowSecurityModal ] = useState < boolean > ( false )
14
15
const [ modalState , setModalState ] = useState < SecurityModalStateType > ( DEFAULT_SECURITY_MODAL_IMAGE_STATE )
15
16
const { imageScan, codeScan, kubernetesManifest } = scanResult
16
17
17
- const imageScanToolId =
18
- imageScan ?. vulnerability ?. list ?. [ 0 ] . scanToolName === 'TRIVY' ? SCAN_TOOL_ID_TRIVY : SCAN_TOOL_ID_CLAIR
19
- const codeScanToolId = codeScan ?. scanToolName === 'TRIVY' ? SCAN_TOOL_ID_TRIVY : SCAN_TOOL_ID_CLAIR
20
- const manifestScanToolId = kubernetesManifest ?. scanToolName === 'TRIVY' ? SCAN_TOOL_ID_TRIVY : SCAN_TOOL_ID_CLAIR
18
+ const SECURITY_CONFIG = getSecurityConfig ( {
19
+ imageScan : ! ! imageScan ,
20
+ codeScan : ! ! codeScan ,
21
+ kubernetesManifest : ! ! kubernetesManifest ,
22
+ } )
23
+
24
+ const getScanToolId = ( category : string ) => {
25
+ switch ( category ) {
26
+ case CATEGORIES . CODE_SCAN :
27
+ return codeScan ?. scanToolName === 'TRIVY' ? SCAN_TOOL_ID_TRIVY : SCAN_TOOL_ID_CLAIR
28
+ case CATEGORIES . KUBERNETES_MANIFEST :
29
+ return kubernetesManifest ?. scanToolName === 'TRIVY' ? SCAN_TOOL_ID_TRIVY : SCAN_TOOL_ID_CLAIR
30
+ case CATEGORIES . IMAGE_SCAN :
31
+ return imageScan ?. vulnerability ?. list ?. [ 0 ] . scanToolName === 'TRIVY'
32
+ ? SCAN_TOOL_ID_TRIVY
33
+ : SCAN_TOOL_ID_CLAIR
34
+ default :
35
+ return SCAN_TOOL_ID_TRIVY
36
+ }
37
+ }
21
38
22
39
const handleCardClick = (
23
40
category : SecurityCardProps [ 'category' ] ,
@@ -35,91 +52,40 @@ const SecurityDetailsCards = ({ scanResult, Sidebar }: SecurityDetailsCardsProps
35
52
setShowSecurityModal ( false )
36
53
}
37
54
38
- const isValidSubCategory = ( subCategory : ScanSubCategories ) : boolean =>
39
- Object . values ( SUB_CATEGORIES ) . includes ( subCategory )
40
-
41
55
return (
42
56
< >
43
57
< div className = "flexbox-col dc__gap-20" >
44
- { imageScan ? (
45
- < div className = "flexbox-col dc__gap-12" >
46
- < div className = "flexbox dc__content-space pb-8 dc__border-bottom-n1" >
47
- < span className = "fs-13 fw-6 lh-1-5 cn-9" > Image Scan</ span >
48
- < ScannedByToolModal scanToolId = { imageScanToolId } />
49
- </ div >
50
- < div className = "dc__grid security-cards" >
51
- { Object . keys ( imageScan ) . map ( ( subCategory : SecurityCardProps [ 'subCategory' ] ) => {
52
- if ( ! isValidSubCategory ( subCategory ) ) {
53
- return null
54
- }
55
- return (
56
- < SecurityCard
57
- category = { CATEGORIES . IMAGE_SCAN }
58
- subCategory = { subCategory }
59
- severityCount = { imageScan [ subCategory ] ?. summary . severities }
60
- handleCardClick = { ( ) => handleCardClick ( CATEGORIES . IMAGE_SCAN , subCategory ) }
61
- />
62
- )
63
- } ) }
64
- </ div >
65
- </ div >
66
- ) : null }
67
- { codeScan ? (
68
- < div className = "flexbox-col dc__gap-12" >
69
- < div className = "flexbox dc__content-space pb-8 dc__border-bottom-n1" >
70
- < span className = "fs-13 fw-6 lh-1-5 cn-9" > Code Scan</ span >
71
- < ScannedByToolModal scanToolId = { codeScanToolId } />
72
- </ div >
73
- < div className = "dc__grid security-cards" >
74
- { Object . keys ( codeScan ) . map ( ( subCategory : SecurityCardProps [ 'subCategory' ] ) => {
75
- if ( ! isValidSubCategory ( subCategory ) ) {
76
- return null
77
- }
78
- const severityCount =
79
- subCategory === 'misConfigurations'
80
- ? codeScan . misConfigurations ?. misConfSummary ?. status
81
- : codeScan [ subCategory ] ?. summary ?. severities
82
- return (
83
- < SecurityCard
84
- category = { CATEGORIES . CODE_SCAN }
85
- subCategory = { subCategory }
86
- severityCount = { severityCount }
87
- handleCardClick = { ( ) => handleCardClick ( CATEGORIES . CODE_SCAN , subCategory ) }
88
- />
89
- )
90
- } ) }
91
- </ div >
92
- </ div >
93
- ) : null }
94
- { kubernetesManifest ? (
95
- < div className = "flexbox-col dc__gap-12" >
96
- < div className = "flexbox dc__content-space pb-8 dc__border-bottom-n1" >
97
- < span className = "fs-13 fw-6 lh-1-5 cn-9" > Manifest Scan</ span >
98
- < ScannedByToolModal scanToolId = { manifestScanToolId } />
99
- </ div >
100
- < div className = "dc__grid security-cards" >
101
- { Object . keys ( kubernetesManifest ) . map ( ( subCategory : SecurityCardProps [ 'subCategory' ] ) => {
102
- if ( ! isValidSubCategory ( subCategory ) ) {
103
- return null
104
- }
105
- const severityCount =
106
- subCategory === 'misConfigurations'
107
- ? kubernetesManifest . misConfigurations ?. misConfSummary ?. status
108
- : kubernetesManifest [ subCategory ] ?. summary ?. severities
109
- return (
110
- < SecurityCard
111
- category = { CATEGORIES . KUBERNETES_MANIFEST }
112
- subCategory = { subCategory }
113
- severityCount = { severityCount }
114
- handleCardClick = { ( ) =>
115
- handleCardClick ( CATEGORIES . KUBERNETES_MANIFEST , subCategory )
116
- }
117
- />
118
- )
119
- } ) }
58
+ { Object . values ( CATEGORIES ) . map ( ( category : ScanCategories ) => {
59
+ if ( ! SECURITY_CONFIG [ category ] ) {
60
+ return null
61
+ }
62
+ const scanToolId = getScanToolId ( category )
63
+ return (
64
+ < div className = "flexbox-col dc__gap-12" key = { category } >
65
+ < div className = "flexbox dc__content-space pb-8 dc__border-bottom-n1" >
66
+ < span className = "fs-13 fw-6 lh-1-5 cn-9" > { SECURITY_CONFIG [ category ] . label } </ span >
67
+ < ScannedByToolModal scanToolId = { scanToolId } />
68
+ </ div >
69
+ < div className = "dc__grid security-cards" >
70
+ { SECURITY_CONFIG [ category ] . subCategories . map ( ( subCategory : ScanSubCategories ) => {
71
+ const severityCount =
72
+ subCategory === SUB_CATEGORIES . MISCONFIGURATIONS
73
+ ? scanResult [ category ] [ subCategory ] ?. misConfSummary ?. status
74
+ : scanResult [ category ] [ subCategory ] ?. summary ?. severities
75
+
76
+ return (
77
+ < SecurityCard
78
+ category = { category }
79
+ subCategory = { subCategory }
80
+ severityCount = { severityCount }
81
+ handleCardClick = { ( ) => handleCardClick ( category , subCategory ) }
82
+ />
83
+ )
84
+ } ) }
85
+ </ div >
120
86
</ div >
121
- </ div >
122
- ) : null }
87
+ )
88
+ } ) }
123
89
</ div >
124
90
{ showSecurityModal && (
125
91
< SecurityModal
0 commit comments