From 84a874e63b39d42d4c82dc9411b5af9e4853f766 Mon Sep 17 00:00:00 2001 From: Nick Hammond Date: Thu, 12 Dec 2024 05:15:52 -0700 Subject: [PATCH] Update secrets manager spec to render multiple errors --- lib/kamal/secrets/adapters/aws_secrets_manager.rb | 2 +- test/secrets/aws_secrets_manager_adapter_test.rb | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/kamal/secrets/adapters/aws_secrets_manager.rb b/lib/kamal/secrets/adapters/aws_secrets_manager.rb index c9314ca52..4bcac21d5 100644 --- a/lib/kamal/secrets/adapters/aws_secrets_manager.rb +++ b/lib/kamal/secrets/adapters/aws_secrets_manager.rb @@ -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 diff --git a/test/secrets/aws_secrets_manager_adapter_test.rb b/test/secrets/aws_secrets_manager_adapter_test.rb index 5873731e5..60074778b 100644 --- a/test/secrets/aws_secrets_manager_adapter_test.rb +++ b/test/secrets/aws_secrets_manager_adapter_test.rb @@ -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." } @@ -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