Skip to content

Commit

Permalink
Added profile support for AWS secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
akclace committed Sep 11, 2024
1 parent 874e399 commit 477aebc
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions internal/system/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,24 @@ type awsSecretProvider struct {
}

func (a *awsSecretProvider) Configure(ctx context.Context, conf map[string]any) error {
cfg, err := config.LoadDefaultConfig(ctx)
// IAM is automatically supported by default config
profileStr := ""
profile, ok := conf["profile"]
if ok {
profileStr, ok = profile.(string)
if !ok {
return fmt.Errorf("profile must be a string")
}
}

var cfg aws.Config
var err error
// IAM is automatically supported by config load
if profileStr != "" {
cfg, err = config.LoadDefaultConfig(ctx, config.WithSharedConfigProfile(profileStr))
} else {
cfg, err = config.LoadDefaultConfig(ctx)
}

if err != nil {
return err
}
Expand Down Expand Up @@ -141,12 +157,12 @@ type vaultSecretProvider struct {
func getConfigString(conf map[string]any, key string) (string, error) {
value, ok := conf[key]
if !ok {
return "", fmt.Errorf("missing %s in config", key)
return "", fmt.Errorf("missing '%s' in config", key)
}

valueStr, ok := value.(string)
if !ok {
return "", fmt.Errorf("%s must be a string", key)
return "", fmt.Errorf("'%s' must be a string", key)
}

return valueStr, nil
Expand All @@ -155,11 +171,11 @@ func getConfigString(conf map[string]any, key string) (string, error) {
func (v *vaultSecretProvider) Configure(ctx context.Context, conf map[string]any) error {
address, err := getConfigString(conf, "address")
if err != nil {
return err
return fmt.Errorf("vault invalid config: %w", err)
}
token, err := getConfigString(conf, "token")
if err != nil {
return err
return fmt.Errorf("vault invalid config: %w", err)
}

vaultConfig := &api.Config{
Expand Down

0 comments on commit 477aebc

Please sign in to comment.