Skip to content

Commit

Permalink
feat: use global runtime information [LINK-881] (#4936)
Browse files Browse the repository at this point in the history
* feat: use global runtime information

* chore: add acceptance test

* chore: upgrade GAF

* fix: linter

* fix: run formatter
  • Loading branch information
PeterSchafer committed Nov 20, 2023
1 parent a6383c0 commit 088a3a8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
9 changes: 6 additions & 3 deletions cliv2/cmd/cliv2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"

"github.com/snyk/go-application-framework/pkg/runtimeinfo"

"github.com/snyk/cli/cliv2/internal/cliv2"
"github.com/snyk/cli/cliv2/internal/constants"
"github.com/snyk/cli/cliv2/pkg/basic_workflows"
Expand Down Expand Up @@ -79,7 +81,7 @@ const (

func getDebugLevel(config configuration.Configuration) zerolog.Level {
loglevel := zerolog.DebugLevel
if loglevelString := config.GetString("snyk_loglevel"); loglevelString != "" {
if loglevelString := config.GetString("snyk_log_level"); loglevelString != "" {
var err error
loglevel, err = zerolog.ParseLevel(loglevelString)
if err == nil {
Expand Down Expand Up @@ -371,6 +373,7 @@ func displayError(err error) {

func MainWithErrorCode() int {
var err error
rInfo := runtimeinfo.New(runtimeinfo.WithName("snyk-cli"), runtimeinfo.WithVersion(cliv2.GetFullVersion()))

rootCommand := prepareRootCommand()
_ = rootCommand.ParseFlags(os.Args)
Expand All @@ -386,7 +389,7 @@ func MainWithErrorCode() int {
debugLogger := initDebugLogger(globalConfiguration)

initApplicationConfiguration(globalConfiguration)
engine = app.CreateAppEngineWithOptions(app.WithZeroLogger(debugLogger), app.WithConfiguration(globalConfiguration))
engine = app.CreateAppEngineWithOptions(app.WithZeroLogger(debugLogger), app.WithConfiguration(globalConfiguration), app.WithRuntimeInfo(rInfo))

if noProxyAuth := globalConfiguration.GetBool(basic_workflows.PROXY_NOAUTH); noProxyAuth {
globalConfiguration.Set(configuration.PROXY_AUTHENTICATION_MECHANISM, httpauth.StringFromAuthenticationMechanism(httpauth.NoAuth))
Expand Down Expand Up @@ -423,7 +426,7 @@ func MainWithErrorCode() int {
"User-Agent",
networking.UserAgent(
networking.UaWithConfig(globalConfiguration),
networking.UaWithApplication("snyk-cli", cliv2.GetFullVersion()),
networking.UaWithRuntimeInfo(rInfo),
networking.UaWithOS(internalOS)).String(),
)

Expand Down
2 changes: 1 addition & 1 deletion cliv2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/snyk/cli-extension-iac-rules v0.0.0-20230601153200-c572cfce46ce
github.com/snyk/cli-extension-sbom v0.0.0-20230926124903-9705d7d47d8f
github.com/snyk/container-cli v0.0.0-20230920093251-fe865879a91f
github.com/snyk/go-application-framework v0.0.0-20231113083350-f8b61e9b23e5
github.com/snyk/go-application-framework v0.0.0-20231117124326-6dff117c23a7
github.com/snyk/go-httpauth v0.0.0-20230925093100-dfb05155efc1
github.com/snyk/snyk-iac-capture v0.6.5
github.com/snyk/snyk-ls v0.0.0-20231110143802-54d54e374783
Expand Down
4 changes: 2 additions & 2 deletions cliv2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,8 @@ github.com/snyk/cli-extension-sbom v0.0.0-20230926124903-9705d7d47d8f h1:U3DQ9wn
github.com/snyk/cli-extension-sbom v0.0.0-20230926124903-9705d7d47d8f/go.mod h1:O/cjwCbKhJQWyXHPmNbZ7ToQKnhyw0VUp1Qhim3WEcw=
github.com/snyk/container-cli v0.0.0-20230920093251-fe865879a91f h1:ghajT5PEiLP8XNFIdc7Yn4Th74RH/9Q++dDOp6Cb9eo=
github.com/snyk/container-cli v0.0.0-20230920093251-fe865879a91f/go.mod h1:38w+dcAQp9eG3P5t2eNS9eG0reut10AeJjLv5lJ5lpM=
github.com/snyk/go-application-framework v0.0.0-20231113083350-f8b61e9b23e5 h1:Po8dmmQKc6G0Fwx2hU9OOTf9AaV9wKvDcENee1WUrgU=
github.com/snyk/go-application-framework v0.0.0-20231113083350-f8b61e9b23e5/go.mod h1:YGuE2uaW3PG7Q3CcVpCdu/tOFhv5eUjcTNlYIcw6FDo=
github.com/snyk/go-application-framework v0.0.0-20231117124326-6dff117c23a7 h1:6PQ+kR6tHAnw0b3yNi1YjYh3TCQoxZr8RezEsC8daAQ=
github.com/snyk/go-application-framework v0.0.0-20231117124326-6dff117c23a7/go.mod h1:YGuE2uaW3PG7Q3CcVpCdu/tOFhv5eUjcTNlYIcw6FDo=
github.com/snyk/go-httpauth v0.0.0-20230925093100-dfb05155efc1 h1:2HfjHQxOjWyD5jKJQtiZV9mptamqikAvE/H4gilFk30=
github.com/snyk/go-httpauth v0.0.0-20230925093100-dfb05155efc1/go.mod h1:88KbbvGYlmLgee4OcQ19yr0bNpXpOr2kciOthaSzCAg=
github.com/snyk/policy-engine v0.22.0 h1:od9pduGrXyfWO791X+8M1qmnvWUxaIXh0gBzGKqeseA=
Expand Down
12 changes: 11 additions & 1 deletion test/jest/acceptance/https.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,18 @@ describe('https', () => {
cwd: project.path(),
env,
});
expect(server.getRequests().length).toBeGreaterThan(0);
expect(server.getRequests().length).toBeGreaterThan(1);
expect(code).toBe(0);

// get rid of the first entry which has another User Agent
server
.getRequests()
.reverse()
.pop();

for (const r of server.getRequests()) {
expect(r.headers['user-agent']).toContain('snyk-cli/');
}
});
});
});

0 comments on commit 088a3a8

Please sign in to comment.