Skip to content

Commit 093f509

Browse files
committed
Add --auth support for crictl pull.
Signed-off-by: Lantao Liu <[email protected]>
1 parent 5a01d85 commit 093f509

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

cmd/crictl/image.go

+24-15
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,13 +78,9 @@ 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") {
@@ -327,15 +328,23 @@ func parseCreds(creds string) (string, string, error) {
327328
return up[0], up[1], nil
328329
}
329330

330-
func getAuth(creds string) (*pb.AuthConfig, error) {
331-
username, password, err := parseCreds(creds)
332-
if err != nil {
333-
return nil, err
331+
func getAuth(creds string, auth string) (*pb.AuthConfig, error) {
332+
if creds != "" {
333+
username, password, err := parseCreds(creds)
334+
if err != nil {
335+
return nil, err
336+
}
337+
return &pb.AuthConfig{
338+
Username: username,
339+
Password: password,
340+
}, nil
341+
}
342+
if auth != "" {
343+
return &pb.AuthConfig{
344+
Auth: auth,
345+
}, nil
334346
}
335-
return &pb.AuthConfig{
336-
Username: username,
337-
Password: password,
338-
}, nil
347+
return nil, nil
339348
}
340349

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

0 commit comments

Comments
 (0)