Skip to content

Commit

Permalink
etcdctl: add --password flag to the subcommand user add
Browse files Browse the repository at this point in the history
  • Loading branch information
mitake committed May 17, 2018
1 parent 1b9791c commit 408716d
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions etcdctl/ctlv3/command/user_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func NewUserCommand() *cobra.Command {

var (
passwordInteractive bool
passwordFromFlag string
)

func newUserAddCommand() *cobra.Command {
Expand All @@ -57,6 +58,7 @@ func newUserAddCommand() *cobra.Command {
}

cmd.Flags().BoolVar(&passwordInteractive, "interactive", true, "Read password from stdin instead of interactive terminal")
cmd.Flags().StringVar(&passwordFromFlag, "password", "", "Supply password from the command line flag")

return &cmd
}
Expand Down Expand Up @@ -126,19 +128,24 @@ func userAddCommandFunc(cmd *cobra.Command, args []string) {
var password string
var user string

splitted := strings.SplitN(args[0], ":", 2)
if len(splitted) < 2 {
if passwordFromFlag != "" {
user = args[0]
if !passwordInteractive {
fmt.Scanf("%s", &password)
} else {
password = readPasswordInteractive(args[0])
}
password = passwordFromFlag
} else {
user = splitted[0]
password = splitted[1]
if len(user) == 0 {
ExitWithError(ExitBadArgs, fmt.Errorf("empty user name is not allowed."))
splitted := strings.SplitN(args[0], ":", 2)
if len(splitted) < 2 {
user = args[0]
if !passwordInteractive {
fmt.Scanf("%s", &password)
} else {
password = readPasswordInteractive(args[0])
}
} else {
user = splitted[0]
password = splitted[1]
if len(user) == 0 {
ExitWithError(ExitBadArgs, fmt.Errorf("empty user name is not allowed."))
}
}
}

Expand Down

0 comments on commit 408716d

Please sign in to comment.