@@ -182,35 +182,27 @@ func (c CredentialsCmd) Get(ctx context.Context, in CredentialsGetInput) error {
182182 return nil
183183}
184184
185- func totpExtraFields (secret , algorithm string , digits , period * int ) ( map [ string ] any , error ) {
185+ func validateTotpSettings (secret , algorithm string , digits , period * int ) error {
186186 if algorithm == "" && digits == nil && period == nil {
187- return nil , nil
187+ return nil
188188 }
189189 if secret == "" {
190- return nil , fmt .Errorf ("TOTP settings require --totp-secret" )
190+ return fmt .Errorf ("TOTP settings require --totp-secret" )
191191 }
192- fields := make (map [string ]any )
193192 if algorithm != "" {
194193 switch strings .ToUpper (algorithm ) {
195194 case "SHA1" , "SHA256" , "SHA512" :
196- fields ["totp_algorithm" ] = strings .ToUpper (algorithm )
197195 default :
198- return nil , fmt .Errorf ("--totp-algorithm must be SHA1, SHA256, or SHA512" )
196+ return fmt .Errorf ("--totp-algorithm must be SHA1, SHA256, or SHA512" )
199197 }
200198 }
201- if digits != nil {
202- if * digits < 6 || * digits > 9 {
203- return nil , fmt .Errorf ("--totp-digits must be between 6 and 9" )
204- }
205- fields ["totp_digits" ] = * digits
199+ if digits != nil && (* digits < 6 || * digits > 9 ) {
200+ return fmt .Errorf ("--totp-digits must be between 6 and 9" )
206201 }
207- if period != nil {
208- if * period < 15 || * period > 300 {
209- return nil , fmt .Errorf ("--totp-period must be between 15 and 300" )
210- }
211- fields ["totp_period" ] = * period
202+ if period != nil && (* period < 15 || * period > 300 ) {
203+ return fmt .Errorf ("--totp-period must be between 15 and 300" )
212204 }
213- return fields , nil
205+ return nil
214206}
215207
216208func (c CredentialsCmd ) Create (ctx context.Context , in CredentialsCreateInput ) error {
@@ -228,8 +220,7 @@ func (c CredentialsCmd) Create(ctx context.Context, in CredentialsCreateInput) e
228220 return fmt .Errorf ("at least one --value is required" )
229221 }
230222
231- extra , err := totpExtraFields (in .TotpSecret , in .TotpAlgorithm , in .TotpDigits , in .TotpPeriod )
232- if err != nil {
223+ if err := validateTotpSettings (in .TotpSecret , in .TotpAlgorithm , in .TotpDigits , in .TotpPeriod ); err != nil {
233224 return err
234225 }
235226 params := kernel.CredentialNewParams {
@@ -245,7 +236,15 @@ func (c CredentialsCmd) Create(ctx context.Context, in CredentialsCreateInput) e
245236 if in .TotpSecret != "" {
246237 params .CreateCredentialRequest .TotpSecret = kernel .Opt (in .TotpSecret )
247238 }
248- params .CreateCredentialRequest .SetExtraFields (extra )
239+ if in .TotpAlgorithm != "" {
240+ params .CreateCredentialRequest .TotpAlgorithm = kernel .CreateCredentialRequestTotpAlgorithm (strings .ToUpper (in .TotpAlgorithm ))
241+ }
242+ if in .TotpDigits != nil {
243+ params .CreateCredentialRequest .TotpDigits = kernel .Int (int64 (* in .TotpDigits ))
244+ }
245+ if in .TotpPeriod != nil {
246+ params .CreateCredentialRequest .TotpPeriod = kernel .Int (int64 (* in .TotpPeriod ))
247+ }
249248
250249 if in .Output != "json" {
251250 pterm .Info .Printf ("Creating credential '%s'...\n " , in .Name )
@@ -294,8 +293,7 @@ func (c CredentialsCmd) Update(ctx context.Context, in CredentialsUpdateInput) e
294293 if err := validateJSONOutput (in .Output ); err != nil {
295294 return err
296295 }
297- extra , err := totpExtraFields (in .TotpSecret , in .TotpAlgorithm , in .TotpDigits , in .TotpPeriod )
298- if err != nil {
296+ if err := validateTotpSettings (in .TotpSecret , in .TotpAlgorithm , in .TotpDigits , in .TotpPeriod ); err != nil {
299297 return err
300298 }
301299
@@ -311,7 +309,15 @@ func (c CredentialsCmd) Update(ctx context.Context, in CredentialsUpdateInput) e
311309 if in .TotpSecret != "" {
312310 params .UpdateCredentialRequest .TotpSecret = kernel .Opt (in .TotpSecret )
313311 }
314- params .UpdateCredentialRequest .SetExtraFields (extra )
312+ if in .TotpAlgorithm != "" {
313+ params .UpdateCredentialRequest .TotpAlgorithm = kernel .UpdateCredentialRequestTotpAlgorithm (strings .ToUpper (in .TotpAlgorithm ))
314+ }
315+ if in .TotpDigits != nil {
316+ params .UpdateCredentialRequest .TotpDigits = kernel .Int (int64 (* in .TotpDigits ))
317+ }
318+ if in .TotpPeriod != nil {
319+ params .UpdateCredentialRequest .TotpPeriod = kernel .Int (int64 (* in .TotpPeriod ))
320+ }
315321 if len (in .Values ) > 0 {
316322 params .UpdateCredentialRequest .Values = in .Values
317323 }
0 commit comments