Skip to content

Commit 49d31a6

Browse files
authored
Implement simple file-upload in web-ui (#3977)
1 parent 78f5629 commit 49d31a6

File tree

18 files changed

+143
-578
lines changed

18 files changed

+143
-578
lines changed

sechub-administration/src/main/java/com/mercedesbenz/sechub/domain/administration/user/UserTransactionService.java

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// SPDX-License-Identifier: MIT
12
package com.mercedesbenz.sechub.domain.administration.user;
23

34
import static java.util.Objects.requireNonNull;

sechub-pds-solutions/gitleaks/env

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The base image to use
22
# uncomment to use local image
3-
# BASE_IMAGE="pds-base_pds"
3+
# BASE_IMAGE="pds-base-pds"
44
BASE_IMAGE="ghcr.io/mercedes-benz/sechub/pds-base"
55

66
# The gitleaks version to use

sechub-web-ui/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
This project is a web application that provides a user interface for the SecHub API. It is built with [Vite](https://vitejs.dev/), [Vue 3](https://v3.vuejs.org/), and [Vuetify](https://vuetifyjs.com/en/).
55

6-
## Prequisites
6+
## Prerequisites
77

88
### Installation
99

@@ -65,14 +65,14 @@ You can use the sechub-api.sh script to manage your user and project.
6565
1. Follow all steps above
6666
2. Start the integration test PDS
6767
(for the correct run configuration follow the [developer guide](https://mercedes-benz.github.io/sechub/latest/sechub-developer-quickstart-guide.html#run-integration-tests-from-ide))
68-
3. (Optional) Initial setup: execute `test-setups/setup-integration-test-server.sh`. Make sure the .env file contains the correct values for basic auth.
68+
3. (Optional) Initial setup: execute `test-setups/integrationtest-setups/setup.sh`. Make sure the .env file contains the correct values for basic auth.
6969

7070
### Running local development server with SecHub Docker Container and PDS Docker Container (Real Products)
7171
> Only useful If you want to get real scan results
7272
1. Start the SecHub Server as Docker Container (see sechub-solution/01-...)
73-
2. Start the required PDS as Docker Container (e.g. sechub-pds-solutions/gosec/05-...)
74-
3. Set up PDS in sechub-solution/setups/ e.g. setup-gosec.sh
75-
4. Make sure your user is assigned to the project you want to scan
73+
2. Start the required PDS as Docker (e.g. sechub-pds-solutions/gosec/05-...)
74+
3. (Optional) Initial setup: execute `/test-setups/docker/setup.sh` for gosec and gitleaks (Make sure PDS are running)
75+
7676

7777
Now you can test your web-ui with sechub and real scans!
7878

sechub-web-ui/public/favicon.ico

11.5 KB
Binary file not shown.
4.31 KB
Loading

sechub-web-ui/src/assets/sechub-logo.svg

-494
This file was deleted.

sechub-web-ui/src/components/AppHeader.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<router-link to="/projects">
77
<img
88
alt="Logo"
9-
class="logo ma-2 pa-1"
10-
src="@/assets/sechub-logo.svg"
9+
class="logo ma-2 pa-2"
10+
src="@/assets/sechub-logo-shield.png"
1111
>
1212
</router-link>
1313

Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<!-- SPDX-License-Identifier: MIT -->
22
<template>
3-
<v-card>
4-
<v-alert
5-
closable
6-
color="success"
7-
density="compact"
8-
:title="$t('CHANGE_USER_MAIL_SUCCESS')"
9-
variant="tonal"
10-
>
11-
</v-alert>
12-
</v-card>
3+
<v-card>
4+
<v-alert
5+
closable
6+
color="success"
7+
density="compact"
8+
:title="$t('CHANGE_USER_MAIL_SUCCESS')"
9+
variant="tonal"
10+
/>
11+
</v-card>
1312
</template>

sechub-web-ui/src/components/ScanCreate.vue

+3-4
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,15 @@
9494
<script lang="ts">
9595
import { defineComponent } from 'vue'
9696
import { useRoute } from 'vue-router'
97-
import { useI18n } from 'vue-i18n'
9897
import { SecHubConfiguration } from '@/generated-sources/openapi'
9998
import { buildSecHubConfiguration } from '@/utils/scanConfigUtils'
10099
import defaultClient from '@/services/defaultClient'
100+
import { CODE_SCAN_IDENTIFIER, SECRET_SCAN_IDENTIFER } from '@/utils/applicationConstants'
101101

102102
export default defineComponent({
103103

104104
setup () {
105105
// routing and translation methods
106-
const { t } = useI18n()
107106
const route = useRoute()
108107
const router = useRouter()
109108
const projectId = ref('')
@@ -151,7 +150,7 @@
151150
}
152151

153152
if (selectedFile.value !== null) {
154-
configuration.value = buildSecHubConfiguration(selectedScanOptions.value, selectedFile.value, selectedFileType.value, projectId.value)
153+
configuration.value = buildSecHubConfiguration(selectedScanOptions.value, selectedFileType.value, projectId.value)
155154
createScan()
156155
}
157156
}
@@ -172,7 +171,7 @@
172171

173172
return {
174173
projectId,
175-
scanOptions: [t('SCAN_CREATE_CODE_SCAN'), t('SCAN_CREATE_SECRET_SCAN')] as string[],
174+
scanOptions: [CODE_SCAN_IDENTIFIER, SECRET_SCAN_IDENTIFER] as string[],
176175
selectedScanOptions,
177176
validateScanReady,
178177
selectedFile,

sechub-web-ui/src/components/ScanFileUpload.vue

+6-19
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,13 @@
2121
:label="$t('SCAN_CREATE_SOURCE_CODE')"
2222
:value="1"
2323
/>
24-
<!--
2524
<v-radio
2625
color="primary"
2726
:label="$t('SCAN_CREATE_BINARIES')"
2827
:value="2"
2928
/>
30-
-->
3129
</v-radio-group>
32-
<v-alert
33-
class="pa-2, mb-5"
34-
color="info"
35-
max-width="1000px"
36-
:title="$t('SCAN_CREATE_FILE_UPLOAD_NOTE_TITLE')"
37-
type="info"
38-
variant="tonal"
39-
>
40-
{{ $t('SCAN_CREATE_FILE_UPLOAD_NOTE_ONE') }} <br>
41-
{{ $t('SCAN_CREATE_FILE_UPLOAD_NOTE_TWO') }} <br>
42-
{{ $t('SCAN_CREATE_FILE_UPLOAD_NOTE_THREE') }}
43-
</v-alert>
30+
4431
<v-file-input
4532
v-model="file"
4633
:accept="fileAccept"
@@ -67,6 +54,7 @@
6754
<script lang="ts">
6855
import { defineComponent, ref } from 'vue'
6956
import { useI18n } from 'vue-i18n'
57+
import { FILETYPE_BINARIES, FILETYPE_SOURCES } from '@/utils/applicationConstants'
7058

7159
export default defineComponent({
7260
emits: ['onFileUpdate'],
@@ -90,15 +78,14 @@
9078

9179
switch (selectedRadio.value) {
9280
case 1:
93-
fileType = 'sources'
81+
fileType = FILETYPE_SOURCES
9482
validType = file.value?.type === 'application/zip'
9583
errorMessage = t('SCAN_CREATE_FILE_UPLOAD_INPUT_ERROR_ZIP')
9684
break
9785
case 2:
98-
// binary upload currently not needed
99-
// fileType = 'binaries'
100-
// validType = file.value?.type === 'application/x-tar'
101-
// errorMessage = t('SCAN_CREATE_FILE_UPLOAD_INPUT_ERROR_TAR')
86+
fileType = FILETYPE_BINARIES
87+
validType = file.value?.type === 'application/x-tar'
88+
errorMessage = t('SCAN_CREATE_FILE_UPLOAD_INPUT_ERROR_TAR')
10289
break
10390
}
10491

sechub-web-ui/src/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const config = ref({
66
// New ENV must be defined in global.d.ts
77
USERNAME: import.meta.env.VITE_API_USERNAME || undefined,
88
PASSWORD: import.meta.env.VITE_API_PASSWORD || undefined,
9-
BASIC_AUTH_DEV: import.meta.env.VITE_API_BASIC_AUTH_DEV === "true" || false,
9+
BASIC_AUTH_DEV: import.meta.env.VITE_API_BASIC_AUTH_DEV === 'true' || false,
1010
})
1111

1212
// Overrides local environment variables after project compilation

sechub-web-ui/src/i18n/locales/en.json

+2-8
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,21 @@
4343
"SCAN_CREATE_TITLE": "Create new Scan",
4444
"SCAN_CREATE_SELECT_SCAN_TYPE": "Select Scan Type",
4545
"SCAN_CREATE_FILE_UPLOAD": "File Upload",
46-
"SCAN_CREATE_FILE_UPLOAD_NOTE_TITLE": "Important for secretScan",
47-
"SCAN_CREATE_FILE_UPLOAD_NOTE_ONE": "1. Put your code in the structure __data__/web-ui-upload/your-code",
48-
"SCAN_CREATE_FILE_UPLOAD_NOTE_TWO": "2. Create __data__.zip",
49-
"SCAN_CREATE_FILE_UPLOAD_NOTE_THREE": "3. Upload __data__.zip",
5046
"SCAN_CREATE_FILE_UPLOAD_INPUT": "Upload File",
5147
"SCAN_CREATE_FILE_UPLOAD_PROGRESS": "Uploading your data...",
5248
"SCAN_CREATE_FILE_UPLOAD_INPUT_ERROR_TITLE": "Upload Error. Please select a valid file",
5349
"SCAN_CREATE_FILE_UPLOAD_INPUT_ERROR_ZIP": "File must be a valid .zip containing the code you wish to scan.",
5450
"SCAN_CREATE_FILE_UPLOAD_INPUT_ERROR_TAR": "File must be a valid .tar containing the binary you wish to scan.",
5551
"SCAN_CREATE_BINARIES": "Binaires",
5652
"SCAN_CREATE_SOURCE_CODE": "Source Code",
57-
"SCAN_CREATE_CODE_SCAN": "codeScan",
58-
"SCAN_CREATE_SECRET_SCAN": "secretScan",
5953
"SCAN_CREATE_SCAN_START": "Scan",
6054
"SCAN_CREATE_SCAN_CONFIGURATION": "Scan Configuration",
6155
"SCAN_ERROR_ALERT_TITLE": "Ooops, your scan failed",
6256
"SCAN_ERROR_ALERT_JOB_NOT_CREATED": "Could not create a new Job.",
6357
"SCAN_ERROR_ALERT_SOURCE_UPLOAD_FAILED": "Could not upload sources. Your Zip file might be too big or is not correctly packed. We recommend using the cli client for large files.",
6458
"SCAN_ERROR_ALERT_BINARY_UPLOAD_FAILED": "Could not upload binaries. Your Tar file might be too big or is not correctly packed. We recommend using the cli client for large files.",
6559
"SCAN_ERROR_ALERT_JOB_NOT_APPROVED": "Could not approve Job.",
66-
"SCAN_ERROR_ALERT_NO_DATA_SECTION": "Could not get data section from configuration. Internal Error.",
67-
"SCAN_ERROR_ALERT_GENERIC": "An internal error ocurred.",
60+
"SCAN_ERROR_ALERT_NO_DATA_SECTION": "Could not get type section from configuration. Internal Error.",
61+
"SCAN_ERROR_ALERT_GENERIC": "An internal error occurred.",
6862
"CHANGE_USER_MAIL_SUCCESS": "You have changed your Email successfully!"
6963
}

sechub-web-ui/src/services/executionService/ScanService.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import executionApi from './executionService'
99
import { createSha256Checksum } from '../../utils/cryptoUtils'
1010
import { UserUploadsBinariesWorkaroundRequest, UserUploadSourceCodeWorkaroundRequest } from '@/services/executionService/executionService'
1111
import i18n from '@/i18n'
12+
import {
13+
UPLOAD_BINARIES_IDENTIFIER,
14+
UPLOAD_SOURCE_CODE_IDENTIFIER,
15+
} from '@/utils/applicationConstants'
1216

1317
// Implements the scan of a file in three steps: creating a Job, uploading the data and approve the job
1418
class ScanService {
@@ -47,7 +51,7 @@ class ScanService {
4751
private async uploadData (configuration: SecHubConfiguration, jobId: string, file: File, errorMessages: string[]) {
4852
const checksum: string = await createSha256Checksum(file)
4953

50-
if (configuration.data?.sources) {
54+
if (this.containsString(configuration, UPLOAD_SOURCE_CODE_IDENTIFIER)) {
5155
const requestParameters: UserUploadSourceCodeWorkaroundRequest = {
5256
projectId: configuration.projectId,
5357
jobUUID: jobId,
@@ -61,7 +65,7 @@ class ScanService {
6165
console.error('Source code upload failed:', error)
6266
errorMessages.push(i18n.global.t('SCAN_ERROR_ALERT_SOURCE_UPLOAD_FAILED'))
6367
}
64-
} else if (configuration.data?.binaries) {
68+
} else if (this.containsString(configuration, UPLOAD_BINARIES_IDENTIFIER)) {
6569
const size: string = file.size.toString()
6670
const requestParameters: UserUploadsBinariesWorkaroundRequest = {
6771
projectId: configuration.projectId,
@@ -78,10 +82,15 @@ class ScanService {
7882
errorMessages.push(i18n.global.t('SCAN_ERROR_ALERT_BINARY_UPLOAD_FAILED'))
7983
}
8084
} else {
81-
errorMessages.push(i18n.global.t('SCAN_ERROR_ALERT_NO_DATA_SECTION'))
85+
errorMessages.push(i18n.global.t('SCAN_ERROR_ALERT_CONFIGURATION_ERROR'))
8286
}
8387
}
8488

89+
private containsString (config: SecHubConfiguration, searchString: string): boolean {
90+
const jsonString = JSON.stringify(config)
91+
return jsonString.includes(searchString)
92+
}
93+
8594
private async approveJob (projectId: string, jobId: string, errorMessages: string[]) {
8695
const requestParameters: UserApproveJobRequest = {
8796
projectId,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// SPDX-License-Identifier: MIT
2+
// constants for sechub scan configuration
3+
export const UPLOAD_BINARIES_IDENTIFIER: string = '__binaries_archive_root__'
4+
export const UPLOAD_SOURCE_CODE_IDENTIFIER: string = '__sourcecode_archive_root__'
5+
export const CODE_SCAN_IDENTIFIER: string = 'codeScan'
6+
export const SECRET_SCAN_IDENTIFER: string = 'secretScan'
7+
8+
export const FILETYPE_SOURCES: string = 'sources'
9+
export const FILETYPE_BINARIES: string = 'binaries'

sechub-web-ui/src/utils/scanConfigUtils.ts

+26-27
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,47 @@
22
import {
33
SecHubCodeScanConfiguration,
44
SecHubConfiguration,
5-
SecHubDataConfiguration,
6-
SecHubFileSystemConfiguration,
75
SecHubSecretScanConfiguration,
86
} from '@/generated-sources/openapi'
97

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'
2816

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)
3219

3320
const config: SecHubConfiguration = {
3421
apiVersion: '1.0',
3522
projectId,
36-
data: dataConfiguration,
3723
}
3824

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]
4128
config.codeScan = codeScanConfiguration
4229
}
4330

44-
if (secretScanConfiguration.use) {
31+
if (scanTypes.includes(SECRET_SCAN_IDENTIFER)) {
32+
const secretScanConfiguration: SecHubSecretScanConfiguration = {}
33+
secretScanConfiguration.use = [UNIQUE_NAME]
4534
config.secretScan = secretScanConfiguration
4635
}
4736

4837
return config
4938
}
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: MIT
3+
4+
echo "Start executing helper script"
5+
echo "Please make sure you have started the Docker SecHub Server and Docker PDS Gosec and Gitleaks"
6+
echo "Setting up Gosec and Gitleaks Project for Docker Server with real Products"
7+
8+
srcdir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )
9+
10+
cd $srcdir
11+
12+
# Copy the .env file to the current directory
13+
if [ -e .env ]
14+
then
15+
echo "Using existsing .env file"
16+
else
17+
echo "Coping .env file from web-ui directory"
18+
cp ../../.env .
19+
fi
20+
21+
# Source the .env file to load environment variables
22+
set -a
23+
source ./.env
24+
set +a
25+
26+
echo "Using VITE .env to setup your user and apitoken"
27+
28+
# Export additional variables
29+
export SECHUB_APITOKEN=${VITE_API_PASSWORD}
30+
export SECHUB_USERID=${VITE_API_USERNAME}
31+
export SECHUB_SERVER=https://localhost:8443
32+
33+
echo 'Starting test setup...'
34+
35+
# setting up gosec
36+
../../../sechub-solution/setup-pds/setup-gosec.sh
37+
../../../sechub-developertools/scripts/sechub-api.sh project_assign_user test-gosec $SECHUB_USERID
38+
39+
# setting up gitleaks
40+
../../../sechub-solution/setup-pds/setup-gitleaks.sh
41+
../../../sechub-developertools/scripts/sechub-api.sh project_assign_user test-gitleaks $SECHUB_USERID
42+
43+
echo "Finished setting up Gosec and Gitleaks Project for Docker Server with real Products"

0 commit comments

Comments
 (0)