Skip to content

Commit

Permalink
CLOUDP-74002: [mongocli] Invite users should ask for password if the …
Browse files Browse the repository at this point in the history
…flag is not set (#477)
  • Loading branch information
andreaangiolillo authored Oct 6, 2020
1 parent 860a264 commit c9359aa
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion internal/cli/iam/users/invite.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"strings"

"github.com/AlecAivazis/survey/v2"
"github.com/mongodb/mongocli/internal/cli"
"github.com/mongodb/mongocli/internal/config"
"github.com/mongodb/mongocli/internal/flag"
Expand Down Expand Up @@ -155,6 +156,16 @@ func (opts *InviteOpts) createUserRole() ([]*opsmngr.UserRole, error) {
return nil, nil
}

func (opts *InviteOpts) Prompt() error {
if opts.password != "" {
return nil
}
prompt := &survey.Password{
Message: "Password:",
}
return survey.AskOne(prompt, &opts.password)
}

func splitRole(role string) ([]string, error) {
value := strings.Split(role, ":")
if len(value) != keyParts {
Expand Down Expand Up @@ -233,6 +244,9 @@ func InviteBuilder() *cobra.Command {
return opts.init()
},
RunE: func(cmd *cobra.Command, args []string) error {
if err := opts.Prompt(); err != nil {
return err
}
return opts.Run()
},
}
Expand All @@ -249,7 +263,6 @@ func InviteBuilder() *cobra.Command {
cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut)

_ = cmd.MarkFlagRequired(flag.Username)
_ = cmd.MarkFlagRequired(flag.Password)
_ = cmd.MarkFlagRequired(flag.Email)
_ = cmd.MarkFlagRequired(flag.FirstName)
_ = cmd.MarkFlagRequired(flag.LastName)
Expand Down

0 comments on commit c9359aa

Please sign in to comment.