Skip to content

Commit 8ad0c8b

Browse files
CLI | Add functionality to use SCS repo token as env var (AST-75938) (#956)
* Add functionality to use SCS repo token as env var * added and fixed existing tests * added test and fixed existing tests --------- Co-authored-by: AlvoBen <[email protected]>
1 parent 2004d56 commit 8ad0c8b

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

internal/commands/scan.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,10 @@ func addSCSScan(cmd *cobra.Command, resubmitConfig []wrappers.Config, hasEnterpr
10061006
SCSMapConfig := make(map[string]interface{})
10071007
SCSMapConfig[resultsMapType] = commonParams.MicroEnginesType // scs is still microengines in the scans API
10081008
userScanTypes, _ := cmd.Flags().GetString(commonParams.ScanTypes)
1009-
scsRepoToken, _ := cmd.Flags().GetString(commonParams.SCSRepoTokenFlag)
1009+
scsRepoToken := viper.GetString(commonParams.ScsRepoTokenKey)
1010+
if token, _ := cmd.Flags().GetString(commonParams.SCSRepoTokenFlag); token != "" {
1011+
scsRepoToken = token
1012+
}
10101013
viper.Set(commonParams.SCSRepoTokenFlag, scsRepoToken) // sanitizeLogs uses viper to get the value
10111014
scsRepoURL, _ := cmd.Flags().GetString(commonParams.SCSRepoURLFlag)
10121015
viper.Set(commonParams.SCSRepoURLFlag, scsRepoURL) // sanitizeLogs uses viper to get the value

internal/params/binds.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,5 @@ var EnvVarsBinds = []struct {
6868
{AiProxyAzureAiRouteKey, AiProxyAzureAiRouteEnv, "api/ai-proxy/redirect/externalAzure"},
6969
{AiProxyCheckmarxAiRouteKey, AiProxyCheckmarxAiRouteEnv, "api/ai-proxy/redirect/azure"},
7070
{ASCAPortKey, ASCAPortEnv, ""},
71+
{ScsRepoTokenKey, ScsRepoTokenEnv, ""},
7172
}

internal/params/envs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,5 @@ const (
6767
AiProxyAzureAiRouteEnv = "CX_AIPROXY_AZUREAI_ROUTE"
6868
AiProxyCheckmarxAiRouteEnv = "CX_AIPROXY_CHECKMARXAI_ROUTE"
6969
ASCAPortEnv = "CX_ASCA_PORT"
70+
ScsRepoTokenEnv = "SCS_REPO_TOKEN"
7071
)

internal/params/keys.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,5 @@ var (
6767
AiProxyAzureAiRouteKey = strings.ToLower(AiProxyAzureAiRouteEnv)
6868
AiProxyCheckmarxAiRouteKey = strings.ToLower(AiProxyCheckmarxAiRouteEnv)
6969
ASCAPortKey = strings.ToLower(ASCAPortEnv)
70+
ScsRepoTokenKey = strings.ToLower(ScsRepoTokenEnv)
7071
)

test/integration/scan_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,6 @@ func getCreateArgsWithNameAndGroups(source string, tags map[string]string, group
939939
flag(params.TagList), formatTags(tags),
940940
flag(params.BranchFlag), SlowRepoBranch,
941941
flag(params.ProjectGroupList), formatGroups(groups),
942-
flag(params.DebugFlag),
943942
}
944943

945944
if strings.Contains(scanTypes, "scs") {
@@ -1804,6 +1803,28 @@ func TestCreateScan_WithTypeScsMissingRepoURL_Fail(t *testing.T) {
18041803

18051804
func TestCreateScan_WithTypeScsMissingRepoToken_Fail(t *testing.T) {
18061805
_, projectName := getRootProject(t)
1806+
scsRepoTokenEnvValue := os.Getenv(params.ScsRepoTokenEnv)
1807+
defer setEnvVars(map[string]string{params.ScsRepoTokenEnv: scsRepoTokenEnvValue})
1808+
1809+
setEnvVars(map[string]string{
1810+
params.ScsRepoTokenEnv: "",
1811+
})
1812+
1813+
args := []string{
1814+
"scan", "create",
1815+
flag(params.ProjectName), projectName,
1816+
flag(params.SourcesFlag), Zip,
1817+
flag(params.ScanTypes), "iac-security, scs",
1818+
flag(params.BranchFlag), "main",
1819+
flag(params.SCSRepoURLFlag), scsRepoURL,
1820+
}
1821+
1822+
err, _ := executeCommand(t, args...)
1823+
assert.Error(t, err, commands.ScsRepoRequiredMsg)
1824+
}
1825+
1826+
func TestCreateScan_ScsRepoTokenEnvConfigured_Success(t *testing.T) {
1827+
_, projectName := getRootProject(t)
18071828

18081829
args := []string{
18091830
"scan", "create",

0 commit comments

Comments
 (0)