mirror of
https://github.com/smallstep/certificates.git
synced 2024-11-11 07:11:00 +00:00
rewrite and improve secret-id config
This commit is contained in:
parent
6989c7f146
commit
9ec154aab0
@ -41,19 +41,20 @@ func NewApproleAuthMethod(mountPath string, options json.RawMessage) (*approle.A
|
|||||||
}
|
}
|
||||||
|
|
||||||
var sid approle.SecretID
|
var sid approle.SecretID
|
||||||
if opts.SecretID != "" {
|
switch {
|
||||||
|
case opts.SecretID != "" && opts.SecretIDFile == "" && opts.SecretIDEnv == "":
|
||||||
sid = approle.SecretID{
|
sid = approle.SecretID{
|
||||||
FromString: opts.SecretID,
|
FromString: opts.SecretID,
|
||||||
}
|
}
|
||||||
} else if opts.SecretIDFile != "" {
|
case opts.SecretIDFile != "" && opts.SecretID == "" && opts.SecretIDEnv == "":
|
||||||
sid = approle.SecretID{
|
sid = approle.SecretID{
|
||||||
FromFile: opts.SecretIDFile,
|
FromFile: opts.SecretIDFile,
|
||||||
}
|
}
|
||||||
} else if opts.SecretIDEnv != "" {
|
case opts.SecretIDEnv != "" && opts.SecretIDFile == "" && opts.SecretID == "":
|
||||||
sid = approle.SecretID{
|
sid = approle.SecretID{
|
||||||
FromEnv: opts.SecretIDEnv,
|
FromEnv: opts.SecretIDEnv,
|
||||||
}
|
}
|
||||||
} else {
|
default:
|
||||||
return nil, errors.New("you must set one of secretID, secretIDFile or secretIDEnv")
|
return nil, errors.New("you must set one of secretID, secretIDFile or secretIDEnv")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,6 +158,30 @@ func TestApprole_NewApproleAuthMethod(t *testing.T) {
|
|||||||
`{"RoleID": "0000-0000-0000-0000"}`,
|
`{"RoleID": "0000-0000-0000-0000"}`,
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"fail multiple secret-id types id and env",
|
||||||
|
"",
|
||||||
|
`{"RoleID": "0000-0000-0000-0000", "SecretID": "0000-0000-0000-0000", "SecretIDEnv": "VAULT_APPROLE_SECRETID"}`,
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fail multiple secret-id types id and file",
|
||||||
|
"",
|
||||||
|
`{"RoleID": "0000-0000-0000-0000", "SecretID": "0000-0000-0000-0000", "SecretIDFile": "./secret-id"}`,
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fail multiple secret-id types env and file",
|
||||||
|
"",
|
||||||
|
`{"RoleID": "0000-0000-0000-0000", "SecretIDFile": "./secret-id", "SecretIDEnv": "VAULT_APPROLE_SECRETID"}`,
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fail multiple secret-id types all",
|
||||||
|
"",
|
||||||
|
`{"RoleID": "0000-0000-0000-0000", "SecretID": "0000-0000-0000-0000", "SecretIDFile": "./secret-id", "SecretIDEnv": "VAULT_APPROLE_SECRETID"}`,
|
||||||
|
true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user