1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-11-06 09:09:19 +02:00

feat(protecodeExecuteScan): allow scanning a binary (#2889)

* feat(protecodeExecuteScan): allow scanning a binary

so far the step only accepts a Docker image or a FetchURL
This adds functionality to also pass a FilePath

* Update protecodeExecuteScan.go

* Update protecodeExecuteScan.go

* Update protecodeExecuteScan.go

* Update protecodeExecuteScan.go

* Update protecodeExecuteScan.go

* Update protecodeExecuteScan.go

* Fix fmt

Co-authored-by: Sven Merk <33895725+nevskrem@users.noreply.github.com>
Co-authored-by: Sven Merk <s.merk@sap.com>
This commit is contained in:
Oliver Nocon
2021-06-17 09:40:21 +02:00
committed by GitHub
parent 78d7c4c71a
commit 188e409a87
2 changed files with 11 additions and 2 deletions

View File

@@ -55,7 +55,7 @@ func runProtecodeScan(config *protecodeExecuteScanOptions, influx *protecodeExec
//create client for sending api request
log.Entry().Debug("Create protecode client")
client := createClient(config)
if len(config.FetchURL) <= 0 {
if len(config.FetchURL) == 0 && len(config.FilePath) == 0 {
log.Entry().Debugf("Get docker image: %v, %v, %v, %v", config.ScanImage, config.DockerRegistryURL, config.FilePath, config.IncludeLayers)
fileName, filePath, err = getDockerImage(dClient, config)
if err != nil {
@@ -65,6 +65,15 @@ func runProtecodeScan(config *protecodeExecuteScanOptions, influx *protecodeExec
(*config).FilePath = filePath
log.Entry().Debugf("Filepath for upload image: %v", config.FilePath)
}
} else if len(config.FilePath) > 0 {
parts := strings.Split(config.FilePath, "/")
pathFragment := strings.Join(parts[:len(parts)-1], "/")
if len(pathFragment) > 0 {
(*config).FilePath = pathFragment
} else {
(*config).FilePath = "./"
}
fileName = parts[len(parts)-1]
}
log.Entry().Debug("Execute protecode scan")

View File

@@ -154,7 +154,7 @@ func TestRunProtecodeScan(t *testing.T) {
})
t.Run("Without tar as scan image", func(t *testing.T) {
config := protecodeExecuteScanOptions{ServerURL: server.URL, ScanImage: "t", FilePath: path, TimeoutMinutes: "1", VerifyOnly: false, CleanupMode: "none", Group: "13", ExcludeCVEs: "CVE-2018-1, CVE-2017-1000382", ReportFileName: "./cache/report-file.txt"}
config := protecodeExecuteScanOptions{ServerURL: server.URL, ScanImage: "t", TimeoutMinutes: "1", VerifyOnly: false, CleanupMode: "none", Group: "13", ExcludeCVEs: "CVE-2018-1, CVE-2017-1000382", ReportFileName: "./cache/report-file.txt"}
err = runProtecodeScan(&config, &influx, dClient)
assert.NoError(t, err)
})