11package main
22
33// !!! This import needs to be the first import, please do not change this !!!
4- import _ "github.com/snyk/go-application-framework/pkg/networking/fips_enable"
5-
64import (
75 "context"
86 "encoding/json"
@@ -25,19 +23,20 @@ import (
2523 "github.com/snyk/cli-extension-mcp-scan/pkg/mcpscan"
2624 "github.com/snyk/cli-extension-os-flows/pkg/osflows"
2725 "github.com/snyk/cli-extension-sbom/pkg/sbom"
28- "github.com/snyk/container-cli/pkg/container"
29- "github.com/snyk/error-catalog-golang-public/cli"
30- "github.com/spf13/cobra"
31- "github.com/spf13/pflag"
32-
3326 "github.com/snyk/cli/cliv2/cmd/cliv2/behavior/legacy"
3427 "github.com/snyk/cli/cliv2/internal/cliv2"
3528 "github.com/snyk/cli/cliv2/internal/constants"
29+ featureflaggateway "github.com/snyk/cli/cliv2/internal/feature-flag-gateway"
30+ "github.com/snyk/container-cli/pkg/container"
31+ "github.com/snyk/error-catalog-golang-public/cli"
3632 "github.com/snyk/go-application-framework/pkg/analytics"
3733 "github.com/snyk/go-application-framework/pkg/app"
3834 "github.com/snyk/go-application-framework/pkg/configuration"
3935 "github.com/snyk/go-application-framework/pkg/instrumentation"
4036 "github.com/snyk/go-application-framework/pkg/logging"
37+ _ "github.com/snyk/go-application-framework/pkg/networking/fips_enable"
38+ "github.com/spf13/cobra"
39+ "github.com/spf13/pflag"
4140
4241 cliv2utils "github.com/snyk/cli/cliv2/internal/utils"
4342
@@ -46,7 +45,6 @@ import (
4645 "github.com/snyk/go-application-framework/pkg/local_workflows/network_utils"
4746
4847 workflows "github.com/snyk/go-application-framework/pkg/local_workflows/connectivity_check_extension"
49-
5048 "github.com/snyk/go-httpauth/pkg/httpauth"
5149 "github.com/snyk/snyk-iac-capture/pkg/capture"
5250
@@ -59,7 +57,6 @@ import (
5957 "github.com/snyk/go-application-framework/pkg/workflow"
6058
6159 snykls "github.com/snyk/snyk-ls/ls_extension"
62-
6360 "github.com/snyk/studio-mcp/pkg/mcp"
6461
6562 cli_errors "github.com/snyk/cli/cliv2/internal/errors"
@@ -77,10 +74,11 @@ var scrubbedLogger logging.ScrubbingLogWriter
7774var interactionId = instrumentation .AssembleUrnFromUUID (uuid .NewString ())
7875
7976const (
80- unknownCommandMessage string = "unknown command"
81- disable_analytics_flag string = "DISABLE_ANALYTICS"
82- debug_level_flag string = "log-level"
83- integrationNameFlag string = "integration-name"
77+ unknownCommandMessage string = "unknown command"
78+ disable_analytics_flag string = "DISABLE_ANALYTICS"
79+ debug_level_flag string = "log-level"
80+ integrationNameFlag string = "integration-name"
81+ showMavenBuildScopeFlag string = "show-maven-build-scope"
8482)
8583
8684type JsonErrorStruct struct {
@@ -591,6 +589,14 @@ func MainWithErrorCode() int {
591589 // add workflows as commands
592590 createCommandsForWorkflows (rootCommand , globalEngine )
593591
592+ // fetch feature flags
593+ ffgService , err := featureflaggateway .NewService (globalConfiguration .GetUrl (configuration .API_URL ), 10 * time .Second )
594+ if err != nil {
595+ globalLogger .Print ("Failed to fetch feature flags" , err )
596+ return constants .SNYK_EXIT_CODE_ERROR
597+ }
598+ apiToken := globalConfiguration .GetString (configuration .AUTHENTICATION_TOKEN )
599+
594600 // init Analytics
595601 cliAnalytics := globalEngine .GetAnalytics ()
596602 cliAnalytics .SetVersion (cliv2 .GetFullVersion ())
@@ -601,6 +607,8 @@ func MainWithErrorCode() int {
601607 cliAnalytics .GetInstrumentation ().SetCategory (instrumentation .DetermineCategory (os .Args , globalEngine ))
602608 cliAnalytics .GetInstrumentation ().SetStage (instrumentation .DetermineStage (cliAnalytics .IsCiEnvironment ()))
603609 cliAnalytics .GetInstrumentation ().SetStatus (analytics .Success )
610+ cliAnalytics .GetInstrumentation ().AddExtension (showMavenBuildScopeFlag ,
611+ IsFeatureEnabled (ctx , ffgService , globalConfiguration .GetString (configuration .ORGANIZATION ), showMavenBuildScopeFlag , apiToken ))
604612
605613 setTimeout (globalConfiguration , func () {
606614 os .Exit (constants .SNYK_EXIT_CODE_EX_UNAVAILABLE )
@@ -659,6 +667,26 @@ func MainWithErrorCode() int {
659667 return exitCode
660668}
661669
670+ func IsFeatureEnabled (
671+ ctx context.Context ,
672+ service featureflaggateway.Service ,
673+ orgID string ,
674+ flag string ,
675+ token string ,
676+ ) bool {
677+ resp , err := service .EvaluateFlags (ctx , []string {flag }, orgID , "2024-10-15" , token )
678+ if err != nil || resp == nil {
679+ return false
680+ }
681+ evals := resp .Data .Attributes .Evaluations
682+ for _ , e := range evals {
683+ if e .Key == flag {
684+ return e .Value
685+ }
686+ }
687+ return false
688+ }
689+
662690func legacyCLITerminated (err error , errorList []error ) error {
663691 exitErr , isExitError := err .(* exec.ExitError )
664692 if isExitError && exitErr .ExitCode () == constants .SNYK_EXIT_CODE_TS_CLI_TERMINATED {
0 commit comments