|
2 | 2 | import {
|
3 | 3 | SecHubCodeScanConfiguration,
|
4 | 4 | SecHubConfiguration,
|
5 |
| - SecHubDataConfiguration, |
6 |
| - SecHubFileSystemConfiguration, |
7 | 5 | SecHubSecretScanConfiguration,
|
8 | 6 | } from '@/generated-sources/openapi'
|
9 | 7 |
|
10 |
| -export function buildSecHubConfiguration (scanTypes: string[], uploadFile: File, fileType: string, projectId: string): SecHubConfiguration { |
11 |
| - const UNIQUE_NAME = 'web-ui-upload' |
12 |
| - |
13 |
| - const fileSystemConfig: SecHubFileSystemConfiguration = { |
14 |
| - files: [uploadFile.name], |
15 |
| - } |
16 |
| - |
17 |
| - const dataConfiguration: SecHubDataConfiguration = { |
18 |
| - sources: fileType === 'sources' ? [{ name: UNIQUE_NAME, fileSystem: fileSystemConfig }] : undefined, |
19 |
| - binaries: fileType === 'binaries' ? [{ name: UNIQUE_NAME, fileSystem: fileSystemConfig }] : undefined, |
20 |
| - } |
21 |
| - |
22 |
| - const codeScanConfiguration: SecHubCodeScanConfiguration = {} |
23 |
| - const secretScanConfiguration: SecHubSecretScanConfiguration = {} |
24 |
| - |
25 |
| - if (scanTypes.includes('codeScan')) { |
26 |
| - codeScanConfiguration.use = [UNIQUE_NAME] |
27 |
| - } |
| 8 | +import { |
| 9 | + CODE_SCAN_IDENTIFIER, |
| 10 | + FILETYPE_BINARIES, |
| 11 | + FILETYPE_SOURCES, |
| 12 | + SECRET_SCAN_IDENTIFER, |
| 13 | + UPLOAD_BINARIES_IDENTIFIER, |
| 14 | + UPLOAD_SOURCE_CODE_IDENTIFIER, |
| 15 | +} from './applicationConstants' |
28 | 16 |
|
29 |
| - if (scanTypes.includes('secretScan')) { |
30 |
| - secretScanConfiguration.use = [UNIQUE_NAME] |
31 |
| - } |
| 17 | +export function buildSecHubConfiguration (scanTypes: string[], fileType: string, projectId: string): SecHubConfiguration { |
| 18 | + const UNIQUE_NAME : string = getUniqueName(fileType) |
32 | 19 |
|
33 | 20 | const config: SecHubConfiguration = {
|
34 | 21 | apiVersion: '1.0',
|
35 | 22 | projectId,
|
36 |
| - data: dataConfiguration, |
37 | 23 | }
|
38 | 24 |
|
39 |
| - // adding scan types to configuration |
40 |
| - if (codeScanConfiguration.use) { |
| 25 | + if (scanTypes.includes(CODE_SCAN_IDENTIFIER)) { |
| 26 | + const codeScanConfiguration: SecHubCodeScanConfiguration = {} |
| 27 | + codeScanConfiguration.use = [UNIQUE_NAME] |
41 | 28 | config.codeScan = codeScanConfiguration
|
42 | 29 | }
|
43 | 30 |
|
44 |
| - if (secretScanConfiguration.use) { |
| 31 | + if (scanTypes.includes(SECRET_SCAN_IDENTIFER)) { |
| 32 | + const secretScanConfiguration: SecHubSecretScanConfiguration = {} |
| 33 | + secretScanConfiguration.use = [UNIQUE_NAME] |
45 | 34 | config.secretScan = secretScanConfiguration
|
46 | 35 | }
|
47 | 36 |
|
48 | 37 | return config
|
49 | 38 | }
|
| 39 | + |
| 40 | +function getUniqueName (fileType: string): string { |
| 41 | + if (fileType === FILETYPE_BINARIES) { |
| 42 | + return UPLOAD_BINARIES_IDENTIFIER |
| 43 | + } else if (fileType === FILETYPE_SOURCES) { |
| 44 | + return UPLOAD_SOURCE_CODE_IDENTIFIER |
| 45 | + } else { |
| 46 | + throw new Error(`Unknown fileType: ${fileType}`) |
| 47 | + } |
| 48 | +} |
0 commit comments