Skip to content

Commit 745e258

Browse files
authored
Merge pull request #390 from Random-Liu/add-auth-flag
Add `--auth` support for `crictl pull`.
2 parents 5a01d85 + 293aed6 commit 745e258

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

cmd/crictl/image.go

+27-16
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ var pullImageCommand = cli.Command{
5656
Value: "",
5757
Usage: "Use `USERNAME[:PASSWORD]` for accessing the registry",
5858
},
59+
cli.StringFlag{
60+
Name: "auth",
61+
Value: "",
62+
Usage: "Use `AUTH_STRING` for accessing the registry. AUTH_STRING is a base64 encoded 'USERNAME[:PASSWORD]'",
63+
},
5964
cli.StringFlag{
6065
Name: "pod-config",
6166
Value: "",
@@ -73,17 +78,12 @@ var pullImageCommand = cli.Command{
7378
return err
7479
}
7580

76-
var auth *pb.AuthConfig
77-
if context.IsSet("creds") {
78-
var err error
79-
auth, err = getAuth(context.String("creds"))
80-
if err != nil {
81-
return err
82-
}
81+
auth, err := getAuth(context.String("creds"), context.String("auth"))
82+
if err != nil {
83+
return err
8384
}
8485
var sandbox *pb.PodSandboxConfig
8586
if context.IsSet("pod-config") {
86-
var err error
8787
sandbox, err = loadPodSandboxConfig(context.String("pod-config"))
8888
if err != nil {
8989
return fmt.Errorf("load podSandboxConfig failed: %v", err)
@@ -327,15 +327,26 @@ func parseCreds(creds string) (string, string, error) {
327327
return up[0], up[1], nil
328328
}
329329

330-
func getAuth(creds string) (*pb.AuthConfig, error) {
331-
username, password, err := parseCreds(creds)
332-
if err != nil {
333-
return nil, err
330+
func getAuth(creds string, auth string) (*pb.AuthConfig, error) {
331+
if creds != "" && auth != "" {
332+
return nil, errors.New("both `--creds` and `--auth` are specified")
333+
}
334+
if creds != "" {
335+
username, password, err := parseCreds(creds)
336+
if err != nil {
337+
return nil, err
338+
}
339+
return &pb.AuthConfig{
340+
Username: username,
341+
Password: password,
342+
}, nil
343+
}
344+
if auth != "" {
345+
return &pb.AuthConfig{
346+
Auth: auth,
347+
}, nil
334348
}
335-
return &pb.AuthConfig{
336-
Username: username,
337-
Password: password,
338-
}, nil
349+
return nil, nil
339350
}
340351

341352
// Ideally repo tag should always be image:tag.

0 commit comments

Comments
 (0)