Skip to content
Draft
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: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ engine.Invoke(code.WORKFLOWID_CODE)

The `codeWorkflowEntryPoint` function:
- Checks if SAST is enabled for the organization
- Determines whether to use the native or legacy implementation based on feature flags
- Routes to either `EntryPointNative` (for Code Consistent Ignores support) or `EntryPointLegacy`
- Routes to the native `EntryPointNative` implementation
- Returns workflow data containing scan results as local findings

### Library Functions
Expand Down Expand Up @@ -149,4 +148,4 @@ All of our development will remain public for transparency. We thank the communi

GitHub issues have been disabled on this repository as part of our move to a closed-contribution model. The Snyk support team does not actively monitor GitHub issues on any Snyk development project.

For help with the Snyk CLI or Snyk in general, please use the [Snyk support page](https://support.snyk.io/), which is the fastest way to get assistance.
For help with the Snyk CLI or Snyk in general, please use the [Snyk support page](https://support.snyk.io/), which is the fastest way to get assistance.
21 changes: 0 additions & 21 deletions internal/commands/code_workflow/legacy_workflow.go

This file was deleted.

59 changes: 11 additions & 48 deletions pkg/code/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,23 @@ 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.
Expand Down Expand Up @@ -166,26 +162,6 @@ func getSlceEnabled(engine workflow.Engine) configuration.DefaultValueFunction {
return callback
}

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

// 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
Expand All @@ -200,14 +176,12 @@ 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)

return err
}

// 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()
Expand All @@ -218,26 +192,15 @@ func codeWorkflowEntryPoint(invocationCtx workflow.InvocationContext, _ []workfl
return result, err
}

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)))
}

implementationName := "legacy"
if nativeImplementation {
implementationName = "native"
}

invocationCtx.GetAnalytics().AddExtensionStringValue("implementation", implementationName)
logger.Debug().Msgf("Implementation: %s", implementationName)
invocationCtx.GetAnalytics().AddExtensionStringValue("implementation", "native")
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)

Expand Down
Loading
Loading