Skip to content
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

Merged
merged 1 commit into from
Sep 26, 2018
Merged
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
43 changes: 27 additions & 16 deletions cmd/crictl/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ var pullImageCommand = cli.Command{
Value: "",
Usage: "Use `USERNAME[:PASSWORD]` for accessing the registry",
},
cli.StringFlag{
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Let it fail.

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: "",
Expand All @@ -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") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

declaration of "err" shadows declaration at cmd/crictl/image.go:81 (vetshadow)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is super annoying, we ignore that error in containerd. :P

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
Expand Down Expand Up @@ -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.
Expand Down