@@ -34,28 +34,31 @@ def aws_get_secret(secret_name):
3434 try :
3535 get_secret_value_response = client .get_secret_value (SecretId = secret_name )
3636 except ClientError as e :
37- if e .response ["Error" ]["Code" ] == "DecryptionFailureException" :
38- # Secrets Manager can't decrypt the protected secret text..
39- # ... using the provided KMS key.
40- # Deal with the exception here, and/or rethrow at your discretion.
41- raise RetrieveSecretException (e )
42- if e .response ["Error" ]["Code" ] == "InternalServiceErrorException" :
43- # An error occurred on the server side.
44- # Deal with the exception here, and/or rethrow at your discretion.
45- raise RetrieveSecretException (e )
46- if e .response ["Error" ]["Code" ] == "InvalidParameterException" :
47- # You provided an invalid value for a parameter.
48- # Deal with the exception here, and/or rethrow at your discretion.
49- raise RetrieveSecretException (e )
50- if e .response ["Error" ]["Code" ] == "InvalidRequestException" :
51- # You provided a parameter value that is not valid for the..
52- # ... current state of the resource.
53- # Deal with the exception here, and/or rethrow at your discretion.
54- raise RetrieveSecretException (e )
55- if e .response ["Error" ]["Code" ] == "ResourceNotFoundException" :
56- # We can't find the resource that you asked for.
57- # Deal with the exception here, and/or rethrow at your discretion.
58- raise RetrieveSecretException (e )
37+ match e .response ["Error" ]["Code" ]:
38+ case "DecryptionFailureException" | "DecryptionFailure" :
39+ # Secrets Manager can't decrypt the protected secret text..
40+ # ... using the provided KMS key.
41+ # Deal with the exception here, and/or rethrow at your discretion.
42+ raise RetrieveSecretException (e )
43+ case "InternalServiceErrorException" | "InternalServiceError" :
44+ # An error occurred on the server side.
45+ # Deal with the exception here, and/or rethrow at your discretion.
46+ raise RetrieveSecretException (e )
47+ case "InvalidParameterException" :
48+ # You provided an invalid value for a parameter.
49+ # Deal with the exception here, and/or rethrow at your discretion.
50+ raise RetrieveSecretException (e )
51+ case "InvalidRequestException" :
52+ # You provided a parameter value that is not valid for the..
53+ # ... current state of the resource.
54+ # Deal with the exception here, and/or rethrow at your discretion.
55+ raise RetrieveSecretException (e )
56+ case "ResourceNotFoundException" :
57+ # We can't find the resource that you asked for.
58+ # Deal with the exception here, and/or rethrow at your discretion.
59+ raise RetrieveSecretException (e )
60+ case _:
61+ raise RetrieveSecretException (e )
5962 else :
6063 # Decrypts secret using the associated KMS CMK.
6164 # Depending on whether the secret is a string or binary,..
@@ -86,5 +89,8 @@ def get_secret(secret_name, default=""):
8689 logging .error (
8790 f"Error: { e } . Secret: { secret_name } "
8891 ) # lgtm [py/clear-text-logging-sensitive-data]
89-
92+ except Exception as e :
93+ logging .exception (
94+ f"Error: { e } . Secret: { secret_name } "
95+ ) # lgtm [py/clear-text-logging-sensitive-data]
9096 return secret
0 commit comments