Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/docker-scan/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func runAuthentication(ctx context.Context, dockerCli command.Cli, flags options
func runScan(ctx context.Context, cmd *cobra.Command, dockerCli command.Cli, flags options, args []string) error {
scanProvider, err := configureProvider(ctx, dockerCli, flags, provider.WithAuthConfig(func(hub *registry.IndexInfo) types.AuthConfig {
return command.ResolveAuthConfig(context.Background(), dockerCli, hub)
}))
}), provider.WithVersion(internal.Version))
if len(args) != 1 {
if err := cmd.Usage(); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion e2e/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Provider: %s
}

func getProviderVersion(env string) string {
if runtime.GOOS != "windows" {
if runtime.GOOS == "linux" {
return fmt.Sprintf("Snyk (%s (standalone))", os.Getenv(env))
}
return fmt.Sprintf("Snyk (%s)", os.Getenv(env))
Expand Down
9 changes: 7 additions & 2 deletions internal/provider/containerizedsnyk.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func (d *dockerSnykProvider) createContainer(token string, containerName string)
"NO_UPDATE_NOTIFIER=true",
"SNYK_CFG_DISABLESUGGESTIONS=true",
"SNYK_INTEGRATION_NAME=DOCKER_DESKTOP",
"SNYK_INTEGRATION_VERSION=" + d.version,
"SNYK_UTM_MEDIUM=Partner",
"SNYK_UTM_SOURCE=Docker",
"SNYK_UTM_CAMPAIGN=Docker-Desktop-2020",
Expand Down Expand Up @@ -282,8 +283,12 @@ func (d *dockerSnykProvider) newCommand(envVars []string, arg ...string) (string
arg[index] = "--file=/app/Dockerfile"
}
}
defaultEnvs := []string{"NO_UPDATE_NOTIFIER=true", "SNYK_CFG_DISABLESUGGESTIONS=true",
"SNYK_INTEGRATION_NAME=DOCKER_DESKTOP"}
defaultEnvs := []string{
"NO_UPDATE_NOTIFIER=true",
"SNYK_CFG_DISABLESUGGESTIONS=true",
"SNYK_INTEGRATION_NAME=DOCKER_DESKTOP",
"SNYK_INTEGRATION_VERSION=" + d.version,
}
envVars = append(envVars, defaultEnvs...)

args := strslice.StrSlice{"snyk"}
Expand Down
13 changes: 11 additions & 2 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Options struct {
out io.Writer
err io.Writer
path string
version string
}

// NewProvider returns default provider options setup with the give options
Expand Down Expand Up @@ -78,15 +79,15 @@ func WithAuthConfig(authResolver func(*registry.IndexInfo) types.AuthConfig) Ops
}
}

//WithContext update the provider with a cancelable context
// WithContext update the provider with a cancelable context
func WithContext(ctx context.Context) Ops {
return func(options *Options) error {
options.context = ctx
return nil
}
}

//WithStreams sets the out and err streams to be used by commands
// WithStreams sets the out and err streams to be used by commands
func WithStreams(out, err io.Writer) Ops {
return func(options *Options) error {
options.out = out
Expand Down Expand Up @@ -184,6 +185,14 @@ func WithExperimental() Ops {
}
}

// WithVersion set the version of the scan cli plugin to the provider
func WithVersion(version string) Ops {
return func(provider *Options) error {
provider.version = version
return nil
}
}

func getToken(opts Options) (string, error) {
if opts.auth.Username == "" {
return "", fmt.Errorf(`You need to be logged in to Docker Hub to use the scan feature.
Expand Down
4 changes: 3 additions & 1 deletion internal/provider/snyk.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ func (s *snykProvider) newCommand(arg ...string) *exec.Cmd {
cmd.Env = append(os.Environ(),
"NO_UPDATE_NOTIFIER=true",
"SNYK_CFG_DISABLESUGGESTIONS=true",
"SNYK_INTEGRATION_NAME=DOCKER_DESKTOP")
"SNYK_INTEGRATION_NAME=DOCKER_DESKTOP",
"SNYK_INTEGRATION_VERSION="+s.version,
)
return cmd
}

Expand Down
15 changes: 11 additions & 4 deletions internal/provider/snyk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ var (
)

const (
snykToken = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
snykToken = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
fakeVersion = "abcd1234"
)

func TestSnykLoginEnvVars(t *testing.T) {
Expand All @@ -48,8 +49,10 @@ func TestSnykLoginEnvVars(t *testing.T) {
err := provider.Authenticate(snykToken)
assert.NilError(t, err)

// SNYK_INTEGRATION is always set
// SNYK_INTEGRATION_NAME is always set
assert.Assert(t, strings.Contains(outStream.String(), "SNYK_INTEGRATION_NAME=DOCKER_DESKTOP"))
// SNYK_INTEGRATION_VERSION is always set
assert.Assert(t, strings.Contains(outStream.String(), "SNYK_INTEGRATION_VERSION="+fakeVersion))
// NO_UPDATE_NOTIFIER disables node.js automatic update notification in console
assert.Assert(t, strings.Contains(outStream.String(), "NO_UPDATE_NOTIFIER=true"))
// SNYK_CFG_DISABLESUGGESTIONS removes user hints from snyk
Expand Down Expand Up @@ -78,8 +81,10 @@ func TestSnykScanEnvVars(t *testing.T) {
err := provider.Scan("image")
assert.NilError(t, err)

// SNYK_INTEGRATION is always set
// SNYK_INTEGRATION_NAME is always set
assert.Assert(t, strings.Contains(outStream.String(), "SNYK_INTEGRATION_NAME=DOCKER_DESKTOP"))
// SNYK_INTEGRATION_VERSION is always set
assert.Assert(t, strings.Contains(outStream.String(), "SNYK_INTEGRATION_VERSION="+fakeVersion))
// NO_UPDATE_NOTIFIER disables node.js automatic update notification in console
assert.Assert(t, strings.Contains(outStream.String(), "NO_UPDATE_NOTIFIER=true"))
// SNYK_CFG_DISABLESUGGESTIONS removes user hints from snyk
Expand All @@ -95,7 +100,9 @@ func setupMockSnykBinary(t *testing.T) (Provider, *bytes.Buffer) {

defaultProvider, err := NewProvider(WithContext(context.Background()),
WithPath(snykPath),
WithStreams(outStream, errStream))
WithStreams(outStream, errStream),
WithVersion(fakeVersion),
)
assert.NilError(t, err)
provider, err := NewSnykProvider(
defaultProvider)
Expand Down
8 changes: 4 additions & 4 deletions vars.mk
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Pinned Versions
SNYK_DESKTOP_VERSION=1.1025.0
SNYK_USER_VERSION=1.1025.0
SNYK_DESKTOP_VERSION=1.1054.0
SNYK_USER_VERSION=1.1054.0
SNYK_OLD_VERSION=1.382.1
# Digest of the 1.1025.0 snyk/snyk:docker image
SNYK_IMAGE_DIGEST=sha256:b979e1827473ce7675439213a918687ac532481c3370818bce61884735bdb09d
# Digest of the 1.1054.0 snyk/snyk:docker image
SNYK_IMAGE_DIGEST=sha256:81c312b1dd662a492a1cf40e597359dd391653293bd17674f8f60a021d687c58
GO_VERSION=1.17.5
CLI_VERSION=20.10.11
ALPINE_VERSION=3.15.0
Expand Down