@@ -34,7 +34,6 @@ type inputModel struct {
3434 * globalflags.GlobalFlagModel
3535 Username * string
3636 Displayname * string
37- Password * bool
3837 CredentialsRef * string
3938}
4039
@@ -68,6 +67,10 @@ func NewCmd(p *print.Printer) *cobra.Command {
6867 return err
6968 }
7069
70+ req , err := buildRequest (ctx , & model , apiClient , readPassword )
71+ if err != nil {
72+ return err
73+ }
7174 if ! model .AssumeYes {
7275 prompt := fmt .Sprintf ("Are you sure you want to update credential %q?" , * model .CredentialsRef )
7376 err = p .PromptForConfirmation (prompt )
@@ -77,10 +80,6 @@ func NewCmd(p *print.Printer) *cobra.Command {
7780 }
7881
7982 // Call API
80- req , err := buildRequest (ctx , & model , apiClient , readPassword )
81- if err != nil {
82- return err
83- }
8483 resp , err := req .Execute ()
8584 if err != nil {
8685 return fmt .Errorf ("update credential: %w" , err )
@@ -99,26 +98,28 @@ func NewCmd(p *print.Printer) *cobra.Command {
9998func configureFlags (cmd * cobra.Command ) {
10099 cmd .Flags ().StringP (usernameFlag , "u" , "" , "the username for the credentials" )
101100 cmd .Flags ().StringP (displaynameFlag , "d" , "" , "the displayname for the credentials" )
102- cmd . Flags (). BoolP ( passwordFlag , "w" , false , "change the password for the credentials" )
101+ cobra . CheckErr ( flags . MarkFlagsRequired ( cmd , displaynameFlag , usernameFlag , displaynameFlag ) )
103102}
104103
105104func buildRequest (ctx context.Context , model * inputModel , apiClient * alb.APIClient , readPassword func () (string , error )) (req alb.ApiUpdateCredentialsRequest , err error ) {
106105 req = apiClient .UpdateCredentials (ctx , model .ProjectId , model .Region , * model .CredentialsRef )
107106
108107 var password * string
109- if model .Password != nil && * model .Password {
110- p , err := readPassword ()
111- if err != nil {
112- return req , err
113- }
114- password = & p
108+ p , err := readPassword ()
109+ if err != nil {
110+ return req , err
115111 }
112+ password = & p
116113 payload := alb.UpdateCredentialsPayload {
117114 DisplayName : model .Displayname ,
118115 Password : password ,
119116 Username : model .Username ,
120117 }
121118
119+ if model .Displayname == nil && model .Username == nil {
120+ return req , fmt .Errorf ("no attribute to change passed" )
121+ }
122+
122123 return req .UpdateCredentialsPayload (payload ), nil
123124}
124125func readPassword () (string , error ) {
@@ -138,7 +139,7 @@ func readPassword() (string, error) {
138139 return "" , fmt .Errorf ("cannot read password: %w" , err )
139140 }
140141 fmt .Println ()
141- if bytes .Equal (password , confirmation ) {
142+ if ! bytes .Equal (password , confirmation ) {
142143 return "" , fmt .Errorf ("the password and the confirmation do not match" )
143144 }
144145
@@ -149,7 +150,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) inputM
149150 GlobalFlagModel : globalflags .Parse (p , cmd ),
150151 Username : flags .FlagToStringPointer (p , cmd , usernameFlag ),
151152 Displayname : flags .FlagToStringPointer (p , cmd , displaynameFlag ),
152- Password : flags .FlagToBoolPointer (p , cmd , passwordFlag ),
153153 CredentialsRef : & inputArgs [0 ],
154154 }
155155
0 commit comments