Skip to content

Commit

Permalink
chore: support local and remote code report
Browse files Browse the repository at this point in the history
  • Loading branch information
sandor-trombitas authored and PeterSchafer committed Feb 27, 2025
1 parent 00bc4ff commit 396b2b7
Show file tree
Hide file tree
Showing 20 changed files with 818 additions and 367 deletions.
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.33.0
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
github.com/snyk/code-client-go v1.13.1
github.com/snyk/code-client-go v1.14.2-0.20250227153650-c248591556ec
github.com/snyk/go-httpauth v0.0.0-20231117135515-eb445fea7530
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
Expand All @@ -26,12 +26,12 @@ require (
)

require (
github.com/go-git/go-git/v5 v5.13.2
github.com/go-git/go-git/v5 v5.14.0
github.com/gofrs/flock v0.12.1
github.com/mattn/go-isatty v0.0.20
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1
github.com/oapi-codegen/runtime v1.1.1
github.com/snyk/error-catalog-golang-public v0.0.0-20241030160523-0aa643bb7069
github.com/snyk/error-catalog-golang-public v0.0.0-20250218074309-307ad7b38a60
github.com/subosito/gotenv v1.4.1
golang.org/x/sync v0.11.0
gopkg.in/yaml.v3 v3.0.1
Expand Down Expand Up @@ -91,7 +91,7 @@ require (
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/puzpuzpuz/xsync v1.5.2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/rogpeppe/go-internal v1.14.1 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/skeema/knownhosts v1.3.1 // indirect
github.com/speakeasy-api/openapi-overlay v0.9.0 // indirect
Expand All @@ -116,3 +116,5 @@ require (
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

//replace github.com/snyk/code-client-go => ../code-client-go
24 changes: 12 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8Yc
github.com/dprotaso/go-yit v0.0.0-20191028211022-135eb7262960/go.mod h1:9HQzr9D/0PGwMEbC3d5AB7oi67+h4TsQqItC1GVYG58=
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 h1:PRxIJD8XjimM5aTknUK9w6DHLDox2r2M3DI4i2pnd3w=
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936/go.mod h1:ttYvX5qlB+mlV1okblJqcSMtR4c52UKxDiX9GRBS8+Q=
github.com/elazarl/goproxy v1.4.0 h1:4GyuSbFa+s26+3rmYNSuUVsx+HgPrV1bk1jXI0l9wjM=
github.com/elazarl/goproxy v1.4.0/go.mod h1:X/5W/t+gzDyLfHW4DrMdpjqYjpXsURlBt9lpBDxZZZQ=
github.com/elazarl/goproxy v1.7.2 h1:Y2o6urb7Eule09PjlhQRGNsqRfPmYI3KKQLFpCAV3+o=
github.com/elazarl/goproxy v1.7.2/go.mod h1:82vkLNir0ALaW14Rc399OTTjyNREgmdL2cVoIbS6XaE=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
Expand All @@ -62,8 +62,8 @@ github.com/go-git/go-billy/v5 v5.6.2 h1:6Q86EsPXMa7c3YZ3aLAQsMA0VlWmy43r6FHqa/UN
github.com/go-git/go-billy/v5 v5.6.2/go.mod h1:rcFC2rAsp/erv7CMz9GczHcuD0D32fWzH+MJAU+jaUU=
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4=
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII=
github.com/go-git/go-git/v5 v5.13.2 h1:7O7xvsK7K+rZPKW6AQR1YyNhfywkv7B8/FsP3ki6Zv0=
github.com/go-git/go-git/v5 v5.13.2/go.mod h1:hWdW5P4YZRjmpGHwRH2v3zkWcNl6HeXaXQEMGb3NJ9A=
github.com/go-git/go-git/v5 v5.14.0 h1:/MD3lCrGjCen5WfEAzKg00MJJffKhC8gzS80ycmCi60=
github.com/go-git/go-git/v5 v5.14.0/go.mod h1:Z5Xhoia5PcWA3NF8vRLURn9E5FRhSl7dGj9ItW3Wk5k=
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
Expand Down Expand Up @@ -91,8 +91,8 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand Down Expand Up @@ -211,8 +211,8 @@ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
Expand All @@ -225,10 +225,10 @@ github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/skeema/knownhosts v1.3.1 h1:X2osQ+RAjK76shCbvhHHHVl3ZlgDm8apHEHFqRjnBY8=
github.com/skeema/knownhosts v1.3.1/go.mod h1:r7KTdC8l4uxWRyK2TpQZ/1o5HaSzh06ePQNxPwTcfiY=
github.com/snyk/code-client-go v1.13.1 h1:JWQIrHOg/HYs0yqLmv1kNASwNhKXSYOcZsHU3QEugLk=
github.com/snyk/code-client-go v1.13.1/go.mod h1:jMRi+hf0T4472k390nGIM5/ZA7bufXlD72TBPmuWdVQ=
github.com/snyk/error-catalog-golang-public v0.0.0-20241030160523-0aa643bb7069 h1:Oj/BJAEMEuBjTAQ72UYB4tR0IZKOB2ZtdDnAnJDL1BM=
github.com/snyk/error-catalog-golang-public v0.0.0-20241030160523-0aa643bb7069/go.mod h1:Ytttq7Pw4vOCu9NtRQaOeDU2dhBYUyNBe6kX4+nIIQ4=
github.com/snyk/code-client-go v1.14.2-0.20250227153650-c248591556ec h1:cxgLu1IMIrrBmk70/5x1YgOogDefCWwFa6NPmAvSoxw=
github.com/snyk/code-client-go v1.14.2-0.20250227153650-c248591556ec/go.mod h1:oiPes18nZDXGw6G9XCr2fV2SzCyF6FU43975kyAqj5E=
github.com/snyk/error-catalog-golang-public v0.0.0-20250218074309-307ad7b38a60 h1:iB6z2BhBpfN9p0/dEZfwWvs7fpdZk3loooAih8yspS8=
github.com/snyk/error-catalog-golang-public v0.0.0-20250218074309-307ad7b38a60/go.mod h1:Ytttq7Pw4vOCu9NtRQaOeDU2dhBYUyNBe6kX4+nIIQ4=
github.com/snyk/go-httpauth v0.0.0-20231117135515-eb445fea7530 h1:s9PHNkL6ueYRiAKNfd8OVxlUOqU3qY0VDbgCD1f6WQY=
github.com/snyk/go-httpauth v0.0.0-20231117135515-eb445fea7530/go.mod h1:88KbbvGYlmLgee4OcQ19yr0bNpXpOr2kciOthaSzCAg=
github.com/speakeasy-api/openapi-overlay v0.9.0 h1:Wrz6NO02cNlLzx1fB093lBlYxSI54VRhy1aSutx0PQg=
Expand Down
4 changes: 2 additions & 2 deletions internal/presenters/__snapshots__/components_test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Status: 400 Bad Request

[Test_RenderError/with_links - 1]

[41m [0m[97;41mERROR[0m[41m [0m [1mRequest not fulfilled due to server error (SNYK-9999)[0m
[41m [0m[97;41mERROR[0m[41m [0m [1mUnable to process request (SNYK-9999)[0m
The server cannot process the request due to an unexpected error. Check Snyk
status, then try again.

Expand All @@ -99,7 +99,7 @@ Docs: https://docs.snyk.io/scan-with-snyk/error-catalog#snyk-9999

[Test_RenderError/with_context - 1]

[41m [0m[97;41mERROR[0m[41m [0m [1mRequest not fulfilled due to server error (SNYK-9999)[0m
[41m [0m[97;41mERROR[0m[41m [0m [1mUnable to process request (SNYK-9999)[0m
The server cannot process the request due to an unexpected error. Check Snyk
status, then try again.

Expand Down
9 changes: 8 additions & 1 deletion internal/presenters/templates/local_finding.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@
{{- end}}
{{- print " " $countFound " " $severity " " | toUpperCase | renderInSeverityColor }}
{{- end}}]{{- end}}
{{- end}} {{/* end summary */}}
{{- if .Links.report }}

{{ "Report" | bold }}
{{- "\n" }}
Your test results are available at:
{{ .Links.report | bold }}
{{- end }}
{{- end }} {{/* end summary */}}

{{- define "main" }}
{{- range $result := $.Results}}
Expand Down
31 changes: 0 additions & 31 deletions internal/utils/findings/findings.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,3 @@ func GetSeverityThresholdFilter(severityThreshold string, severityOrder []string
return utils.Contains(allowed_severities, string(finding.Attributes.Rating.Severity.Value))
}
}

func NewFindingsCounts() local_models.TypesFindingCounts {
return local_models.TypesFindingCounts{
CountBy: local_models.TypesFindingCounts_CountBy{Severity: map[string]uint32{}},
CountByAdjusted: local_models.TypesFindingCounts_CountByAdjusted{Severity: map[string]uint32{}},
CountBySuppressed: local_models.TypesFindingCounts_CountBySuppressed{Severity: map[string]uint32{}},
}
}

// updateFindingsSummary updates the summary of the findings based on their severity levels
func UpdateFindingSummary(findingsModel *local_models.LocalFinding) {
updatedFindingCounts := NewFindingsCounts()
updatedFindingCounts.CountKeyOrderAsc = findingsModel.Summary.Counts.CountKeyOrderAsc

// update FindingsCount with Findings data
for _, finding := range findingsModel.Findings {
severity := string(finding.Attributes.Rating.Severity.Value)
updatedFindingCounts.CountBy.Severity[severity]++
updatedFindingCounts.Count++

if finding.Attributes.Suppression != nil {
updatedFindingCounts.CountBySuppressed.Severity[severity]++
updatedFindingCounts.CountSuppressed++
} else {
updatedFindingCounts.CountByAdjusted.Severity[severity]++
updatedFindingCounts.CountAdjusted++
}
}

findingsModel.Summary.Counts = updatedFindingCounts
}
7 changes: 4 additions & 3 deletions pkg/configuration/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const (
UNKNOWN_ARGS string = "internal_unknown_arguments" // arguments unknown to the current application but maybe relevant for delegated application calls
IN_MEMORY_THRESHOLD_BYTES string = "internal_in_memory_threshold_bytes" // threshold to determine where to store workflow.Data
// feature flags
FF_OAUTH_AUTH_FLOW_ENABLED string = "internal_snyk_oauth_enabled"
FF_CODE_CONSISTENT_IGNORES string = "internal_snyk_code_ignores_enabled"
FF_TRANSFORMATION_WORKFLOW string = "internal_snyk_transformation_workflow_enabled"
FF_OAUTH_AUTH_FLOW_ENABLED string = "internal_snyk_oauth_enabled"
FF_CODE_CONSISTENT_IGNORES string = "internal_snyk_code_ignores_enabled"
FF_CODE_CONSISTENT_REPORT_ENABLED string = "internal_snyk_code_ignores_report_enabled"
FF_TRANSFORMATION_WORKFLOW string = "internal_snyk_transformation_workflow_enabled"
)
78 changes: 53 additions & 25 deletions pkg/local_workflows/code_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package localworkflows
import (
"fmt"

"github.com/rs/zerolog"
"github.com/snyk/error-catalog-golang-public/code"
"github.com/spf13/pflag"

"github.com/snyk/error-catalog-golang-public/code"
"github.com/snyk/go-application-framework/internal/api"
"github.com/snyk/go-application-framework/internal/utils"
"github.com/snyk/go-application-framework/pkg/configuration"
Expand All @@ -15,8 +16,7 @@ import (
)

const (
codeWorkflowName = "code.test"
ConfigurationSastEnabled = "internal_sast_enabled"
codeWorkflowName = "code.test"
)

func GetCodeFlagSet() *pflag.FlagSet {
Expand All @@ -25,16 +25,16 @@ func GetCodeFlagSet() *pflag.FlagSet {
// add flags here
flagSet.Bool("sarif", false, "Output in sarif format")
flagSet.Bool("json", false, "Output in json format")
flagSet.Bool("report", false, "Share results with the Snyk Web UI")
flagSet.Bool(code_workflow.ConfigurationReportFlag, false, "Share results with the Snyk Web UI")
flagSet.String(code_workflow.ConfigurationProjectName, "", "The name of the project to test.")
flagSet.String(code_workflow.ConfigurationRemoteRepoUrlFlagname, "", "The URL of the remote repository to test.")
flagSet.String("severity-threshold", "", "Minimum severity level to report (low|medium|high)")
flagSet.String("sarif-file-output", "", "Save test output in SARIF format directly to the <OUTPUT_FILE_PATH> file, regardless of whether or not you use the --sarif option.")
flagSet.String("json-file-output", "", "Save test output in JSON format directly to the <OUTPUT_FILE_PATH> file, regardless of whether or not you use the --json option.")
flagSet.String("project-name", "", "The name of the project to test.")
flagSet.String("project-id", "", "The unique identifier of the project to test.")
flagSet.String("commit-id", "", "The unique identifier of the commit to test.")
flagSet.String("target-name", "", "The name of the target to test.")
flagSet.String(code_workflow.ConfigurationTargetName, "", "The name of the target to test.")
flagSet.String("target-file", "", "The path to the target file to test.")
flagSet.String(code_workflow.RemoteRepoUrlFlagname, "", "The URL of the remote repository to test.")
flagSet.Bool(configuration.FLAG_EXPERIMENTAL, false, "Enable experimental code test command")

return flagSet
Expand Down Expand Up @@ -64,6 +64,46 @@ func getSastEnabled(engine workflow.Engine) configuration.DefaultValueFunction {
return callback
}

func getSlceEnabled(engine workflow.Engine) configuration.DefaultValueFunction {
callback := func(existingValue interface{}) (interface{}, error) {
if existingValue != nil {
return existingValue, nil
}

client := engine.GetNetworkAccess().GetHttpClient()
url := engine.GetConfiguration().GetString(configuration.API_URL)
org := engine.GetConfiguration().GetString(configuration.ORGANIZATION)
apiClient := api.NewApi(url, client)
response, err := apiClient.GetSastSettings(org)
if err != nil {
engine.GetLogger().Err(err).Msg("Failed to access settings.")
return false, err
}

return response.LocalCodeEngine.Enabled, nil
}
return callback
}

func useNativeImplementation(config configuration.Configuration, logger *zerolog.Logger, sastEnabled bool) bool {
useConsistentIgnoresFF := config.GetBool(configuration.FF_CODE_CONSISTENT_IGNORES)
useNativeReportFF := config.GetBool(configuration.FF_CODE_CONSISTENT_REPORT_ENABLED)
reportEnabled := config.GetBool(code_workflow.ConfigurationReportFlag)
scleEnabled := config.GetBool(code_workflow.ConfigurarionSlceEnabled)

useLegacyReport := reportEnabled && !useNativeReportFF
nativeImplementationEnabled := useConsistentIgnoresFF && !useLegacyReport && !scleEnabled

logger.Debug().Msgf("SAST Enabled: %v", sastEnabled)
logger.Debug().Msgf("Report enabled: %v", reportEnabled)
logger.Debug().Msgf("SLCE enabled: %v", scleEnabled)
logger.Debug().Msgf("Consistent Ignores:")
logger.Debug().Msgf(" FF ignores: %v", useConsistentIgnoresFF)
logger.Debug().Msgf(" FF report: %v", useNativeReportFF)

return nativeImplementationEnabled
}

// InitCodeWorkflow initializes the code workflow before registering it with the engine.
func InitCodeWorkflow(engine workflow.Engine) error {
// register workflow with engine
Expand All @@ -74,9 +114,11 @@ func InitCodeWorkflow(engine workflow.Engine) error {
return err
}

engine.GetConfiguration().AddDefaultValue(ConfigurationSastEnabled, getSastEnabled(engine))
engine.GetConfiguration().AddDefaultValue(code_workflow.ConfigurationSastEnabled, getSastEnabled(engine))
engine.GetConfiguration().AddDefaultValue(code_workflow.ConfigurarionSlceEnabled, getSlceEnabled(engine))
engine.GetConfiguration().AddDefaultValue(code_workflow.ConfigurationTestFLowName, configuration.StandardDefaultValueFunction("cli_test"))
config_utils.AddFeatureFlagToConfig(engine, configuration.FF_CODE_CONSISTENT_IGNORES, "snykCodeConsistentIgnores")
config_utils.AddFeatureFlagToConfig(engine, configuration.FF_CODE_CONSISTENT_REPORT_ENABLED, code_workflow.FfNameNativeReport)

return err
}
Expand All @@ -88,34 +130,20 @@ func codeWorkflowEntryPoint(invocationCtx workflow.InvocationContext, _ []workfl
config := invocationCtx.GetConfiguration()
logger := invocationCtx.GetEnhancedLogger()

sastEnabledI, err := config.GetWithError(ConfigurationSastEnabled)
sastEnabledI, err := config.GetWithError(code_workflow.ConfigurationSastEnabled)
if err != nil {
return result, err
}

sastEnabled := utils.ToBool(sastEnabledI)

ignoresFeatureFlag := config.GetBool(configuration.FF_CODE_CONSISTENT_IGNORES)
reportEnabled := config.GetBool("report")

logger.Debug().Msgf("SAST Enabled: %v", sastEnabled)
logger.Debug().Msgf("Consistent Ignores: %v", ignoresFeatureFlag)
logger.Debug().Msgf("Report enabled: %v", reportEnabled)
nativeImplementation := useNativeImplementation(config, logger, sastEnabled)

if !sastEnabled {
return result, code.NewFeatureIsNotEnabledError(fmt.Sprintf("Snyk Code is not supported for your current organization: `%s`.", config.GetString(configuration.ORGANIZATION_SLUG)))
}

if ignoresFeatureFlag && !reportEnabled {
if nativeImplementation {
logger.Debug().Msg("Implementation: Native")

unsupportedParameter := []string{"project-name", "project-id", "commit-id", "target-name", "target-file"}
for _, v := range unsupportedParameter {
if config.IsSet(v) {
logger.Warn().Msgf("The parameter \"%s\" is not yet supported in this experimental implementation!", v)
}
}

result, err = code_workflow.EntryPointNative(invocationCtx)
} else {
logger.Debug().Msg("Implementation: legacy")
Expand Down
22 changes: 22 additions & 0 deletions pkg/local_workflows/code_workflow/code_client_helper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package code_workflow

import (
"errors"
"strings"
"time"

Expand Down Expand Up @@ -36,3 +37,24 @@ func (c *codeClientConfig) SnykCodeAnalysisTimeout() time.Duration {
timeoutInSeconds := c.localConfiguration.GetInt(configuration.TIMEOUT)
return time.Duration(timeoutInSeconds) * time.Second
}

func GetReportMode(config configuration.Configuration) (reportType, error) {
reportEnabled := config.GetBool(ConfigurationReportFlag)
if !reportEnabled {
return noReport, nil
}

if len(config.GetString(ConfigurationProjectId)) > 0 && len(config.GetString(ConfigurationCommitId)) == 0 {
return noReport, errors.New("\"commit-id\" must be provided for \"report\"")
}

if len(config.GetString(ConfigurationProjectId)) > 0 {
return remoteCode, nil
}

if len(config.GetString(ConfigurationProjectName)) == 0 {
return noReport, errors.New("\"project-name\" must be provided for \"report\"")
}

return localCode, nil
}
Loading

0 comments on commit 396b2b7

Please sign in to comment.