Skip to content

Commit

Permalink
integrating PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
eikenb committed Mar 1, 2023
1 parent 99b8aef commit b3b3229
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions agent/connect/ca/provider_vault_auth_approle.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ func NewAppRoleAuthClient(authMethod *structs.VaultAuthMethod) (*VaultAuthClient
return authClient, nil
}

// don't need to check for legacy params as this func isn't used in that case
func ArLoginDataGen(authMethod *structs.VaultAuthMethod) (map[string]any, error) {
// don't need to check for legacy params as this func isn't used in that case
params := authMethod.Params
// role_id is required
roleIdFilePath := params["role_id_file_path"].(string)
// secret_id is optional (secret_ok is used in check below)
secretIdFilePath, secret_ok := params["secret_id_file_path"].(string)
// secretIdFilePath, secret_ok := params["secret_id_file_path"].(string)
secretIdFilePath, hasSecret := params["secret_id_file_path"].(string)
if hasSecret && strings.TrimSpace(secretIdFilePath) == "" {
hasSecret = false
}

var err error
var rawRoleID, rawSecretID []byte
Expand All @@ -49,11 +53,13 @@ func ArLoginDataGen(authMethod *structs.VaultAuthMethod) (map[string]any, error)
return nil, err
}
data["role_id"] = string(rawRoleID)
switch rawSecretID, err = os.ReadFile(secretIdFilePath); {
case err != nil && secret_ok:
return nil, err
case len(bytes.TrimSpace(rawSecretID)) > 0:
data["secret_id"] = string(rawSecretID)
if hasSecret {
switch rawSecretID, err = os.ReadFile(secretIdFilePath); {
case err != nil:
return nil, err
case len(bytes.TrimSpace(rawSecretID)) > 0:
data["secret_id"] = strings.TrimSpace(string(rawSecretID))
}
}

return data, nil
Expand Down

0 comments on commit b3b3229

Please sign in to comment.