From 50044273d0a24894d9faa380bbe4f7918e1eb36d Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Tue, 20 Aug 2024 11:18:07 +0300 Subject: [PATCH 01/10] Itay/Support scs engine with scan create resubmit and tests --- internal/commands/scan.go | 27 +++++++++-- internal/commands/scan_test.go | 89 +++++++++++++++++++++++++++++++++- 2 files changed, 111 insertions(+), 5 deletions(-) diff --git a/internal/commands/scan.go b/internal/commands/scan.go index be5dcbe80..66a5b3f6e 100644 --- a/internal/commands/scan.go +++ b/internal/commands/scan.go @@ -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." + @@ -750,6 +751,7 @@ func setupScanTypeProjectAndConfig( userScanTypes, _ := cmd.Flags().GetString(commonParams.ScanTypes) // Get the latest scan configuration resubmitConfig, _ = getResubmitConfiguration(scansWrapper, projectID, userScanTypes) + } else if _, ok := info["config"]; !ok { err := json.Unmarshal([]byte("[]"), &configArr) if err != nil { @@ -779,7 +781,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 { @@ -974,8 +976,8 @@ func addAPISecScan(cmd *cobra.Command) map[string]interface{} { return nil } -func addSCSScan(cmd *cobra.Command) (map[string]interface{}, error) { - if scanTypeEnabled(commonParams.ScsType) { +func addSCSScan(cmd *cobra.Command, resubmitConfig []wrappers.Config) (map[string]interface{}, error) { + if scanTypeEnabled(commonParams.ScsType) || scanTypeEnabled(commonParams.MicroEnginesType) { SCSMapConfig := make(map[string]interface{}) SCSConfig := wrappers.SCSConfig{} SCSMapConfig[resultsMapType] = commonParams.MicroEnginesType // scs is still microengines in the scans API @@ -983,6 +985,25 @@ func addSCSScan(cmd *cobra.Command) (map[string]interface{}, error) { SCSRepoToken, _ := cmd.Flags().GetString(commonParams.SCSRepoTokenFlag) SCSRepoURL, _ := cmd.Flags().GetString(commonParams.SCSRepoURLFlag) SCSEngines, _ := cmd.Flags().GetString(commonParams.SCSEnginesFlag) + if resubmitConfig != nil { + 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 + } + + } + SCSMapConfig[resultsMapValue] = &SCSConfig + return SCSMapConfig, nil + } if SCSEngines != "" { SCSEnginesTypes := strings.Split(SCSEngines, ",") for _, engineType := range SCSEnginesTypes { diff --git a/internal/commands/scan_test.go b/internal/commands/scan_test.go index 5bf0ba199..894fa97b7 100644 --- a/internal/commands/scan_test.go +++ b/internal/commands/scan_test.go @@ -664,6 +664,89 @@ func TestAddScaScan(t *testing.T) { t.Errorf("Expected %+v, but got %+v", scaMapConfig, result) } } +func TestAddSCSScan_ResubmitWithOutScorecardFlags_ShouldPass(t *testing.T) { + cmdCommand := &cobra.Command{ + Use: "scan", + Short: "Scan a project", + } + cmdCommand.PersistentFlags().String(commonParams.ScanTypes, "", "Scan types") + cmdCommand.PersistentFlags().String(commonParams.SCSRepoTokenFlag, "", "SCS Repo Token") + cmdCommand.PersistentFlags().String(commonParams.SCSRepoURLFlag, "", "SCS Repo URL") + + _ = cmdCommand.Execute() + + _ = cmdCommand.Flags().Set(commonParams.ScanTypes, commonParams.ScsType) + _ = cmdCommand.Flags().Set(commonParams.SCSRepoURLFlag, "") + _ = cmdCommand.Flags().Set(commonParams.SCSRepoTokenFlag, "") + + resubmitConfig := []wrappers.Config{ + { + Type: commonParams.ScsType, + Value: map[string]interface{}{ + configTwoms: "true", + ScsScoreCardType: falseString, + }, + }, + } + + result, _ := addSCSScan(cmdCommand, resubmitConfig) + + expectedConfig := wrappers.SCSConfig{ + Twoms: "true", + Scorecard: falseString, + } + + expectedMapConfig := make(map[string]interface{}) + expectedMapConfig[resultsMapType] = commonParams.MicroEnginesType + expectedMapConfig[resultsMapValue] = &expectedConfig + + if !reflect.DeepEqual(result, expectedMapConfig) { + t.Errorf("Expected %+v, but got %+v", expectedMapConfig, result) + } +} + +func TestAddSCSScan_ResubmitWithScorecardFlags_ShouldPass(t *testing.T) { + cmdCommand := &cobra.Command{ + Use: "scan", + Short: "Scan a project", + } + cmdCommand.PersistentFlags().String(commonParams.ScanTypes, "", "Scan types") + cmdCommand.PersistentFlags().String(commonParams.SCSRepoTokenFlag, "", "SCS Repo Token") + cmdCommand.PersistentFlags().String(commonParams.SCSRepoURLFlag, "", "SCS Repo URL") + + _ = cmdCommand.Execute() + + _ = cmdCommand.Flags().Set(commonParams.ScanTypes, commonParams.ScsType) + _ = cmdCommand.Flags().Set(commonParams.SCSRepoURLFlag, dummyRepo) + _ = cmdCommand.Flags().Set(commonParams.SCSRepoTokenFlag, dummyToken) + + resubmitConfig := []wrappers.Config{ + { + Type: commonParams.ScsType, + Value: map[string]interface{}{ + configTwoms: "true", + ScsScoreCardType: trueString, + }, + }, + } + + result, _ := addSCSScan(cmdCommand, resubmitConfig) + + expectedConfig := wrappers.SCSConfig{ + Twoms: "true", + Scorecard: trueString, + RepoToken: dummyToken, + RepoURL: dummyRepo, + } + + expectedMapConfig := make(map[string]interface{}) + expectedMapConfig[resultsMapType] = commonParams.MicroEnginesType + expectedMapConfig[resultsMapValue] = &expectedConfig + + if !reflect.DeepEqual(result, expectedMapConfig) { + t.Errorf("Expected %+v, but got %+v", expectedMapConfig, result) + } +} func TestAddSastScan_WithFastScanFlag_ShouldPass(t *testing.T) { var resubmitConfig []wrappers.Config @@ -809,6 +892,7 @@ func TestCreateScan_WithSCSScorecard_ShouldFail(t *testing.T) { } func TestCreateScan_WithSCSSecretDetectionAndScorecard_scsMapHasBoth(t *testing.T) { + var resubmitConfig []wrappers.Config cmdCommand := &cobra.Command{ Use: "scan", Short: "Scan a project", @@ -822,7 +906,7 @@ func TestCreateScan_WithSCSSecretDetectionAndScorecard_scsMapHasBoth(t *testing. _ = cmdCommand.Flags().Set(commonParams.SCSRepoTokenFlag, dummyToken) _ = cmdCommand.Flags().Set(commonParams.SCSRepoURLFlag, dummyRepo) - result, _ := addSCSScan(cmdCommand) + result, _ := addSCSScan(cmdCommand, resubmitConfig) scsConfig := wrappers.SCSConfig{ Twoms: "true", @@ -840,6 +924,7 @@ func TestCreateScan_WithSCSSecretDetectionAndScorecard_scsMapHasBoth(t *testing. } func TestCreateScan_WithSCSSecretDetection_scsMapHasSecretDetection(t *testing.T) { + var resubmitConfig []wrappers.Config cmdCommand := &cobra.Command{ Use: "scan", Short: "Scan a project", @@ -849,7 +934,7 @@ func TestCreateScan_WithSCSSecretDetection_scsMapHasSecretDetection(t *testing.T _ = cmdCommand.Execute() _ = cmdCommand.Flags().Set(commonParams.SCSEnginesFlag, "secret-detection") - result, _ := addSCSScan(cmdCommand) + result, _ := addSCSScan(cmdCommand, resubmitConfig) scsConfig := wrappers.SCSConfig{ Twoms: "true", From d4bb15db4e2f2ace4df1f293d8aae31fe44de9b5 Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Tue, 20 Aug 2024 11:35:25 +0300 Subject: [PATCH 02/10] fix linter --- internal/commands/scan.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/commands/scan.go b/internal/commands/scan.go index 66a5b3f6e..de4084b32 100644 --- a/internal/commands/scan.go +++ b/internal/commands/scan.go @@ -751,7 +751,6 @@ func setupScanTypeProjectAndConfig( userScanTypes, _ := cmd.Flags().GetString(commonParams.ScanTypes) // Get the latest scan configuration resubmitConfig, _ = getResubmitConfiguration(scansWrapper, projectID, userScanTypes) - } else if _, ok := info["config"]; !ok { err := json.Unmarshal([]byte("[]"), &configArr) if err != nil { From 7babb9a06bd1994e25be88e26b5300de5170d45e Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Tue, 20 Aug 2024 11:38:32 +0300 Subject: [PATCH 03/10] fix linter --- internal/commands/scan.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/commands/scan.go b/internal/commands/scan.go index de4084b32..6e5fff7db 100644 --- a/internal/commands/scan.go +++ b/internal/commands/scan.go @@ -998,7 +998,6 @@ func addSCSScan(cmd *cobra.Command, resubmitConfig []wrappers.Config) (map[strin } else { SCSConfig.Scorecard = falseString } - } SCSMapConfig[resultsMapValue] = &SCSConfig return SCSMapConfig, nil From 9f7cbbb33e1ae249a693244c9f4a184bfeb962e7 Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Tue, 20 Aug 2024 12:57:47 +0300 Subject: [PATCH 04/10] fix cyclomatic complexity error --- internal/commands/scan.go | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/internal/commands/scan.go b/internal/commands/scan.go index 6e5fff7db..7ae2ce1c3 100644 --- a/internal/commands/scan.go +++ b/internal/commands/scan.go @@ -974,6 +974,22 @@ func addAPISecScan(cmd *cobra.Command) map[string]interface{} { } return nil } +func processResubmitConfig(SCSConfig *wrappers.SCSConfig, resubmitConfig []wrappers.Config, SCSRepoToken, SCSRepoURL string) { + 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 + } + } +} func addSCSScan(cmd *cobra.Command, resubmitConfig []wrappers.Config) (map[string]interface{}, error) { if scanTypeEnabled(commonParams.ScsType) || scanTypeEnabled(commonParams.MicroEnginesType) { @@ -985,20 +1001,7 @@ func addSCSScan(cmd *cobra.Command, resubmitConfig []wrappers.Config) (map[strin SCSRepoURL, _ := cmd.Flags().GetString(commonParams.SCSRepoURLFlag) SCSEngines, _ := cmd.Flags().GetString(commonParams.SCSEnginesFlag) if resubmitConfig != nil { - 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 - } - } + processResubmitConfig(&SCSConfig, resubmitConfig, SCSRepoToken, SCSRepoURL) SCSMapConfig[resultsMapValue] = &SCSConfig return SCSMapConfig, nil } From d406d0618f32baa231a69850ece2b6a11cb10230 Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Tue, 20 Aug 2024 13:00:31 +0300 Subject: [PATCH 05/10] Fix pr comments --- internal/commands/scan_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/commands/scan_test.go b/internal/commands/scan_test.go index 894fa97b7..2f9ae39d4 100644 --- a/internal/commands/scan_test.go +++ b/internal/commands/scan_test.go @@ -683,7 +683,7 @@ func TestAddSCSScan_ResubmitWithOutScorecardFlags_ShouldPass(t *testing.T) { { Type: commonParams.ScsType, Value: map[string]interface{}{ - configTwoms: "true", + configTwoms: trueString, ScsScoreCardType: falseString, }, }, @@ -692,7 +692,7 @@ func TestAddSCSScan_ResubmitWithOutScorecardFlags_ShouldPass(t *testing.T) { result, _ := addSCSScan(cmdCommand, resubmitConfig) expectedConfig := wrappers.SCSConfig{ - Twoms: "true", + Twoms: trueString, Scorecard: falseString, } @@ -724,7 +724,7 @@ func TestAddSCSScan_ResubmitWithScorecardFlags_ShouldPass(t *testing.T) { { Type: commonParams.ScsType, Value: map[string]interface{}{ - configTwoms: "true", + configTwoms: trueString, ScsScoreCardType: trueString, }, }, From bd3e8e0aadcb2701871e5f415bdde1ae07a6789e Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Tue, 20 Aug 2024 13:34:38 +0300 Subject: [PATCH 06/10] Fix pr lint errors --- internal/commands/scan.go | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/internal/commands/scan.go b/internal/commands/scan.go index 7ae2ce1c3..c1e1f6e0c 100644 --- a/internal/commands/scan.go +++ b/internal/commands/scan.go @@ -974,35 +974,34 @@ func addAPISecScan(cmd *cobra.Command) map[string]interface{} { } return nil } -func processResubmitConfig(SCSConfig *wrappers.SCSConfig, resubmitConfig []wrappers.Config, SCSRepoToken, SCSRepoURL string) { +func processResubmitConfig(scsConfig *wrappers.SCSConfig, resubmitConfig []wrappers.Config, SCSRepoToken, SCSRepoURL string) { for _, config := range resubmitConfig { resubmitTwoms := config.Value[configTwoms] if resubmitTwoms != nil { - SCSConfig.Twoms = resubmitTwoms.(string) + scsConfig.Twoms = resubmitTwoms.(string) } - SCSConfig.RepoURL = SCSRepoURL - SCSConfig.RepoToken = SCSRepoToken + scsConfig.RepoURL = SCSRepoURL + scsConfig.RepoToken = SCSRepoToken resubmitScoreCard := config.Value[ScsScoreCardType] if resubmitScoreCard == trueString && SCSRepoToken != "" && SCSRepoURL != "" { - SCSConfig.Scorecard = trueString + scsConfig.Scorecard = trueString } else { - SCSConfig.Scorecard = falseString + scsConfig.Scorecard = falseString } } } - func addSCSScan(cmd *cobra.Command, resubmitConfig []wrappers.Config) (map[string]interface{}, error) { if scanTypeEnabled(commonParams.ScsType) || scanTypeEnabled(commonParams.MicroEnginesType) { SCSMapConfig := make(map[string]interface{}) - SCSConfig := wrappers.SCSConfig{} + 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) SCSEngines, _ := cmd.Flags().GetString(commonParams.SCSEnginesFlag) if resubmitConfig != nil { - processResubmitConfig(&SCSConfig, resubmitConfig, SCSRepoToken, SCSRepoURL) - SCSMapConfig[resultsMapValue] = &SCSConfig + processResubmitConfig(&scsConfig, resubmitConfig, SCSRepoToken, SCSRepoURL) + SCSMapConfig[resultsMapValue] = &scsConfig return SCSMapConfig, nil } if SCSEngines != "" { @@ -1011,19 +1010,19 @@ func addSCSScan(cmd *cobra.Command, resubmitConfig []wrappers.Config) (map[strin 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 scsConfig.Scorecard == trueString { if SCSRepoToken != "" && SCSRepoURL != "" { - SCSConfig.RepoToken = SCSRepoToken - SCSConfig.RepoURL = strings.ToLower(SCSRepoURL) + scsConfig.RepoToken = SCSRepoToken + scsConfig.RepoURL = strings.ToLower(SCSRepoURL) } else { if userScanTypes == "" { fmt.Println(ScsRepoRequiredMsg) @@ -1032,7 +1031,7 @@ func addSCSScan(cmd *cobra.Command, resubmitConfig []wrappers.Config) (map[strin return nil, errors.Errorf(ScsRepoRequiredMsg) } } - SCSMapConfig[resultsMapValue] = &SCSConfig + SCSMapConfig[resultsMapValue] = &scsConfig return SCSMapConfig, nil } return nil, nil From 15a0a978a0e81b5e21b5f76d5e1134f03d896e20 Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Tue, 20 Aug 2024 13:41:38 +0300 Subject: [PATCH 07/10] Fix pr lint errors --- internal/commands/scan.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/commands/scan.go b/internal/commands/scan.go index c1e1f6e0c..8e6089186 100644 --- a/internal/commands/scan.go +++ b/internal/commands/scan.go @@ -974,16 +974,16 @@ func addAPISecScan(cmd *cobra.Command) map[string]interface{} { } return nil } -func processResubmitConfig(scsConfig *wrappers.SCSConfig, resubmitConfig []wrappers.Config, SCSRepoToken, SCSRepoURL string) { +func processResubmitConfig(scsConfig *wrappers.SCSConfig, resubmitConfig []wrappers.Config, scsRepoToken, scsRepoUrl string) { for _, config := range resubmitConfig { resubmitTwoms := config.Value[configTwoms] if resubmitTwoms != nil { scsConfig.Twoms = resubmitTwoms.(string) } - scsConfig.RepoURL = SCSRepoURL - scsConfig.RepoToken = SCSRepoToken + scsConfig.RepoURL = scsRepoUrl + scsConfig.RepoToken = scsRepoToken resubmitScoreCard := config.Value[ScsScoreCardType] - if resubmitScoreCard == trueString && SCSRepoToken != "" && SCSRepoURL != "" { + if resubmitScoreCard == trueString && scsRepoToken != "" && scsRepoUrl != "" { scsConfig.Scorecard = trueString } else { scsConfig.Scorecard = falseString @@ -996,11 +996,11 @@ func addSCSScan(cmd *cobra.Command, resubmitConfig []wrappers.Config) (map[strin 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 { - processResubmitConfig(&scsConfig, resubmitConfig, SCSRepoToken, SCSRepoURL) + processResubmitConfig(&scsConfig, resubmitConfig, scsRepoToken, scsRepoUrl) SCSMapConfig[resultsMapValue] = &scsConfig return SCSMapConfig, nil } @@ -1020,9 +1020,9 @@ func addSCSScan(cmd *cobra.Command, resubmitConfig []wrappers.Config) (map[strin scsConfig.Twoms = trueString } if scsConfig.Scorecard == trueString { - if SCSRepoToken != "" && SCSRepoURL != "" { - scsConfig.RepoToken = SCSRepoToken - scsConfig.RepoURL = strings.ToLower(SCSRepoURL) + if scsRepoToken != "" && scsRepoUrl != "" { + scsConfig.RepoToken = scsRepoToken + scsConfig.RepoURL = strings.ToLower(scsRepoUrl) } else { if userScanTypes == "" { fmt.Println(ScsRepoRequiredMsg) From 5ee272fa59a87231f38af5f46c33f0e58033628b Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Tue, 20 Aug 2024 13:46:58 +0300 Subject: [PATCH 08/10] fix pr --- internal/commands/scan.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/commands/scan.go b/internal/commands/scan.go index 8e6089186..31d325ff2 100644 --- a/internal/commands/scan.go +++ b/internal/commands/scan.go @@ -974,16 +974,16 @@ func addAPISecScan(cmd *cobra.Command) map[string]interface{} { } return nil } -func processResubmitConfig(scsConfig *wrappers.SCSConfig, resubmitConfig []wrappers.Config, scsRepoToken, scsRepoUrl string) { +func processResubmitConfig(scsConfig *wrappers.SCSConfig, resubmitConfig []wrappers.Config, scsRepoToken, scsRepoURL string) { for _, config := range resubmitConfig { resubmitTwoms := config.Value[configTwoms] if resubmitTwoms != nil { scsConfig.Twoms = resubmitTwoms.(string) } - scsConfig.RepoURL = scsRepoUrl + scsConfig.RepoURL = scsRepoURL scsConfig.RepoToken = scsRepoToken resubmitScoreCard := config.Value[ScsScoreCardType] - if resubmitScoreCard == trueString && scsRepoToken != "" && scsRepoUrl != "" { + if resubmitScoreCard == trueString && scsRepoToken != "" && scsRepoURL != "" { scsConfig.Scorecard = trueString } else { scsConfig.Scorecard = falseString @@ -997,10 +997,10 @@ func addSCSScan(cmd *cobra.Command, resubmitConfig []wrappers.Config) (map[strin 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) + scsRepoURL, _ := cmd.Flags().GetString(commonParams.SCSRepoURLFlag) SCSEngines, _ := cmd.Flags().GetString(commonParams.SCSEnginesFlag) if resubmitConfig != nil { - processResubmitConfig(&scsConfig, resubmitConfig, scsRepoToken, scsRepoUrl) + processResubmitConfig(&scsConfig, resubmitConfig, scsRepoToken, scsRepoURL) SCSMapConfig[resultsMapValue] = &scsConfig return SCSMapConfig, nil } @@ -1020,9 +1020,9 @@ func addSCSScan(cmd *cobra.Command, resubmitConfig []wrappers.Config) (map[strin scsConfig.Twoms = trueString } if scsConfig.Scorecard == trueString { - if scsRepoToken != "" && scsRepoUrl != "" { + if scsRepoToken != "" && scsRepoURL != "" { scsConfig.RepoToken = scsRepoToken - scsConfig.RepoURL = strings.ToLower(scsRepoUrl) + scsConfig.RepoURL = strings.ToLower(scsRepoURL) } else { if userScanTypes == "" { fmt.Println(ScsRepoRequiredMsg) From 3112218c56b6ffd31a97dd5aabacc82e1e3df585 Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Tue, 20 Aug 2024 15:23:08 +0300 Subject: [PATCH 09/10] change help function to return new obj from pass by referance --- internal/commands/scan.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/commands/scan.go b/internal/commands/scan.go index 31d325ff2..88072af21 100644 --- a/internal/commands/scan.go +++ b/internal/commands/scan.go @@ -974,7 +974,8 @@ func addAPISecScan(cmd *cobra.Command) map[string]interface{} { } return nil } -func processResubmitConfig(scsConfig *wrappers.SCSConfig, resubmitConfig []wrappers.Config, scsRepoToken, scsRepoURL string) { +func createResubmitConfig(resubmitConfig []wrappers.Config, scsRepoToken, scsRepoURL string) wrappers.SCSConfig { + scsConfig := wrappers.SCSConfig{} for _, config := range resubmitConfig { resubmitTwoms := config.Value[configTwoms] if resubmitTwoms != nil { @@ -989,18 +990,19 @@ func processResubmitConfig(scsConfig *wrappers.SCSConfig, resubmitConfig []wrapp scsConfig.Scorecard = falseString } } + return scsConfig } func addSCSScan(cmd *cobra.Command, resubmitConfig []wrappers.Config) (map[string]interface{}, error) { if scanTypeEnabled(commonParams.ScsType) || scanTypeEnabled(commonParams.MicroEnginesType) { - SCSMapConfig := make(map[string]interface{}) scsConfig := wrappers.SCSConfig{} + SCSMapConfig := make(map[string]interface{}) 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) SCSEngines, _ := cmd.Flags().GetString(commonParams.SCSEnginesFlag) if resubmitConfig != nil { - processResubmitConfig(&scsConfig, resubmitConfig, scsRepoToken, scsRepoURL) + scsConfig := createResubmitConfig(resubmitConfig, scsRepoToken, scsRepoURL) SCSMapConfig[resultsMapValue] = &scsConfig return SCSMapConfig, nil } From d0f97b24f5e17994c4dd680365df628877602096 Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Tue, 20 Aug 2024 17:41:33 +0300 Subject: [PATCH 10/10] fix linter --- internal/commands/scan.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/commands/scan.go b/internal/commands/scan.go index 88072af21..0b1367fcd 100644 --- a/internal/commands/scan.go +++ b/internal/commands/scan.go @@ -1002,7 +1002,7 @@ func addSCSScan(cmd *cobra.Command, resubmitConfig []wrappers.Config) (map[strin scsRepoURL, _ := cmd.Flags().GetString(commonParams.SCSRepoURLFlag) SCSEngines, _ := cmd.Flags().GetString(commonParams.SCSEnginesFlag) if resubmitConfig != nil { - scsConfig := createResubmitConfig(resubmitConfig, scsRepoToken, scsRepoURL) + scsConfig = createResubmitConfig(resubmitConfig, scsRepoToken, scsRepoURL) SCSMapConfig[resultsMapValue] = &scsConfig return SCSMapConfig, nil }