Skip to content

Commit

Permalink
Add error checking and iterate over permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
amold1 committed Feb 29, 2024
1 parent 95f7885 commit 449dc09
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions cloud/scope/object_storage_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,18 @@ func (s *ObjectStorageBucketScope) GetAccessKeysFromSecret(ctx context.Context,
return newKeys, err
}
}
for i, e := range []struct {
permission string
suffix string
}{
{"read_write", "rw"},
{"read_only", "ro"},
} {
secretDataForKey, isset := secret.Data[e.permission]
permissions := [2]string{"read_write", "read_only"}
for _, permission := range permissions {
secretDataForKey, isset := secret.Data[permission]
if !isset {
return newKeys, fmt.Errorf("secret %s missing data field: %s", secretName, e.permission)
return newKeys, fmt.Errorf("secret %s missing data field: %s", secretName, permission)
}
decodedSecretDataForKey := string(secretDataForKey)

var jsonMap map[string]interface{}
json.Unmarshal([]byte(string(decodedSecretDataForKey)), &jsonMap)
if err := json.Unmarshal([]byte(string(decodedSecretDataForKey)), &jsonMap); err != nil {
return newKeys, fmt.Errorf("error unmarshalling key: %w", err)
}

accessKeyID, ok := jsonMap["id"]
if !ok {
Expand Down

0 comments on commit 449dc09

Please sign in to comment.