-
Notifications
You must be signed in to change notification settings - Fork 3
refactor: always use native Snyk Code workflow #160
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,27 +9,24 @@ import ( | |
| "slices" | ||
|
|
||
| "github.com/rs/zerolog" | ||
| "github.com/snyk/error-catalog-golang-public/code" | ||
| "github.com/spf13/pflag" | ||
|
|
||
| "github.com/snyk/code-client-go/internal/commands/code_workflow" | ||
| "github.com/snyk/code-client-go/pkg/code/sast_contract" | ||
| "github.com/snyk/error-catalog-golang-public/code" | ||
| "github.com/snyk/go-application-framework/pkg/configuration" | ||
| "github.com/snyk/go-application-framework/pkg/local_workflows/config_utils" | ||
| errorutils "github.com/snyk/go-application-framework/pkg/local_workflows/error_utils" | ||
| "github.com/snyk/go-application-framework/pkg/workflow" | ||
|
|
||
| "github.com/snyk/code-client-go/pkg/code/sast_contract" | ||
| "github.com/spf13/pflag" | ||
| ) | ||
|
|
||
| const ( | ||
| codeWorkflowName = "code.test" | ||
| ) | ||
|
|
||
| const ( | ||
| ConfigurationSastEnabled = "internal_sast_enabled" | ||
| ConfigurationSastSettings = code_workflow.ConfigurationSastSettings | ||
| ConfigurationSlceEnabled = code_workflow.ConfigurationSlceEnabled | ||
| FfNameNativeImplementation = "snykCodeClientNativeImplementation" | ||
| ConfigurationSastEnabled = "internal_sast_enabled" | ||
| ConfigurationSastSettings = code_workflow.ConfigurationSastSettings | ||
| ConfigurationSlceEnabled = code_workflow.ConfigurationSlceEnabled | ||
| ) | ||
|
|
||
| // ConfigurarionSlceEnabled is kept for backward compatibility. | ||
|
|
@@ -166,25 +163,6 @@ func getSlceEnabled(engine workflow.Engine) configuration.DefaultValueFunction { | |
| return callback | ||
| } | ||
|
|
||
| func useNativeImplementation(config configuration.Configuration, logger *zerolog.Logger, sastEnabled bool, scleEnabled bool) bool { | ||
| useConsistentIgnoresFF := config.GetBool(configuration.FF_CODE_CONSISTENT_IGNORES) | ||
| useNativeImplementationFF := config.GetBool(configuration.FF_CODE_NATIVE_IMPLEMENTATION) | ||
|
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. Can we remove the evaluation here? |
||
| reportEnabled := config.GetBool(code_workflow.ConfigurationReportFlag) | ||
|
|
||
| // SCLE no longer forces the legacy path: code-client-go honors the local | ||
| // engine URL from SAST settings (see codeClientConfig.SnykCodeApi), so the | ||
| // native implementation supports SCLE flows directly. | ||
| nativeImplementationEnabled := useConsistentIgnoresFF || useNativeImplementationFF | ||
|
|
||
| logger.Debug().Msgf("SAST Enabled: %v", sastEnabled) | ||
| logger.Debug().Msgf("Report enabled: %v", reportEnabled) | ||
| logger.Debug().Msgf("SLCE enabled: %v", scleEnabled) | ||
| logger.Debug().Msgf("FF consistent ignores: %v", useConsistentIgnoresFF) | ||
| logger.Debug().Msgf("FF native implementation: %v", useNativeImplementationFF) | ||
|
|
||
| return nativeImplementationEnabled | ||
| } | ||
|
|
||
| // Init initializes the code workflow before registering it with the engine. | ||
| func Init(engine workflow.Engine) error { | ||
| // register workflow with engine | ||
|
|
@@ -199,8 +177,6 @@ func Init(engine workflow.Engine) error { | |
| engine.GetConfiguration().AddDefaultValue(ConfigurationSastEnabled, getSastEnabled(engine)) | ||
| engine.GetConfiguration().AddDefaultValue(ConfigurationSlceEnabled, 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_NATIVE_IMPLEMENTATION, FfNameNativeImplementation) | ||
| config_utils.AddFeatureFlagsToConfig(engine, map[string]string{ | ||
| code_workflow.ConfigurationUploadToFileUploadApi: "code-cli-upload-file-content-to-fua", | ||
| }) | ||
|
|
@@ -209,7 +185,7 @@ func Init(engine workflow.Engine) error { | |
| } | ||
|
|
||
| // codeWorkflowEntryPoint is the entry point for the code workflow. | ||
| // it provides a wrapper for the legacycli workflow | ||
| // It always runs the native code-client-go workflow. | ||
| func codeWorkflowEntryPoint(invocationCtx workflow.InvocationContext, _ []workflow.Data) (result []workflow.Data, err error) { | ||
| // get necessary objects from invocation context | ||
| config := invocationCtx.GetConfiguration() | ||
|
|
@@ -221,28 +197,17 @@ func codeWorkflowEntryPoint(invocationCtx workflow.InvocationContext, _ []workfl | |
| } | ||
|
|
||
| scleEnabled := config.GetBool(ConfigurationSlceEnabled) | ||
| nativeImplementation := useNativeImplementation(config, logger, sastEnabled, scleEnabled) | ||
|
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. Any chance that both flags would be set to |
||
|
|
||
| if !sastEnabled { | ||
| return result, code.NewFeatureIsNotEnabledError(fmt.Sprintf("Snyk Code is not supported for your current organization: `%s`.", config.GetString(configuration.ORGANIZATION_SLUG))) | ||
| } | ||
|
|
||
| implementationName := "legacy" | ||
| if nativeImplementation { | ||
| implementationName = "native" | ||
| } | ||
|
|
||
| analyticsClient := invocationCtx.GetAnalytics() | ||
| analyticsClient.AddExtensionStringValue("implementation", implementationName) | ||
| analyticsClient.AddExtensionStringValue("implementation", "native") | ||
| analyticsClient.AddExtensionBoolValue("isSCLE", scleEnabled) | ||
| logger.Debug().Msgf("Implementation: %s", implementationName) | ||
| logger.Debug().Msg("Implementation: native") | ||
|
|
||
| if nativeImplementation { | ||
| registerLocalEngineAuthURL(config, logger) | ||
| result, err = code_workflow.EntryPointNative(invocationCtx) | ||
| } else { | ||
| result, err = code_workflow.EntryPointLegacy(invocationCtx) | ||
| } | ||
| registerLocalEngineAuthURL(config, logger) | ||
| result, err = code_workflow.EntryPointNative(invocationCtx) | ||
|
|
||
| err = errorutils.DecorateTestError(err, config) | ||
|
|
||
|
|
||
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.
This is still an org/group level feature flag.
https://github.com/snyk/registry/blob/4b930c34f61661b32e27d9d2ceb086a71337b58d/src/lib/domain/internal-developer-tooling/features/index.ts#L1249-L1251
Despite it is set to ' true ' by default, customers can still disable it in the org/group settings page.
Can we remove the evaluation here?