Skip to content

Commit

Permalink
Update secrets manager spec to render multiple errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nickhammond committed Dec 12, 2024
1 parent ba567e0 commit 84a874e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/kamal/secrets/adapters/aws_secrets_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_from_secrets_manager(secrets, account:)

return secrets["SecretValues"] unless secrets["Errors"].present?

raise RuntimeError, secrets["Errors"].map { |error| "#{error['SecretId']}: #{error['Message']}" }.join(", ")
raise RuntimeError, secrets["Errors"].map { |error| "#{error['SecretId']}: #{error['Message']}" }.join(" ")
end
end

Expand Down
13 changes: 9 additions & 4 deletions test/secrets/aws_secrets_manager_adapter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ class AwsSecretsManagerAdapterTest < SecretAdapterTestCase
test "fails when errors are present" do
stub_ticks.with("aws --version 2> /dev/null")
stub_ticks
.with("aws secretsmanager batch-get-secret-value --secret-id-list unknown-secret-id --profile default")
.with("aws secretsmanager batch-get-secret-value --secret-id-list unknown1 unknown2 --profile default")
.returns(<<~JSON)
{
"SecretValues": [],
"Errors": [
{
"SecretId": "unknown-secret-id",
"SecretId": "unknown1",
"ErrorCode": "ResourceNotFoundException",
"Message": "Secrets Manager can't find the specified secret."
},
{
"SecretId": "unknown2",
"ErrorCode": "ResourceNotFoundException",
"Message": "Secrets Manager can't find the specified secret."
}
Expand All @@ -19,10 +24,10 @@ class AwsSecretsManagerAdapterTest < SecretAdapterTestCase
JSON

error = assert_raises RuntimeError do
JSON.parse(shellunescape(run_command("fetch", "unknown-secret-id")))
JSON.parse(shellunescape(run_command("fetch", "unknown1", "unknown2")))
end

assert_equal "unknown-secret-id: Secrets Manager can't find the specified secret.", error.message
assert_equal ["unknown1: Secrets Manager can't find the specified secret.", "unknown2: Secrets Manager can't find the specified secret."].join(" "), error.message
end

test "fetch" do
Expand Down

0 comments on commit 84a874e

Please sign in to comment.