From 97fb41e67bc6d7f2c3c064e4471dda9b27afd0b7 Mon Sep 17 00:00:00 2001 From: Sandor Trombitas Date: Thu, 7 Nov 2024 10:56:58 +0200 Subject: [PATCH] chore: disable analytics in go --- cliv2/cmd/cliv2/main.go | 38 ++++---------------------------------- 1 file changed, 4 insertions(+), 34 deletions(-) diff --git a/cliv2/cmd/cliv2/main.go b/cliv2/cmd/cliv2/main.go index b54a68a1e1..baa9d09077 100644 --- a/cliv2/cmd/cliv2/main.go +++ b/cliv2/cmd/cliv2/main.go @@ -1,8 +1,6 @@ package main // !!! This import needs to be the first import, please do not change this !!! -import _ "github.com/snyk/go-application-framework/pkg/networking/fips_enable" - import ( "context" "encoding/json" @@ -19,19 +17,18 @@ import ( "github.com/snyk/cli-extension-dep-graph/pkg/depgraph" "github.com/snyk/cli-extension-iac-rules/iacrules" "github.com/snyk/cli-extension-sbom/pkg/sbom" + "github.com/snyk/cli/cliv2/internal/cliv2" + "github.com/snyk/cli/cliv2/internal/constants" "github.com/snyk/container-cli/pkg/container" "github.com/snyk/go-application-framework/pkg/analytics" "github.com/snyk/go-application-framework/pkg/app" "github.com/snyk/go-application-framework/pkg/configuration" "github.com/snyk/go-application-framework/pkg/instrumentation" + "github.com/snyk/go-application-framework/pkg/local_workflows/network_utils" + _ "github.com/snyk/go-application-framework/pkg/networking/fips_enable" "github.com/spf13/cobra" "github.com/spf13/pflag" - "github.com/snyk/cli/cliv2/internal/cliv2" - "github.com/snyk/cli/cliv2/internal/constants" - - "github.com/snyk/go-application-framework/pkg/local_workflows/network_utils" - localworkflows "github.com/snyk/go-application-framework/pkg/local_workflows" "github.com/snyk/go-application-framework/pkg/local_workflows/content_type" "github.com/snyk/go-application-framework/pkg/local_workflows/json_schemas" @@ -227,29 +224,6 @@ func getErrorFromWorkFlowData(engine workflow.Engine, data []workflow.Data) erro return nil } -func sendAnalytics(analytics analytics.Analytics, debugLogger *zerolog.Logger) { - debugLogger.Print("Sending Analytics") - - res, err := analytics.Send() - if err != nil { - debugLogger.Err(err).Msg("Failed to send Analytics") - return - } - defer res.Body.Close() - - successfullySend := 200 <= res.StatusCode && res.StatusCode < 300 - if successfullySend { - debugLogger.Print("Analytics successfully send") - } else { - var details string - if res != nil { - details = res.Status - } - - debugLogger.Print("Failed to send Analytics:", details) - } -} - func sendInstrumentation(eng workflow.Engine, instrumentor analytics.InstrumentationCollector, logger *zerolog.Logger) { // Avoid duplicate data to be sent for IDE integrations that use the CLI if !shallSendInstrumentation(eng.GetConfiguration(), instrumentor) { @@ -577,10 +551,6 @@ func MainWithErrorCode() int { if exitCode == 2 { cliAnalytics.GetInstrumentation().SetStatus(analytics.Failure) } - - if !globalConfiguration.GetBool(configuration.ANALYTICS_DISABLED) { - sendAnalytics(cliAnalytics, globalLogger) - } sendInstrumentation(globalEngine, cliAnalytics.GetInstrumentation(), globalLogger) // cleanup resources in use