From e3b35911cdfdd6a3fb39e53918974a3461cb6c5b Mon Sep 17 00:00:00 2001 From: ntorba <32570754+ntorba@users.noreply.github.com> Date: Wed, 7 Jun 2023 13:14:03 -0400 Subject: [PATCH 1/5] add check for SecretString --- prefect_aws/secrets_manager.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/prefect_aws/secrets_manager.py b/prefect_aws/secrets_manager.py index 01bc9ba1..2892a0eb 100644 --- a/prefect_aws/secrets_manager.py +++ b/prefect_aws/secrets_manager.py @@ -406,7 +406,10 @@ async def read_secret( response = await run_sync_in_worker_thread( client.get_secret_value, SecretId=self.secret_name, **read_kwargs ) - secret = response["SecretBinary"] + if "SecretBinary" in response: + secret = response["SecretBinary"] + elif "SecretString" in response: + secret = response["SecretString"] arn = response["ARN"] self.logger.info(f"The secret {arn!r} data was successfully read.") return secret From c66deab3061866c36a00708ae9a591fe38a10693 Mon Sep 17 00:00:00 2001 From: ntorba <32570754+ntorba@users.noreply.github.com> Date: Wed, 7 Jun 2023 13:16:03 -0400 Subject: [PATCH 2/5] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46cd8d32..cfc6a0b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Changed - +* Added a check to AwsSecretsManager.load() for 'SecretString' as well as 'SecretBinary' ### Deprecated ### Removed From 368ae7a5174af23346ce823dc5ecd2c069ed02e4 Mon Sep 17 00:00:00 2001 From: nick-amplify <131465708+nick-amplify@users.noreply.github.com> Date: Fri, 9 Jun 2023 13:06:04 -0400 Subject: [PATCH 3/5] Update CHANGELOG.md Co-authored-by: Alexander Streed --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfc6a0b1..266c2a8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Changed -* Added a check to AwsSecretsManager.load() for 'SecretString' as well as 'SecretBinary' +- Added a check to AwsSecretsManager.load() for 'SecretString' as well as 'SecretBinary' - [#274](https://github.com/PrefectHQ/prefect-aws/pull/274) ### Deprecated ### Removed From 15bb8d7bdd2f648da4f28e47e5e7e000d70d9873 Mon Sep 17 00:00:00 2001 From: Alexander Streed Date: Mon, 13 Nov 2023 08:50:06 -0600 Subject: [PATCH 4/5] Adds test for reading secrets --- tests/test_secrets_manager.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_secrets_manager.py b/tests/test_secrets_manager.py index 03d0a08b..712d9d05 100644 --- a/tests/test_secrets_manager.py +++ b/tests/test_secrets_manager.py @@ -199,3 +199,7 @@ def test_delete_secret_recovery_window(self, aws_secret: AwsSecret): ValueError, match="Recovery window must be between 7 and 30 days" ): aws_secret.delete_secret(recovery_window_in_days=42) + + async def test_read_secret(self, secret_under_test, aws_credentials): + secret = AwsSecret(aws_credentials=aws_credentials, secret_name=secret_under_test["secret_name"]) + assert await secret.read_secret() == secret_under_test["expected_value"] From da9cc40641644e4f8f4eeffc296fd0b55ca871c0 Mon Sep 17 00:00:00 2001 From: Alexander Streed Date: Mon, 13 Nov 2023 09:16:40 -0600 Subject: [PATCH 5/5] Fixes formatting --- tests/test_secrets_manager.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_secrets_manager.py b/tests/test_secrets_manager.py index 712d9d05..654f0576 100644 --- a/tests/test_secrets_manager.py +++ b/tests/test_secrets_manager.py @@ -201,5 +201,8 @@ def test_delete_secret_recovery_window(self, aws_secret: AwsSecret): aws_secret.delete_secret(recovery_window_in_days=42) async def test_read_secret(self, secret_under_test, aws_credentials): - secret = AwsSecret(aws_credentials=aws_credentials, secret_name=secret_under_test["secret_name"]) + secret = AwsSecret( + aws_credentials=aws_credentials, + secret_name=secret_under_test["secret_name"], + ) assert await secret.read_secret() == secret_under_test["expected_value"]