Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 2bc8d8d

Browse files
Merge pull request #105 from glours/use_login_flag
Change --auth to --login command plus --token flag
2 parents 9f4f3c3 + ead1095 commit 2bc8d8d

4 files changed

Lines changed: 24 additions & 23 deletions

File tree

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,37 +226,38 @@ Tested 200 dependencies for known issues, found 157 issues.
226226

227227
If you have an existing Snyk account, you can directly use your auth token
228228
```console
229-
$ docker scan --auth PROVIDER_AUTH_TOKEN
229+
$ docker scan --login --token PROVIDER_AUTH_TOKEN
230230
```
231231

232232
You need to get a Snyk [API token](https://app.snyk.io/account) and then use it like this
233233
```console
234-
$ docker scan --auth c68dc480-27bd-45ee-9f5c-XXXXXXXXXXXX
234+
$ docker scan --login --token c68dc480-27bd-45ee-9f5c-XXXXXXXXXXXX
235235

236236
Your account has been authenticated. Snyk is now ready to be used.
237237
```
238238

239-
If you use the `auth` command without any token, you will be redirected to the Snyk website to login.
239+
If you use the `--login` command without any token, you will be redirected to the Snyk website to login.
240240

241241
## Install Docker Scan
242242

243243
### On macOS & Windows:
244244
Docker Desktop comes with Docker scan already installed.
245245
Just try to use the plugin, open a terminal and write the following command:
246246
```console
247-
docker scan
248-
Usage: docker scan [OPTIONS] IMAGE
247+
$ docker scan
248+
Usage: docker scan [OPTIONS] IMAGE
249249

250250
A tool to scan your docker image
251251

252252
Options:
253253
--accept-license Accept to using a third party scanning provider
254-
--auth Authenticate to the scan provider using an optional token, or web base token if empty
255254
--dependency-tree Show dependency tree with scan results
256255
--exclude-base Exclude base image from vulnerability scanning (requires --file)
257256
-f, --file string Dockerfile associated with image
258257
--json Output results in JSON format
258+
--login Authenticate to the scan provider using an optional token (with --token), or web base token if empty
259259
--reject-license Reject to using a third party scanning provider
260+
--token string Authentication token for login to the scan provider
260261
--version Display version of the scan plugin
261262
```
262263

cmd/docker-scan/main.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ func main() {
6060
}
6161

6262
type options struct {
63-
authenticate bool
63+
login bool
64+
token string
6465
dependencyTree bool
6566
dockerFilePath string
6667
excludeBase bool
@@ -81,13 +82,14 @@ func newScanCmd(ctx context.Context, dockerCli command.Cli) *cobra.Command {
8182
if flags.showVersion {
8283
return runVersion(ctx, dockerCli, flags)
8384
}
84-
if flags.authenticate {
85+
if flags.login {
8586
return runAuthentication(ctx, dockerCli, flags, args)
8687
}
8788
return runScan(ctx, cmd, dockerCli, flags, args)
8889
},
8990
}
90-
cmd.Flags().BoolVar(&flags.authenticate, "auth", false, "Authenticate to the scan provider using an optional token, or web base token if empty")
91+
cmd.Flags().BoolVar(&flags.login, "login", false, "Authenticate to the scan provider using an optional token (with --token), or web base token if empty")
92+
cmd.Flags().StringVar(&flags.token, "token", "", "Authentication token for login to the scan provider")
9193
cmd.Flags().BoolVar(&flags.dependencyTree, "dependency-tree", false, "Show dependency tree with scan results")
9294
cmd.Flags().BoolVar(&flags.excludeBase, "exclude-base", false, "Exclude base image from vulnerability scanning (requires --file)")
9395
cmd.Flags().StringVarP(&flags.dockerFilePath, "file", "f", "", "Dockerfile associated with image")
@@ -170,18 +172,14 @@ func runVersion(ctx context.Context, dockerCli command.Streams, flags options) e
170172
}
171173

172174
func runAuthentication(ctx context.Context, dockerCli command.Streams, flags options, args []string) error {
175+
if len(args) != 0 {
176+
return fmt.Errorf(`--login flag expects no argument`)
177+
}
173178
scanProvider, err := configureProvider(ctx, dockerCli, flags)
174179
if err != nil {
175180
return err
176181
}
177-
token := ""
178-
switch {
179-
case len(args) == 1:
180-
token = args[0]
181-
case len(args) > 1:
182-
return fmt.Errorf(`--auth flag expects maximum one argument`)
183-
}
184-
return scanProvider.Authenticate(token)
182+
return scanProvider.Authenticate(flags.token)
185183
}
186184

187185
func runScan(ctx context.Context, cmd *cobra.Command, dockerCli command.Cli, flags options, args []string) error {

e2e/auth_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestSnykAuthentication(t *testing.T) {
4343
token := os.Getenv("E2E_TEST_AUTH_TOKEN")
4444
assert.Assert(t, token != "", "E2E_TEST_AUTH_TOKEN needs to be filled")
4545

46-
cmd.Command = dockerCli.Command("scan", "--accept-license", "--auth", token)
46+
cmd.Command = dockerCli.Command("scan", "--accept-license", "--login", "--token", token)
4747
icmd.RunCmd(cmd).Assert(t, icmd.Success)
4848

4949
// snyk config file should be updated
@@ -59,18 +59,18 @@ func TestAuthenticationFlagFailsWithImage(t *testing.T) {
5959
token := os.Getenv("E2E_TEST_AUTH_TOKEN")
6060
assert.Assert(t, token != "", "E2E_TEST_AUTH_TOKEN needs to be filled")
6161

62-
cmd.Command = dockerCli.Command("scan", "--accept-license", "--auth", token, "example:image")
62+
cmd.Command = dockerCli.Command("scan", "--accept-license", "--login", "--token", token, "example:image")
6363
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
6464
ExitCode: 1,
65-
Err: "--auth flag expects maximum one argument",
65+
Err: "--login flag expects no argument",
6666
})
6767
}
6868

6969
func TestAuthenticationChecksToken(t *testing.T) {
7070
cmd, _, cleanup := dockerCli.createTestCmd()
7171
defer cleanup()
7272

73-
cmd.Command = dockerCli.Command("scan", "--accept-license", "--auth", "invalid-token")
73+
cmd.Command = dockerCli.Command("scan", "--accept-license", "--login", "--token", "invalid-token")
7474
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
7575
ExitCode: 1,
7676
Err: `invalid authentication token "invalid-token"`,

e2e/testdata/plugin-usage.golden

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ A tool to scan your docker image
55

66
Options:
77
--accept-license Accept to using a third party scanning provider
8-
--auth Authenticate to the scan provider using an
9-
optional token, or web base token if empty
108
--dependency-tree Show dependency tree with scan results
119
--exclude-base Exclude base image from vulnerability scanning
1210
(requires --file)
1311
-f, --file string Dockerfile associated with image
1412
--json Output results in JSON format
13+
--login Authenticate to the scan provider using an
14+
optional token (with --token), or web base
15+
token if empty
1516
--reject-license Reject to using a third party scanning provider
17+
--token string Authentication token for login to the scan provider
1618
--version Display version of the scan plugin

0 commit comments

Comments
 (0)