-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support scs engine In scan create Resubmit command (AST-63906) #840
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5004427
Itay/Support scs engine with scan create resubmit and tests
Korjen97 5916275
Merge branch 'main' into Itay/support-SCS-in-scan-create
Korjen97 d4bb15d
fix linter
Korjen97 66e8edf
Merge branch 'Itay/support-SCS-in-scan-create' of https://github.com/…
Korjen97 7babb9a
fix linter
Korjen97 9f7cbbb
fix cyclomatic complexity error
Korjen97 d406d06
Fix pr comments
Korjen97 bd3e8e0
Fix pr lint errors
Korjen97 15a0a97
Fix pr lint errors
Korjen97 5ee272f
fix pr
Korjen97 3112218
change help function to return new obj from pass by referance
Korjen97 d0f97b2
fix linter
Korjen97 8d065e9
Merge branch 'main' into Itay/support-SCS-in-scan-create
Korjen97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,7 @@ const ( | |
resultsMapValue = "value" | ||
resultsMapType = "type" | ||
trueString = "true" | ||
configTwoms = "2ms" | ||
falseString = "false" | ||
maxPollingWaitTime = 60 | ||
engineNotAllowed = "It looks like the \"%s\" scan type does not exist or you are trying to run a scan without the \"%s\" package license." + | ||
|
@@ -779,7 +780,7 @@ func setupScanTypeProjectAndConfig( | |
configArr = append(configArr, containersConfig) | ||
} | ||
|
||
var SCSConfig, scsErr = addSCSScan(cmd) | ||
var SCSConfig, scsErr = addSCSScan(cmd, resubmitConfig) | ||
if scsErr != nil { | ||
return scsErr | ||
} else if SCSConfig != nil { | ||
|
@@ -973,35 +974,57 @@ func addAPISecScan(cmd *cobra.Command) map[string]interface{} { | |
} | ||
return nil | ||
} | ||
|
||
func addSCSScan(cmd *cobra.Command) (map[string]interface{}, error) { | ||
if scanTypeEnabled(commonParams.ScsType) { | ||
func createResubmitConfig(resubmitConfig []wrappers.Config, scsRepoToken, scsRepoURL string) wrappers.SCSConfig { | ||
scsConfig := wrappers.SCSConfig{} | ||
for _, config := range resubmitConfig { | ||
resubmitTwoms := config.Value[configTwoms] | ||
if resubmitTwoms != nil { | ||
scsConfig.Twoms = resubmitTwoms.(string) | ||
} | ||
scsConfig.RepoURL = scsRepoURL | ||
scsConfig.RepoToken = scsRepoToken | ||
resubmitScoreCard := config.Value[ScsScoreCardType] | ||
if resubmitScoreCard == trueString && scsRepoToken != "" && scsRepoURL != "" { | ||
scsConfig.Scorecard = trueString | ||
} else { | ||
scsConfig.Scorecard = falseString | ||
} | ||
} | ||
return scsConfig | ||
} | ||
func addSCSScan(cmd *cobra.Command, resubmitConfig []wrappers.Config) (map[string]interface{}, error) { | ||
if scanTypeEnabled(commonParams.ScsType) || scanTypeEnabled(commonParams.MicroEnginesType) { | ||
scsConfig := wrappers.SCSConfig{} | ||
SCSMapConfig := make(map[string]interface{}) | ||
SCSConfig := wrappers.SCSConfig{} | ||
SCSMapConfig[resultsMapType] = commonParams.MicroEnginesType // scs is still microengines in the scans API | ||
userScanTypes, _ := cmd.Flags().GetString(commonParams.ScanTypes) | ||
SCSRepoToken, _ := cmd.Flags().GetString(commonParams.SCSRepoTokenFlag) | ||
SCSRepoURL, _ := cmd.Flags().GetString(commonParams.SCSRepoURLFlag) | ||
scsRepoToken, _ := cmd.Flags().GetString(commonParams.SCSRepoTokenFlag) | ||
scsRepoURL, _ := cmd.Flags().GetString(commonParams.SCSRepoURLFlag) | ||
SCSEngines, _ := cmd.Flags().GetString(commonParams.SCSEnginesFlag) | ||
if resubmitConfig != nil { | ||
scsConfig = createResubmitConfig(resubmitConfig, scsRepoToken, scsRepoURL) | ||
SCSMapConfig[resultsMapValue] = &scsConfig | ||
return SCSMapConfig, nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont you need the config builder to finish his work first? |
||
} | ||
if SCSEngines != "" { | ||
SCSEnginesTypes := strings.Split(SCSEngines, ",") | ||
for _, engineType := range SCSEnginesTypes { | ||
engineType = strings.TrimSpace(engineType) | ||
switch engineType { | ||
case ScsSecretDetectionType: | ||
SCSConfig.Twoms = trueString | ||
scsConfig.Twoms = trueString | ||
case ScsScoreCardType: | ||
SCSConfig.Scorecard = trueString | ||
scsConfig.Scorecard = trueString | ||
} | ||
} | ||
} else { | ||
SCSConfig.Scorecard = trueString | ||
SCSConfig.Twoms = trueString | ||
scsConfig.Scorecard = trueString | ||
scsConfig.Twoms = trueString | ||
} | ||
if SCSConfig.Scorecard == trueString { | ||
if SCSRepoToken != "" && SCSRepoURL != "" { | ||
SCSConfig.RepoToken = SCSRepoToken | ||
SCSConfig.RepoURL = strings.ToLower(SCSRepoURL) | ||
if scsConfig.Scorecard == trueString { | ||
if scsRepoToken != "" && scsRepoURL != "" { | ||
scsConfig.RepoToken = scsRepoToken | ||
scsConfig.RepoURL = strings.ToLower(scsRepoURL) | ||
} else { | ||
if userScanTypes == "" { | ||
fmt.Println(ScsRepoRequiredMsg) | ||
|
@@ -1010,7 +1033,7 @@ func addSCSScan(cmd *cobra.Command) (map[string]interface{}, error) { | |
return nil, errors.Errorf(ScsRepoRequiredMsg) | ||
} | ||
} | ||
SCSMapConfig[resultsMapValue] = &SCSConfig | ||
SCSMapConfig[resultsMapValue] = &scsConfig | ||
return SCSMapConfig, nil | ||
} | ||
return nil, nil | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the difference between the regular config building and resubmit? Can't we re-use the regular build config?