Skip to content

Commit 7758cfb

Browse files
authored
Merge pull request #481 from devtron-labs/feat/integrate-scans
feat: intergrate scanning for v1 and v2 APIs
2 parents 88d1497 + c17b686 commit 7758cfb

30 files changed

+273
-411
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "1.3.9",
3+
"version": "1.3.10",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Common/Constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export const ROUTES = {
8989
CD_MATERIAL_GET: 'app/cd-pipeline',
9090
DEPLOYMENT_TEMPLATE_LIST: 'app/template/list',
9191
INFRA_CONFIG_PROFILE: 'infra-config/profile',
92-
SECURITY_SCAN_EXECUTION_DETAILS: 'security/scan/executionDetail',
92+
SCAN_RESULT: 'scan-result',
9393
NOTIFIER: 'notification',
9494
APP_LIST: 'app/list',
9595
TELEMETRY_EVENT: 'telemetry/event',

src/Common/RJSF/widgets/Checkbox.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
import React, { ChangeEvent } from 'react'
17+
import { ChangeEvent } from 'react'
1818
import { WidgetProps } from '@rjsf/utils'
19-
import Toggle from '../../Toggle/Toggle'
2019
import { isNullOrUndefined } from '@Shared/Helpers'
20+
import Toggle from '../../Toggle/Toggle'
2121

2222
export const Checkbox = ({
2323
id,

src/Shared/Components/ImageCardAccordion/ImageCardAccordion.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ const ImageCardAccordion = ({
4949
isScanned,
5050
isScanEnabled,
5151
SecurityModalSidebar,
52-
getSecurityScan,
5352
}: ImageCardAccordionProps) => {
5453
const [isOpened, setIsOpened] = useState<boolean>(false)
5554
const [activeTab, setActiveTab] = useState<CDModalTabType>(CDModalTab.Changes)
@@ -77,7 +76,6 @@ const ImageCardAccordion = ({
7776
environmentId={environmentId}
7877
setVulnerabilityCount={setVulnerabilityCount}
7978
SecurityModalSidebar={SecurityModalSidebar}
80-
getSecurityScan={getSecurityScan}
8179
/>
8280
)
8381
}

src/Shared/Components/ImageCardAccordion/types.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616

1717
import React, { ReactNode } from 'react'
18-
import { CDModalTabType, ResponseType, VulnerabilityType } from '../../../Common'
18+
import { CDModalTabType, VulnerabilityType } from '../../../Common'
1919
import { MaterialSecurityInfoType } from '../../types'
20-
import { ApiResponseResultType, AppDetailsPayload, SidebarPropsType } from '../Security'
20+
import { SidebarPropsType } from '../Security'
2121

2222
export interface ImageCardAccordionProps extends MaterialSecurityInfoType {
2323
isSecurityModuleInstalled: boolean
@@ -28,9 +28,6 @@ export interface ImageCardAccordionProps extends MaterialSecurityInfoType {
2828
isScanned: boolean
2929
isScanEnabled: boolean
3030
SecurityModalSidebar: React.FC<SidebarPropsType>
31-
getSecurityScan: (
32-
props: Pick<AppDetailsPayload, 'appId' | 'artifactId'>,
33-
) => Promise<ResponseType<ApiResponseResultType>>
3431
}
3532

3633
export interface SecurityDetailsType {

src/Shared/Components/Security/SecurityModal/SecurityModal.tsx

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import { ReactComponent as ICBack } from '@Icons/ic-caret-left-small.svg'
1717
import { Button, ButtonStyleType, ButtonVariantType } from '@Shared/Components/Button'
1818
import { ComponentSizeType } from '@Shared/constants'
1919
import { Table, InfoCard } from './components'
20-
import { DEFAULT_SECURITY_MODAL_STATE } from './constants'
20+
import { getDefaultSecurityModalState } from './constants'
2121
import { getTableData, getInfoCardData } from './config'
22-
import { SecurityModalPropsType, SecurityModalStateType, DetailViewDataType } from './types'
22+
import { SecurityModalPropsType, SecurityModalStateType, DetailViewDataType, SidebarPropsType } from './types'
2323
import { getEmptyStateValues } from './config/EmptyState'
2424
import './styles.scss'
2525

@@ -39,16 +39,19 @@ const SecurityModal: React.FC<SecurityModalPropsType> = ({
3939
isLoading,
4040
error,
4141
responseData,
42-
isResourceScan = false,
43-
isHelmApp = false,
44-
isSecurityScanV2Enabled = false,
45-
isExternalCI = false,
4642
hidePolicy = false,
4743
}) => {
48-
const [state, setState] = useState<SecurityModalStateType>(DEFAULT_SECURITY_MODAL_STATE)
49-
5044
const data = responseData ?? null
5145

46+
const categoriesConfig: SidebarPropsType['categoriesConfig'] = {
47+
imageScan: !!data?.imageScan,
48+
imageScanLicenseRisks: !!data?.imageScan?.license,
49+
codeScan: !!data?.codeScan,
50+
kubernetesManifest: !!data?.kubernetesManifest,
51+
}
52+
53+
const [state, setState] = useState<SecurityModalStateType>(getDefaultSecurityModalState(categoriesConfig))
54+
5255
const setDetailViewData = (detailViewData: DetailViewDataType) => {
5356
setState((prevState) => ({
5457
...prevState,
@@ -156,14 +159,7 @@ const SecurityModal: React.FC<SecurityModalPropsType> = ({
156159
/* NOTE: the height is restricted to (viewport - header) height since we need overflow-scroll */
157160
<div className="flexbox" style={{ height: 'calc(100vh - 49px)' }}>
158161
{/* NOTE: only show sidebar in AppDetails */}
159-
{isSecurityScanV2Enabled && !isResourceScan && Sidebar && (
160-
<Sidebar
161-
isHelmApp={isHelmApp}
162-
modalState={state}
163-
setModalState={setState}
164-
isExternalCI={isExternalCI}
165-
/>
166-
)}
162+
{Sidebar && <Sidebar modalState={state} setModalState={setState} categoriesConfig={categoriesConfig} />}
167163
<div className="dc__border-right-n1 h-100" />
168164
<div className="dc__overflow-scroll flex-grow-1" style={{ width: '744px' }}>
169165
{selectedDetailViewData && renderDetailViewSubHeader()}
@@ -176,7 +172,7 @@ const SecurityModal: React.FC<SecurityModalPropsType> = ({
176172
return (
177173
<VisibleModal2 className="dc__position-rel" close={handleModalClose}>
178174
<div
179-
className={`${isResourceScan ? 'w-800' : 'w-1024'} h-100vh bcn-0 flexbox-col dc__right-0 dc__top-0 dc__position-abs`}
175+
className={`${Sidebar ? 'w-1024' : 'w-800'} h-100vh bcn-0 flexbox-col dc__right-0 dc__top-0 dc__position-abs`}
180176
onClick={stopPropagation}
181177
>
182178
{renderHeader()}

src/Shared/Components/Security/SecurityModal/config/CodeScan.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
SEVERITY_DEFAULT_SORT_ORDER,
1818
} from '../constants'
1919
import {
20-
ApiResponseResultType,
20+
ScanResultDTO,
2121
CATEGORIES,
2222
CodeScan,
2323
CodeScanExposedSecretsListType,
@@ -454,7 +454,7 @@ const getCompletedEmptyState = (
454454
detailViewData: DetailViewDataType,
455455
) => {
456456
/* NOTE: show empty state only when we don't have any data to show */
457-
if ((data[subCategory]?.list && !detailViewData) || detailViewData?.rows) {
457+
if ((data[subCategory]?.list?.length && !detailViewData) || detailViewData?.rows) {
458458
return null
459459
}
460460

@@ -489,7 +489,7 @@ const getCompletedEmptyState = (
489489
}
490490

491491
export const getCodeScanEmptyState = (
492-
data: ApiResponseResultType,
492+
data: ScanResultDTO,
493493
subCategory: SecurityModalStateType['subCategory'],
494494
detailViewData: DetailViewDataType,
495495
): EmptyStateType => {

src/Shared/Components/Security/SecurityModal/config/EmptyState.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import { getCodeScanEmptyState } from './CodeScan'
66
import { getImageScanEmptyState } from './ImageScan'
77
import { getKubernetesManifestEmptyState } from './KubernetesManifest'
8-
import { ApiResponseResultType, CATEGORIES, DetailViewDataType, SecurityModalStateType } from '../types'
8+
import { ScanResultDTO, CATEGORIES, DetailViewDataType, SecurityModalStateType } from '../types'
99

1010
export const getEmptyStateValues = (
11-
data: ApiResponseResultType,
11+
data: ScanResultDTO,
1212
category: SecurityModalStateType['category'],
1313
subCategory: SecurityModalStateType['subCategory'],
1414
detailViewData: DetailViewDataType,

src/Shared/Components/Security/SecurityModal/config/ImageScan.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
InfoCardPropsType,
1919
ImageScanLicenseListType,
2020
EmptyStateType,
21-
ApiResponseResultType,
21+
ScanResultDTO,
2222
CATEGORIES,
2323
OpenDetailViewButtonProps,
2424
} from '../types'
@@ -105,7 +105,7 @@ const getVulnerabilitiesDetailData = (
105105
setDetailViewData: OpenDetailViewButtonProps['setDetailViewData'],
106106
hidePolicy: boolean,
107107
) => {
108-
const shouldGroupByTarget = element.list.every((item) => !!item.target)
108+
const shouldGroupByTarget = element.list?.every((item) => !!item.target)
109109
if (!shouldGroupByTarget) {
110110
return {
111111
...getVulnerabilitiesDetailBaseData(element),
@@ -355,14 +355,14 @@ const getCompletedEmptyState = (
355355
}
356356

357357
export const getImageScanEmptyState = (
358-
data: ApiResponseResultType,
358+
data: ScanResultDTO,
359359
subCategory: SecurityModalStateType['subCategory'],
360360
detailViewData: DetailViewDataType,
361361
): EmptyStateType => {
362362
/**
363363
* NOTE: handling for resourceScan in ResourceBrowser
364364
* TODO: handle properly */
365-
if (!data[CATEGORIES.IMAGE_SCAN][subCategory]?.list?.length) {
365+
if (!data[CATEGORIES.IMAGE_SCAN]?.[subCategory]?.list?.length) {
366366
return SCAN_IN_PROGRESS_EMPTY_STATE
367367
}
368368

0 commit comments

Comments
 (0)