2026-04-06 15:48:37 +05:30
// Copyright IBM Corp. 2020, 2026
2025-10-29 11:00:09 -05:00
// SPDX-License-Identifier: BUSL-1.1
package credentialscmd
import (
"errors"
"fmt"
2026-10-12 10:33:41 -07:00
"repo.anhonesthost.net/CyberCoveLLC/threshold/api/credentials"
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/cmd/base"
2025-10-29 11:00:09 -05:00
"github.com/hashicorp/go-secure-stdlib/parseutil"
)
func init () {
extraPasswordFlagsFunc = extraPasswordFlagsFuncImpl
extraPasswordActionsFlagsMapFunc = extraPasswordActionsFlagsMapFuncImpl
extraPasswordFlagsHandlingFunc = extraPasswordFlagHandlingFuncImpl
}
type extraPasswordCmdVars struct {
flagPassword string
}
func extraPasswordActionsFlagsMapFuncImpl () map [ string ][] string {
flags := map [ string ][] string {
"create" : {
passwordFlagName ,
},
}
flags [ "update" ] = flags [ "create" ]
return flags
}
func extraPasswordFlagsFuncImpl ( c * PasswordCommand , set * base . FlagSets , _ * base . FlagSet ) {
f := set . NewFlagSet ( "Password Credential Options" )
for _ , name := range flagsPasswordMap [ c . Func ] {
switch name {
case passwordFlagName :
f . StringVar ( & base . StringVar {
Name : passwordFlagName ,
Target : & c . flagPassword ,
Usage : "The password associated with the credential. This can be a file on disk (file://) from which the value will be read, or an env var (env://) from which the value will be read." ,
})
}
}
}
func extraPasswordFlagHandlingFuncImpl ( c * PasswordCommand , _ * base . FlagSets , opts * [] credentials . Option ) bool {
switch c . flagPassword {
case "" :
default :
password , err := parseutil . MustParsePath ( c . flagPassword )
switch {
case err == nil :
case errors . Is ( err , parseutil . ErrNotParsed ):
c . UI . Error ( "Password flag must be used with env:// or file:// syntax" )
return false
default :
c . UI . Error ( fmt . Sprintf ( "Error parsing password flag: %v" , err ))
return false
}
* opts = append ( * opts , credentials . WithPasswordCredentialPassword ( password ))
}
return true
}
func ( c * PasswordCommand ) extraPasswordHelpFunc ( _ map [ string ] func () string ) string {
var helpStr string
switch c . Func {
case "create" :
helpStr = base . WrapForHelpText ([] string {
2026-10-12 10:20:06 -07:00
"Usage: threshold credentials create password -credential-store-id [options] [args]" ,
2025-10-29 11:00:09 -05:00
"" ,
" Create a password credential. Example:" ,
"" ,
2026-10-12 10:20:06 -07:00
` $ threshold credentials create password -credential-store-id csvlt_1234567890 -password pass` ,
2025-10-29 11:00:09 -05:00
"" ,
"" ,
})
case "update" :
helpStr = base . WrapForHelpText ([] string {
2026-10-12 10:20:06 -07:00
"Usage: threshold credentials update password [options] [args]" ,
2025-10-29 11:00:09 -05:00
"" ,
" Update a password credential given its ID. Example:" ,
"" ,
2026-10-12 10:20:06 -07:00
` $ threshold credentials update password -id clvlt_1234567890 -name devops -description "For DevOps usage"` ,
2025-10-29 11:00:09 -05:00
"" ,
"" ,
})
}
return helpStr + c . Flags (). Help ()
}