Skip to content

Commit

Permalink
Include explicit checking of keys
Browse files Browse the repository at this point in the history
  • Loading branch information
matthijswolters-rl committed Oct 8, 2024
1 parent ce3811a commit 6273e31
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/secret/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func LoadSecretData(apiReader client.Reader, secretName, namespace, dataKey stri

func ReadBasicAuthSecret(apiReader clientv1.SecretInterface, secretName string) (string, string, error) {
secret, err := apiReader.Get(context.TODO(), secretName, metav1.GetOptions{})
var username, password string
username, password := "", ""
if err != nil {
return "", "", err
}
Expand All @@ -44,5 +44,13 @@ func ReadBasicAuthSecret(apiReader clientv1.SecretInterface, secretName string)
}
}

if username == "" {
return "", "", fmt.Errorf("secret %s does not contain expected key '%s'", secretName, "username")
} else if password == "" {
return "", "", fmt.Errorf("secret %s does not contain expected key '%s'", secretName, "password")
} else if username == "" && password == "" {
return "", "", fmt.Errorf("secret %s does not contain expected keys '%s','%s'", secretName, "username", "password")
}

return username, password, err
}

0 comments on commit 6273e31

Please sign in to comment.