mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdctl: accept user:pass format for add user
Otherwise needed an interactive terminal to create a user.
This commit is contained in:
parent
3b185f130a
commit
02d9aa481b
@ -109,15 +109,17 @@ func actionUserList(c *cli.Context) {
|
||||
}
|
||||
|
||||
func actionUserAdd(c *cli.Context) {
|
||||
api, user := mustUserAPIAndName(c)
|
||||
api, userarg := mustUserAPIAndName(c)
|
||||
ctx, cancel := contextWithTotalTimeout(c)
|
||||
defer cancel()
|
||||
user, _, _ := getUsernamePassword("", userarg+":")
|
||||
currentUser, err := api.GetUser(ctx, user)
|
||||
if currentUser != nil {
|
||||
fmt.Fprintf(os.Stderr, "User %s already exists\n", user)
|
||||
os.Exit(1)
|
||||
}
|
||||
pass, err := speakeasy.Ask("New password: ")
|
||||
|
||||
_, pass, err := getUsernamePassword("New password: ", userarg)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "Error reading password:", err)
|
||||
os.Exit(1)
|
||||
|
@ -172,11 +172,15 @@ func getTransport(c *cli.Context) (*http.Transport, error) {
|
||||
}
|
||||
|
||||
func getUsernamePasswordFromFlag(usernameFlag string) (username string, password string, err error) {
|
||||
return getUsernamePassword("Password: ", usernameFlag)
|
||||
}
|
||||
|
||||
func getUsernamePassword(prompt, usernameFlag string) (username string, password string, err error) {
|
||||
colon := strings.Index(usernameFlag, ":")
|
||||
if colon == -1 {
|
||||
username = usernameFlag
|
||||
// Prompt for the password.
|
||||
password, err = speakeasy.Ask("Password: ")
|
||||
password, err = speakeasy.Ask(prompt)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user