Skip to content

Commit

Permalink
Remove useDetect7 option (#4717)
Browse files Browse the repository at this point in the history
* removed-detect7-option

* linting-fix

* removed-comment
  • Loading branch information
dimaste authored Jan 8, 2024
1 parent 6cc6a4e commit f5f72bc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 86 deletions.
63 changes: 23 additions & 40 deletions cmd/detectExecuteScan.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,16 @@ func getDetectScript(config detectExecuteScanOptions, utils detectUtils) error {

log.Entry().Infof("Downloading Detect Script")

if config.UseDetect7 {
return utils.DownloadFile("https://detect.synopsys.com/detect7.sh", "detect.sh", nil, nil)
err := utils.DownloadFile("https://detect.synopsys.com/detect8.sh", "detect.sh", nil, nil)
if err != nil {
time.Sleep(time.Second * 5)
err = utils.DownloadFile("https://detect.synopsys.com/detect8.sh", "detect.sh", nil, nil)
if err != nil {
return err
}
}

return utils.DownloadFile("https://detect.synopsys.com/detect8.sh", "detect.sh", nil, nil)
return nil
}

func addDetectArgs(args []string, config detectExecuteScanOptions, utils detectUtils, sys *blackduckSystem) ([]string, error) {
Expand Down Expand Up @@ -376,49 +381,27 @@ func addDetectArgs(args []string, config detectExecuteScanOptions, utils detectU
codelocation = fmt.Sprintf("%v/%v", config.ProjectName, detectVersionName)
}

// Since detect8 adds quotes by default, to avoid double quotation they should be removed for several arguments
if config.UseDetect7 {
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))
args = append(args, fmt.Sprintf("\"--detect.project.name=%v\"", config.ProjectName))
args = append(args, fmt.Sprintf("\"--detect.project.version.name=%v\"", detectVersionName))

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, ",")))
}
// 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, ",")))
}

args = append(args, fmt.Sprintf("\"--detect.code.location.name=%v\"", codelocation))
// 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, ",")))
}

if len(mavenArgs) > 0 && !checkIfArgumentIsInScanProperties(config, "detect.maven.build.command") {
args = append(args, fmt.Sprintf("\"--detect.maven.build.command=%v\"", strings.Join(mavenArgs, " ")))
}
args = append(args, fmt.Sprintf("\"--detect.code.location.name=%v\"", codelocation))

args = append(args, fmt.Sprintf("\"--detect.force.success.on.skip=true\""))
if len(mavenArgs) > 0 && !checkIfArgumentIsInScanProperties(config, "detect.maven.build.command") {
args = append(args, fmt.Sprintf("\"--detect.maven.build.command=%v\"", strings.Join(mavenArgs, " ")))
}

args = append(args, fmt.Sprintf("\"--detect.force.success.on.skip=true\""))

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, ",")))
}
Expand Down
22 changes: 0 additions & 22 deletions cmd/detectExecuteScan_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 0 additions & 24 deletions resources/metadata/detectExecuteScan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -301,30 +301,6 @@ spec:
- STAGES
- STEPS
deprecated: true
- name: useDetect7
description:
"This flag allows to use the currently supported 8 version of Detect Script instead of v7"
aliases:
- name: detect/useDetect7
type: bool
scope:
- PARAMETERS
- STAGES
- STEPS
default: false
- name: useDetect8
description:
"This flag allows to use the currently supported 8 version of Detect Script instead of v7"
aliases:
- name: detect/useDetect8
deprecated: true
type: bool
scope:
- PARAMETERS
- STAGES
- STEPS
default: true
deprecated: true
- name: successOnSkip
description:
"This flag allows forces Black Duck to exit with 0 error code if any step is skipped"
Expand Down

0 comments on commit f5f72bc

Please sign in to comment.