-
Notifications
You must be signed in to change notification settings - Fork 461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --auth
support for crictl pull
.
#390
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,11 @@ var pullImageCommand = cli.Command{ | |
Value: "", | ||
Usage: "Use `USERNAME[:PASSWORD]` for accessing the registry", | ||
}, | ||
cli.StringFlag{ | ||
Name: "auth", | ||
Value: "", | ||
Usage: "Use `AUTH_STRING` for accessing the registry. AUTH_STRING is a base64 encoded 'USERNAME[:PASSWORD]'", | ||
}, | ||
cli.StringFlag{ | ||
Name: "pod-config", | ||
Value: "", | ||
|
@@ -73,17 +78,12 @@ var pullImageCommand = cli.Command{ | |
return err | ||
} | ||
|
||
var auth *pb.AuthConfig | ||
if context.IsSet("creds") { | ||
var err error | ||
auth, err = getAuth(context.String("creds")) | ||
if err != nil { | ||
return err | ||
} | ||
auth, err := getAuth(context.String("creds"), context.String("auth")) | ||
if err != nil { | ||
return err | ||
} | ||
var sandbox *pb.PodSandboxConfig | ||
if context.IsSet("pod-config") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. declaration of "err" shadows declaration at cmd/crictl/image.go:81 (vetshadow) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is super annoying, we ignore that error in containerd. :P There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
var err error | ||
sandbox, err = loadPodSandboxConfig(context.String("pod-config")) | ||
if err != nil { | ||
return fmt.Errorf("load podSandboxConfig failed: %v", err) | ||
|
@@ -327,15 +327,26 @@ func parseCreds(creds string) (string, string, error) { | |
return up[0], up[1], nil | ||
} | ||
|
||
func getAuth(creds string) (*pb.AuthConfig, error) { | ||
username, password, err := parseCreds(creds) | ||
if err != nil { | ||
return nil, err | ||
func getAuth(creds string, auth string) (*pb.AuthConfig, error) { | ||
if creds != "" && auth != "" { | ||
return nil, errors.New("both `--creds` and `--auth` are specified") | ||
} | ||
if creds != "" { | ||
username, password, err := parseCreds(creds) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &pb.AuthConfig{ | ||
Username: username, | ||
Password: password, | ||
}, nil | ||
} | ||
if auth != "" { | ||
return &pb.AuthConfig{ | ||
Auth: auth, | ||
}, nil | ||
} | ||
return &pb.AuthConfig{ | ||
Username: username, | ||
Password: password, | ||
}, nil | ||
return nil, nil | ||
} | ||
|
||
// Ideally repo tag should always be image:tag. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the command fail when both "creds" and "auth" are specified? If not, the usage should explain which takes precedence over the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Let it fail.