Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Plugin for image scanning in Pre/Post step #1361

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/components/CIPipelineN/CIPipeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ export default function CIPipeline({
sharedPlugins={sharedPlugins}
isJobView={isJobCard}
mandatoryPluginsMap={mandatoryPluginsMap}
isSecurityModuleInstalled={isSecurityModuleInstalled}
/>
</Route>
)}
Expand All @@ -799,6 +800,7 @@ export default function CIPipeline({
presetPlugins={presetPlugins}
sharedPlugins={sharedPlugins}
mandatoryPluginsMap={mandatoryPluginsMap}
isSecurityModuleInstalled={isSecurityModuleInstalled}
/>
</Route>
)}
Expand Down
52 changes: 29 additions & 23 deletions src/components/CIPipelineN/PluginCardListContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React from 'react'
import { PluginType, PluginDetailType, VariableType } from '@devtron-labs/devtron-fe-common-lib'
import { PluginCard } from './PluginCard'
import { VulnerabilityScanning } from './ciPipeline.utils'

export function PluginCardListContainer({
pluginListTitle,
pluginList,
setPluginType,
isSecurityModuleInstalled
}: {
pluginListTitle: string
pluginList: PluginDetailType[]
Expand All @@ -17,36 +19,40 @@ export function PluginCardListContainer({
inputVariables: VariableType[],
outputVariables: VariableType[],
) => void
isSecurityModuleInstalled: boolean
}) {
return (
pluginList.length > 0 && (
<div className="plugin-container">
<div data-testid="preset-plugin-heading" className="cn-5 fw-6 fs-13 mt-20 mb-8">
{pluginListTitle}
</div>
{pluginList.map((pluginDetails) => (
<div
key={pluginDetails.id}
onClick={() =>
setPluginType(
PluginType.PLUGIN_REF,
pluginDetails.id,
pluginDetails.name,
pluginDetails.description,
pluginDetails.inputVariables ?? [],
pluginDetails.outputVariables ?? [],
)
}
>
<PluginCard
dataTestId={`${pluginDetails.name}-button`}
imgSource={pluginDetails.icon}
title={pluginDetails.name}
subTitle={pluginDetails.description}
tags={pluginDetails.tags}
/>
</div>
))}
{pluginList.map(
(pluginDetails) =>
(pluginDetails.name !== VulnerabilityScanning || isSecurityModuleInstalled) && (
<div
key={pluginDetails.id}
onClick={() =>
setPluginType(
PluginType.PLUGIN_REF,
pluginDetails.id,
pluginDetails.name,
pluginDetails.description,
pluginDetails.inputVariables ?? [],
pluginDetails.outputVariables ?? [],
)
}
>
<PluginCard
dataTestId={`${pluginDetails.name}-button`}
imgSource={pluginDetails.icon}
title={pluginDetails.name}
subTitle={pluginDetails.description}
tags={pluginDetails.tags}
/>
</div>
),
)}
</div>
)
)
Expand Down
4 changes: 3 additions & 1 deletion src/components/CIPipelineN/PreBuild.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { importComponentFromFELibrary } from '../common'
import { pipelineContext } from '../workflowEditor/workflowEditor'

const isRequired = importComponentFromFELibrary('isRequired', null, 'function')
export function PreBuild({ presetPlugins, sharedPlugins, mandatoryPluginsMap, isJobView }: PreBuildType) {
export function PreBuild({ presetPlugins, sharedPlugins, mandatoryPluginsMap, isJobView, isSecurityModuleInstalled}: PreBuildType) {
const {
formData,
isCdPipeline,
Expand Down Expand Up @@ -151,11 +151,13 @@ export function PreBuild({ presetPlugins, sharedPlugins, mandatoryPluginsMap, is
setPluginType={setPluginType}
pluginListTitle="PRESET PLUGINS"
pluginList={presetPlugins}
isSecurityModuleInstalled={isSecurityModuleInstalled}
/>
<PluginCardListContainer
setPluginType={setPluginType}
pluginListTitle="SHARED PLUGINS"
pluginList={sharedPlugins}
isSecurityModuleInstalled={isSecurityModuleInstalled}
/>
</>
)
Expand Down
2 changes: 2 additions & 0 deletions src/components/CIPipelineN/ciPipeline.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,5 @@ export const reactSelectStyles = {
}
},
}

export const VulnerabilityScanning = 'Vulnerability Scanning'
20 changes: 17 additions & 3 deletions src/components/cdPipeline/NewCDPipeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import React, { useEffect, useMemo, useRef, useState } from 'react'
import { ReactComponent as Close } from '../../assets/icons/ic-close.svg'
import { NavLink, Redirect, Route, Switch, useParams, useRouteMatch } from 'react-router-dom'
import { CDDeploymentTabText, DELETE_ACTION, SourceTypeMap, TriggerType, ViewType } from '../../config'
import { CDDeploymentTabText, DELETE_ACTION, ModuleNameMap, SourceTypeMap, TriggerType, ViewType } from '../../config'
import { ButtonWithLoader, FloatingVariablesSuggestions, sortObjectArrayAlphabetically } from '../common'
import BuildCD from './BuildCD'
import { CD_PATCH_ACTION, Environment, GeneratedHelmPush } from './cdPipeline.types'
Expand Down Expand Up @@ -52,6 +52,8 @@ import { calculateLastStepDetailsLogic, checkUniqueness, validateTask } from './
import { pipelineContext } from '../workflowEditor/workflowEditor'
import { PipelineFormDataErrorType, PipelineFormType } from '../workflowEditor/types'
import { getDockerRegistryMinAuth } from '../ciConfig/service'
import { getModuleInfo } from '../v2/devtronStackManager/DevtronStackManager.service'
import { ModuleStatus } from '../v2/devtronStackManager/DevtronStackManager.type'

export enum deleteDialogType {
showForceDeleteDialog = 'showForceDeleteDialog',
Expand Down Expand Up @@ -176,6 +178,8 @@ export default function NewCDPipeline({
preBuildStage: Map<string, VariableType>[]
postBuildStage: Map<string, VariableType>[]
}>({ preBuildStage: [], postBuildStage: [] })
const [isSecurityModuleInstalled, setSecurityModuleInstalled] = useState<boolean>(false)


useEffect(() => {
getInit()
Expand All @@ -195,6 +199,7 @@ export default function NewCDPipeline({
}

const getInit = () => {
getSecurityModuleStatus()
Promise.all([
getDeploymentStrategyList(appId),
getGlobalVariable(Number(appId), true),
Expand Down Expand Up @@ -276,6 +281,15 @@ export default function NewCDPipeline({
})
}

const getSecurityModuleStatus = async (): Promise<void> => {
try {
const { result } = await getModuleInfo(ModuleNameMap.SECURITY)
if (result?.status === ModuleStatus.INSTALLED) {
setSecurityModuleInstalled(true)
}
} catch (error) {}
}

const calculateLastStepDetail = (
isFromAddNewTask: boolean,
_formData: PipelineFormType,
Expand Down Expand Up @@ -1028,12 +1042,12 @@ export default function NewCDPipeline({
<Switch>
{isAdvanced && (
<Route path={`${path}/pre-build`}>
<PreBuild presetPlugins={presetPlugins} sharedPlugins={sharedPlugins} />
<PreBuild presetPlugins={presetPlugins} sharedPlugins={sharedPlugins} isSecurityModuleInstalled={isSecurityModuleInstalled} />
</Route>
)}
{isAdvanced && (
<Route path={`${path}/post-build`}>
<PreBuild presetPlugins={presetPlugins} sharedPlugins={sharedPlugins} />
<PreBuild presetPlugins={presetPlugins} sharedPlugins={sharedPlugins} isSecurityModuleInstalled={isSecurityModuleInstalled} />
</Route>
)}
<Route path={`${path}/build`}>
Expand Down
1 change: 1 addition & 0 deletions src/components/ciPipeline/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ export interface PreBuildType {
sharedPlugins: PluginDetailType[]
mandatoryPluginsMap?: Record<number, MandatoryPluginDetailType>
isJobView?: boolean
isSecurityModuleInstalled?: boolean
}

export enum CIPipelineBuildType {
Expand Down
Loading