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

added password-stdin flag for login #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions cmd/harbor/root/login.go
@@ -1,8 +1,10 @@
package root

import (
"bufio"
"context"
"fmt"
"os"

"github.com/goharbor/go-client/pkg/harbor"
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/user"
Expand All @@ -15,6 +17,7 @@ type loginOptions struct {
serverAddress string
username string
password string
passwordStdin bool
}

// LoginCommand creates a new `harbor login` command
Expand All @@ -40,14 +43,20 @@ func LoginCommand() *cobra.Command {
panic(err)
}
flags.StringVarP(&opts.password, "password", "p", "", "Password")
if err := cmd.MarkFlagRequired("password"); err != nil {
panic(err)
}
flags.BoolVar(&opts.passwordStdin, "password-stdin", false, "Read password from stdin")

return cmd
}

func runLogin(opts loginOptions) error {
if opts.passwordStdin {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter password: ")
password, _ := reader.ReadString('\n')
password = password[:len(password)-1]
opts.password = password
}

clientConfig := &harbor.ClientSetConfig{
URL: opts.serverAddress,
Username: opts.username,
Expand Down