Use specialised exception for "secret has no value" scenario
This commit is contained in:
parent
6120a60263
commit
30853a0b5c
@ -15,6 +15,7 @@ class ResourceNotFoundException(SecretsManagerClientError):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Using specialised exception due to the use of a non-ASCII character
|
||||||
class SecretNotFoundException(SecretsManagerClientError):
|
class SecretNotFoundException(SecretsManagerClientError):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.code = 404
|
self.code = 404
|
||||||
@ -24,6 +25,17 @@ class SecretNotFoundException(SecretsManagerClientError):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Using specialised exception due to the use of a non-ASCII character
|
||||||
|
class SecretHasNoValueException(SecretsManagerClientError):
|
||||||
|
def __init__(self, version_stage):
|
||||||
|
self.code = 404
|
||||||
|
super(SecretHasNoValueException, self).__init__(
|
||||||
|
"ResourceNotFoundException",
|
||||||
|
message=u"Secrets Manager can\u2019t find the specified secret "
|
||||||
|
u"value for staging label: {}".format(version_stage)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ClientError(SecretsManagerClientError):
|
class ClientError(SecretsManagerClientError):
|
||||||
def __init__(self, message):
|
def __init__(self, message):
|
||||||
super(ClientError, self).__init__(
|
super(ClientError, self).__init__(
|
||||||
|
@ -10,8 +10,8 @@ import boto3
|
|||||||
|
|
||||||
from moto.core import BaseBackend, BaseModel
|
from moto.core import BaseBackend, BaseModel
|
||||||
from .exceptions import (
|
from .exceptions import (
|
||||||
ResourceNotFoundException,
|
|
||||||
SecretNotFoundException,
|
SecretNotFoundException,
|
||||||
|
SecretHasNoValueException,
|
||||||
InvalidParameterException,
|
InvalidParameterException,
|
||||||
ResourceExistsException,
|
ResourceExistsException,
|
||||||
InvalidRequestException,
|
InvalidRequestException,
|
||||||
@ -87,10 +87,7 @@ class SecretsManagerBackend(BaseBackend):
|
|||||||
response_data["SecretBinary"] = secret_version['secret_binary']
|
response_data["SecretBinary"] = secret_version['secret_binary']
|
||||||
|
|
||||||
if 'secret_string' not in secret_version and 'secret_binary' not in secret_version:
|
if 'secret_string' not in secret_version and 'secret_binary' not in secret_version:
|
||||||
raise ResourceNotFoundException(
|
raise SecretHasNoValueException(version_stage or u"AWSCURRENT")
|
||||||
u"Secrets Manager can\u2019t find the specified secret value for staging label: %s" %
|
|
||||||
(version_stage or u"AWSCURRENT")
|
|
||||||
)
|
|
||||||
|
|
||||||
response = json.dumps(response_data)
|
response = json.dumps(response_data)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user