Skip to content
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

Add functionality to use SCS repo token as env var (AST-75938) #955

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion internal/commands/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,10 @@ func addSCSScan(cmd *cobra.Command, resubmitConfig []wrappers.Config, hasEnterpr
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)
scsRepoToken := viper.GetString(commonParams.ScsRepoTokenKey)
if token, _ := cmd.Flags().GetString(commonParams.SCSRepoTokenFlag); token != "" {
scsRepoToken = token
}
viper.Set(commonParams.SCSRepoTokenFlag, scsRepoToken) // sanitizeLogs uses viper to get the value
scsRepoURL, _ := cmd.Flags().GetString(commonParams.SCSRepoURLFlag)
viper.Set(commonParams.SCSRepoURLFlag, scsRepoURL) // sanitizeLogs uses viper to get the value
Expand Down
1 change: 1 addition & 0 deletions internal/params/binds.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@ var EnvVarsBinds = []struct {
{AiProxyAzureAiRouteKey, AiProxyAzureAiRouteEnv, "api/ai-proxy/redirect/externalAzure"},
{AiProxyCheckmarxAiRouteKey, AiProxyCheckmarxAiRouteEnv, "api/ai-proxy/redirect/azure"},
{ASCAPortKey, ASCAPortEnv, ""},
{ScsRepoTokenKey, ScsRepoTokenEnv, ""},
}
1 change: 1 addition & 0 deletions internal/params/envs.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ const (
AiProxyAzureAiRouteEnv = "CX_AIPROXY_AZUREAI_ROUTE"
AiProxyCheckmarxAiRouteEnv = "CX_AIPROXY_CHECKMARXAI_ROUTE"
ASCAPortEnv = "CX_ASCA_PORT"
ScsRepoTokenEnv = "SCS_REPO_TOKEN"
)
1 change: 1 addition & 0 deletions internal/params/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ var (
AiProxyAzureAiRouteKey = strings.ToLower(AiProxyAzureAiRouteEnv)
AiProxyCheckmarxAiRouteKey = strings.ToLower(AiProxyCheckmarxAiRouteEnv)
ASCAPortKey = strings.ToLower(ASCAPortEnv)
ScsRepoTokenKey = strings.ToLower(ScsRepoTokenEnv)
)
23 changes: 22 additions & 1 deletion test/integration/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,6 @@ func getCreateArgsWithNameAndGroups(source string, tags map[string]string, group
flag(params.TagList), formatTags(tags),
flag(params.BranchFlag), SlowRepoBranch,
flag(params.ProjectGroupList), formatGroups(groups),
flag(params.DebugFlag),
}

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

func TestCreateScan_WithTypeScsMissingRepoToken_Fail(t *testing.T) {
_, projectName := getRootProject(t)
scsRepoTokenEnvValue := os.Getenv(params.ScsRepoTokenEnv)
defer setEnvVars(map[string]string{params.ScsRepoTokenEnv: scsRepoTokenEnvValue})

setEnvVars(map[string]string{
params.ScsRepoTokenEnv: "",
})

args := []string{
"scan", "create",
flag(params.ProjectName), projectName,
flag(params.SourcesFlag), Zip,
flag(params.ScanTypes), "iac-security, scs",
flag(params.BranchFlag), "main",
flag(params.SCSRepoURLFlag), scsRepoURL,
}

err, _ := executeCommand(t, args...)
assert.Error(t, err, commands.ScsRepoRequiredMsg)
}

func TestCreateScan_ScsRepoTokenEnvConfigured_Success(t *testing.T) {
_, projectName := getRootProject(t)

args := []string{
"scan", "create",
Expand Down
Loading