Skip to content

Commit

Permalink
chore: apply refactoring and adapt category vector
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterSchafer committed May 21, 2024
1 parent c9b610a commit d98df22
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
35 changes: 17 additions & 18 deletions cliv2/cmd/cliv2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/snyk/snyk-iac-capture/pkg/capture"
snykls "github.com/snyk/snyk-ls/ls_extension"

"github.com/snyk/go-application-framework/pkg/instrumentation"
"github.com/snyk/go-application-framework/pkg/ui"

"github.com/snyk/cli/cliv2/internal/cliv2"
Expand Down Expand Up @@ -241,22 +242,16 @@ func sendAnalytics(analytics analytics.Analytics, debugLogger *zerolog.Logger) {
}
}

// TODO: delete once CLI-303 implemented
//func sendInstrumentation(a analytics.Analytics) {
// api := globalConfiguration.GetString(configuration.API_URL)
// org := globalConfiguration.GetString(configuration.ORGANIZATION)
// data := analytics.GetV2InstrumentationObject(a.GetInstrumentation())
// v2InstrumentationData := utils.ValueOf(json.Marshal(data))
// request, err := v20240307.NewCreateAnalyticsRequest(api+"/hidden/", utils.ValueOf(uuid.Parse(org)), &v20240307.CreateAnalyticsParams{Version: "2024-03-07~experimental"}, *data)
// globalLogger.Printf("%v", request)
// globalLogger.Printf("%v", err)
//
// response, err := globalEngine.GetNetworkAccess().GetHttpClient().Do(request)
// defer response.Body.Close()
// globalLogger.Printf("%v", response)
//
// globalLogger.Println(string(v2InstrumentationData))
//}
func sendInstrumentation(a analytics.Analytics, logger *zerolog.Logger) {
// TODO: actually send data once CLI-303 is implemented
data, err := analytics.GetV2InstrumentationObject(a.GetInstrumentation())
if err != nil {
logger.Err(err).Msg("Failed to derive data object.")
}

v2InstrumentationData := utils.ValueOf(json.Marshal(data))
logger.Printf("%v", string(v2InstrumentationData))
}

func help(_ *cobra.Command, _ []string) error {
helpProvided = true
Expand Down Expand Up @@ -488,17 +483,21 @@ func MainWithErrorCode() int {
}

// init Analytics
knownCommands, knownFlags := instrumentation.GetKnownCommandsAndFlags(globalEngine)
cliAnalytics := globalEngine.GetAnalytics()
cliAnalytics.SetVersion(cliv2.GetFullVersion())
cliAnalytics.SetCmdArguments(os.Args)
cliAnalytics.SetOperatingSystem(internalOS)
cliAnalytics.GetInstrumentation().SetUserAgent(ua)
cliAnalytics.GetInstrumentation().SetInteractionId(analytics.AssembleUrnFromUUID(requestId))
cliAnalytics.GetInstrumentation().SetInteractionId(instrumentation.AssembleUrnFromUUID(requestId))
cliAnalytics.GetInstrumentation().SetCategory(instrumentation.DetermineCategoryFromArgs(os.Args, knownCommands, knownFlags))
cliAnalytics.GetInstrumentation().SetStage(instrumentation.DetermineStage(cliAnalytics.IsCiEnvironment()))

cliAnalytics.GetInstrumentation().SetTargetId("pkg:") // TODO use method when existing
if !globalConfiguration.GetBool(configuration.ANALYTICS_DISABLED) {
defer sendAnalytics(cliAnalytics, globalLogger)
}
//defer sendInstrumentation(cliAnalytics)
defer sendInstrumentation(cliAnalytics, globalLogger)

setTimeout(globalConfiguration, func() {
os.Exit(constants.SNYK_EXIT_CODE_EX_UNAVAILABLE)
Expand Down
2 changes: 1 addition & 1 deletion cliv2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/snyk/cli-extension-iac-rules v0.0.0-20240422133948-ae17a4306672
github.com/snyk/cli-extension-sbom v0.0.0-20240426130148-b83c2ebc75c4
github.com/snyk/container-cli v0.0.0-20240322120441-6d9b9482f9b1
github.com/snyk/go-application-framework v0.0.0-20240521112505-661cc24c0edb
github.com/snyk/go-application-framework v0.0.0-20240521161436-03b01ff08065
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65
github.com/snyk/snyk-iac-capture v0.6.5
github.com/snyk/snyk-ls v0.0.0-20240510163626-041f744c3180
Expand Down
4 changes: 2 additions & 2 deletions cliv2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,8 @@ github.com/snyk/container-cli v0.0.0-20240322120441-6d9b9482f9b1 h1:9RKY9NdX5DrJ
github.com/snyk/container-cli v0.0.0-20240322120441-6d9b9482f9b1/go.mod h1:38w+dcAQp9eG3P5t2eNS9eG0reut10AeJjLv5lJ5lpM=
github.com/snyk/error-catalog-golang-public v0.0.0-20240425141803-2516e42296c3 h1:ZUaY5LIVGQ0GScf1SsaqvUxaiGbBKgBBLsQUgB4Zx5o=
github.com/snyk/error-catalog-golang-public v0.0.0-20240425141803-2516e42296c3/go.mod h1:Ytttq7Pw4vOCu9NtRQaOeDU2dhBYUyNBe6kX4+nIIQ4=
github.com/snyk/go-application-framework v0.0.0-20240521112505-661cc24c0edb h1:2jdNv1NKyfB9zrhG9VlJkHQ6ttgFpbt0gF80sS/WS1A=
github.com/snyk/go-application-framework v0.0.0-20240521112505-661cc24c0edb/go.mod h1:5gvF6i1sqmk1oN21ZbX/EDaEyQtPMfK1pbYCwtS+Fvw=
github.com/snyk/go-application-framework v0.0.0-20240521161436-03b01ff08065 h1:uwOtMcz4VlBoyRV43LcIm3ZNVkHYIpnAGmll6KN+13w=
github.com/snyk/go-application-framework v0.0.0-20240521161436-03b01ff08065/go.mod h1:5gvF6i1sqmk1oN21ZbX/EDaEyQtPMfK1pbYCwtS+Fvw=
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65 h1:CEQuYv0Go6MEyRCD3YjLYM2u3Oxkx8GpCpFBd4rUTUk=
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65/go.mod h1:88KbbvGYlmLgee4OcQ19yr0bNpXpOr2kciOthaSzCAg=
github.com/snyk/policy-engine v0.30.11 h1:wUy5LMar2vccMbNM62MSBRdjAQAhAbIm7aNXXO+g2tk=
Expand Down

0 comments on commit d98df22

Please sign in to comment.