Raise appropriate error when secret exists but has no value
This commit is contained in:
parent
cc96a5e659
commit
381e7b165f
4 changed files with 51 additions and 10 deletions
|
|
@ -7,11 +7,11 @@ class SecretsManagerClientError(JsonRESTError):
|
|||
|
||||
|
||||
class ResourceNotFoundException(SecretsManagerClientError):
|
||||
def __init__(self):
|
||||
def __init__(self, message):
|
||||
self.code = 404
|
||||
super(ResourceNotFoundException, self).__init__(
|
||||
"ResourceNotFoundException",
|
||||
"Secrets Manager can't find the specified secret"
|
||||
message,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class SecretsManagerBackend(BaseBackend):
|
|||
def get_secret_value(self, secret_id, version_id, version_stage):
|
||||
|
||||
if not self._is_valid_identifier(secret_id):
|
||||
raise ResourceNotFoundException()
|
||||
raise ResourceNotFoundException("Secrets Manager can't find the specified secret")
|
||||
|
||||
if not version_id and version_stage:
|
||||
# set version_id to match version_stage
|
||||
|
|
@ -56,7 +56,7 @@ class SecretsManagerBackend(BaseBackend):
|
|||
version_id = ver_id
|
||||
break
|
||||
if not version_id:
|
||||
raise ResourceNotFoundException()
|
||||
raise ResourceNotFoundException("Secrets Manager can't find the specified secret")
|
||||
|
||||
# TODO check this part
|
||||
if 'deleted_date' in self.secrets[secret_id]:
|
||||
|
|
@ -84,6 +84,12 @@ class SecretsManagerBackend(BaseBackend):
|
|||
if 'secret_binary' in secret_version:
|
||||
response_data["SecretBinary"] = secret_version['secret_binary']
|
||||
|
||||
if 'secret_string' not in secret_version and 'secret_binary' not in secret_version:
|
||||
raise ResourceNotFoundException(
|
||||
"Secrets Manager can’t find the specified secret value for staging label: %s" %
|
||||
(version_stage or "AWSCURRENT")
|
||||
)
|
||||
|
||||
response = json.dumps(response_data)
|
||||
|
||||
return response
|
||||
|
|
@ -169,7 +175,7 @@ class SecretsManagerBackend(BaseBackend):
|
|||
|
||||
def describe_secret(self, secret_id):
|
||||
if not self._is_valid_identifier(secret_id):
|
||||
raise ResourceNotFoundException
|
||||
raise ResourceNotFoundException("Secrets Manager can't find the specified secret")
|
||||
|
||||
secret = self.secrets[secret_id]
|
||||
|
||||
|
|
@ -198,7 +204,7 @@ class SecretsManagerBackend(BaseBackend):
|
|||
rotation_days = 'AutomaticallyAfterDays'
|
||||
|
||||
if not self._is_valid_identifier(secret_id):
|
||||
raise ResourceNotFoundException
|
||||
raise ResourceNotFoundException("Secrets Manager can't find the specified secret")
|
||||
|
||||
if 'deleted_date' in self.secrets[secret_id]:
|
||||
raise InvalidRequestException(
|
||||
|
|
@ -340,7 +346,7 @@ class SecretsManagerBackend(BaseBackend):
|
|||
def delete_secret(self, secret_id, recovery_window_in_days, force_delete_without_recovery):
|
||||
|
||||
if not self._is_valid_identifier(secret_id):
|
||||
raise ResourceNotFoundException
|
||||
raise ResourceNotFoundException("Secrets Manager can't find the specified secret")
|
||||
|
||||
if 'deleted_date' in self.secrets[secret_id]:
|
||||
raise InvalidRequestException(
|
||||
|
|
@ -370,7 +376,7 @@ class SecretsManagerBackend(BaseBackend):
|
|||
secret = self.secrets.get(secret_id, None)
|
||||
|
||||
if not secret:
|
||||
raise ResourceNotFoundException
|
||||
raise ResourceNotFoundException("Secrets Manager can't find the specified secret")
|
||||
|
||||
arn = secret_arn(self.region, secret['secret_id'])
|
||||
name = secret['name']
|
||||
|
|
@ -380,7 +386,7 @@ class SecretsManagerBackend(BaseBackend):
|
|||
def restore_secret(self, secret_id):
|
||||
|
||||
if not self._is_valid_identifier(secret_id):
|
||||
raise ResourceNotFoundException
|
||||
raise ResourceNotFoundException("Secrets Manager can't find the specified secret")
|
||||
|
||||
self.secrets[secret_id].pop('deleted_date', None)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue