Skip to content

Commit

Permalink
fix(option): hide false warning about remote options (#1865)
Browse files Browse the repository at this point in the history
  • Loading branch information
afdesk authored Mar 22, 2022
1 parent 218f19c commit 7326709
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ require (
github.com/open-policy-agent/opa v0.37.2
github.com/owenrumney/go-sarif/v2 v2.1.1
github.com/package-url/packageurl-go v0.1.1-0.20220203205134-d70459300c8a
github.com/spf13/afero v1.8.1
github.com/spf13/afero v1.8.1 // indirect
github.com/stretchr/testify v1.7.0
github.com/testcontainers/testcontainers-go v0.12.0
github.com/twitchtv/twirp v8.1.1+incompatible
Expand Down
3 changes: 2 additions & 1 deletion pkg/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/aquasecurity/trivy-db/pkg/metadata"
dbTypes "github.com/aquasecurity/trivy-db/pkg/types"
"github.com/aquasecurity/trivy/pkg/commands/artifact"
"github.com/aquasecurity/trivy/pkg/commands/option"
"github.com/aquasecurity/trivy/pkg/commands/plugin"
"github.com/aquasecurity/trivy/pkg/commands/server"
"github.com/aquasecurity/trivy/pkg/result"
Expand Down Expand Up @@ -215,7 +216,7 @@ var (

tokenHeader = cli.StringFlag{
Name: "token-header",
Value: "Trivy-Token",
Value: option.DefaultTokenHeader,
Usage: "specify a header name for token in client/server mode",
EnvVars: []string{"TRIVY_TOKEN_HEADER"},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/artifact/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func TestOption_Init(t *testing.T) {
set.String("format", "", "")
set.String("server", "", "")
set.String("token", "", "")
set.String("token-header", "", "")
set.String("token-header", option.DefaultTokenHeader, "")
set.Var(&cli.StringSlice{}, "custom-headers", "")

ctx := cli.NewContext(app, set, nil)
Expand Down
4 changes: 3 additions & 1 deletion pkg/commands/option/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"go.uber.org/zap"
)

const DefaultTokenHeader = "Trivy-Token"

// RemoteOption holds options for client/server
type RemoteOption struct {
RemoteAddr string
Expand Down Expand Up @@ -48,7 +50,7 @@ func (c *RemoteOption) Init(logger *zap.SugaredLogger) {
}

if c.RemoteAddr == "" {
if len(c.customHeaders) > 0 || c.token != "" || c.tokenHeader != "" {
if len(c.customHeaders) > 0 || c.token != "" || c.tokenHeader != DefaultTokenHeader {
logger.Warn(`'--token', '--token-header' and 'custom-header' can be used only with '--server'`)
}
return
Expand Down

0 comments on commit 7326709

Please sign in to comment.