1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00

Removed quotation for several detect8 parameters to fix double quotation issue (#4565)

* removed quotation for detect8

* changed order of args

* chagned order
This commit is contained in:
Dmitrii Pavlukhin 2023-09-14 10:07:53 +03:00 committed by GitHub
parent 20b3c0d728
commit b3dc339058
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -345,28 +345,73 @@ func addDetectArgs(args []string, config detectExecuteScanOptions, utils detectU
args = append(args, fmt.Sprintf("--blackduck.api.token=%v", config.Token)) args = append(args, fmt.Sprintf("--blackduck.api.token=%v", config.Token))
// ProjectNames, VersionName, GroupName etc can contain spaces and need to be escaped using double quotes in CLI // ProjectNames, VersionName, GroupName etc can contain spaces and need to be escaped using double quotes in CLI
// Hence the string need to be surrounded by \" // Hence the string need to be surrounded by \"
args = append(args, fmt.Sprintf("\"--detect.project.name='%v'\"", config.ProjectName))
args = append(args, fmt.Sprintf("\"--detect.project.version.name='%v'\"", detectVersionName))
// Groups parameter is added only when there is atleast one non-empty groupname provided // Maven Parameters
if len(config.Groups) > 0 && len(config.Groups[0]) > 0 { mavenArgs, err := maven.DownloadAndGetMavenParameters(config.GlobalSettingsFile, config.ProjectSettingsFile, utils)
args = append(args, fmt.Sprintf("\"--detect.project.user.groups='%v'\"", strings.Join(config.Groups, ","))) if err != nil {
return nil, err
} }
// Atleast 1, non-empty category to fail on must be provided if len(config.M2Path) > 0 {
if len(config.FailOn) > 0 && len(config.FailOn[0]) > 0 { absolutePath, err := utils.Abs(config.M2Path)
args = append(args, fmt.Sprintf("--detect.policy.check.fail.on.severities=%v", strings.Join(config.FailOn, ","))) if err != nil {
} return nil, err
}
if config.SuccessOnSkip { mavenArgs = append(mavenArgs, fmt.Sprintf("-Dmaven.repo.local=%v", absolutePath))
args = append(args, fmt.Sprintf("\"--detect.force.success.on.skip=%v\"", config.SuccessOnSkip))
} }
codelocation := config.CodeLocation codelocation := config.CodeLocation
if len(codelocation) == 0 && len(config.ProjectName) > 0 { if len(codelocation) == 0 && len(config.ProjectName) > 0 {
codelocation = fmt.Sprintf("%v/%v", config.ProjectName, detectVersionName) codelocation = fmt.Sprintf("%v/%v", config.ProjectName, detectVersionName)
} }
args = append(args, fmt.Sprintf("\"--detect.code.location.name='%v'\"", codelocation))
// Since detect8 adds quotes by default, to avoid double quotation they should be removed for several arguments
if config.UseDetect8 {
args = append(args, fmt.Sprintf("\"--detect.project.name=%v\"", config.ProjectName))
args = append(args, fmt.Sprintf("\"--detect.project.version.name=%v\"", detectVersionName))
// Groups parameter is added only when there is atleast one non-empty groupname provided
if len(config.Groups) > 0 && len(config.Groups[0]) > 0 {
args = append(args, fmt.Sprintf("\"--detect.project.user.groups=%v\"", strings.Join(config.Groups, ",")))
}
// Atleast 1, non-empty category to fail on must be provided
if len(config.FailOn) > 0 && len(config.FailOn[0]) > 0 {
args = append(args, fmt.Sprintf("--detect.policy.check.fail.on.severities=%v", strings.Join(config.FailOn, ",")))
}
args = append(args, fmt.Sprintf("\"--detect.code.location.name=%v\"", codelocation))
if len(mavenArgs) > 0 && !checkIfArgumentIsInScanProperties(config, "detect.maven.build.command") {
args = append(args, fmt.Sprintf("\"--detect.maven.build.command=%v\"", strings.Join(mavenArgs, " ")))
}
} else {
args = append(args, fmt.Sprintf("\"--detect.project.name='%v'\"", config.ProjectName))
args = append(args, fmt.Sprintf("\"--detect.project.version.name='%v'\"", detectVersionName))
// Groups parameter is added only when there is atleast one non-empty groupname provided
if len(config.Groups) > 0 && len(config.Groups[0]) > 0 {
args = append(args, fmt.Sprintf("\"--detect.project.user.groups='%v'\"", strings.Join(config.Groups, ",")))
}
// Atleast 1, non-empty category to fail on must be provided
if len(config.FailOn) > 0 && len(config.FailOn[0]) > 0 {
args = append(args, fmt.Sprintf("--detect.policy.check.fail.on.severities=%v", strings.Join(config.FailOn, ",")))
}
args = append(args, fmt.Sprintf("\"--detect.code.location.name='%v'\"", codelocation))
if len(mavenArgs) > 0 && !checkIfArgumentIsInScanProperties(config, "detect.maven.build.command") {
args = append(args, fmt.Sprintf("\"--detect.maven.build.command='%v'\"", strings.Join(mavenArgs, " ")))
}
}
if config.SuccessOnSkip {
args = append(args, fmt.Sprintf("\"--detect.force.success.on.skip=%v\"", config.SuccessOnSkip))
}
if len(config.ScanPaths) > 0 && len(config.ScanPaths[0]) > 0 { if len(config.ScanPaths) > 0 && len(config.ScanPaths[0]) > 0 {
args = append(args, fmt.Sprintf("--detect.blackduck.signature.scanner.paths=%v", strings.Join(config.ScanPaths, ","))) args = append(args, fmt.Sprintf("--detect.blackduck.signature.scanner.paths=%v", strings.Join(config.ScanPaths, ",")))
@ -404,23 +449,6 @@ func addDetectArgs(args []string, config detectExecuteScanOptions, utils detectU
args = append(args, fmt.Sprintf("--detect.npm.arguments=%v", strings.ToUpper(strings.Join(config.NpmArguments, " ")))) args = append(args, fmt.Sprintf("--detect.npm.arguments=%v", strings.ToUpper(strings.Join(config.NpmArguments, " "))))
} }
mavenArgs, err := maven.DownloadAndGetMavenParameters(config.GlobalSettingsFile, config.ProjectSettingsFile, utils)
if err != nil {
return nil, err
}
if len(config.M2Path) > 0 {
absolutePath, err := utils.Abs(config.M2Path)
if err != nil {
return nil, err
}
mavenArgs = append(mavenArgs, fmt.Sprintf("-Dmaven.repo.local=%v", absolutePath))
}
if len(mavenArgs) > 0 && !checkIfArgumentIsInScanProperties(config, "detect.maven.build.command") {
args = append(args, fmt.Sprintf("\"--detect.maven.build.command='%v'\"", strings.Join(mavenArgs, " ")))
}
// rapid scan on pull request // rapid scan on pull request
if utils.GetProvider().IsPullRequest() { if utils.GetProvider().IsPullRequest() {
log.Entry().Debug("pull request detected") log.Entry().Debug("pull request detected")