How to use the moto.core.exceptions.JsonRESTError function in moto

To help you get started, we’ve selected a few moto examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github spulec / moto / moto / config / exceptions.py View on Github external
"Both Resource ID and Resource Name " "cannot be specified in the request",
        )


class InvalidLimit(JsonRESTError):
    code = 400

    def __init__(self, value):
        super(InvalidLimit, self).__init__(
            "ValidationException",
            "Value '{value}' at 'limit' failed to satisify constraint: Member"
            " must have value less than or equal to 100".format(value=value),
        )


class TooManyResourceIds(JsonRESTError):
    code = 400

    def __init__(self):
        super(TooManyResourceIds, self).__init__(
            "ValidationException",
            "The specified list had more than 20 resource ID's. "
            "It must have '20' or less items",
        )


class ResourceNotDiscoveredException(JsonRESTError):
    code = 400

    def __init__(self, type, resource):
        super(ResourceNotDiscoveredException, self).__init__(
            "ResourceNotDiscoveredException",
github spulec / moto / moto / logs / exceptions.py View on Github external
from __future__ import unicode_literals
from moto.core.exceptions import JsonRESTError


class LogsClientError(JsonRESTError):
    code = 400


class ResourceNotFoundException(LogsClientError):
    def __init__(self):
        self.code = 400
        super(ResourceNotFoundException, self).__init__(
            "ResourceNotFoundException", "The specified resource does not exist"
        )


class InvalidParameterException(LogsClientError):
    def __init__(self, msg=None):
        self.code = 400
        super(InvalidParameterException, self).__init__(
            "InvalidParameterException", msg or "A parameter is specified incorrectly."
github spulec / moto / moto / dynamodb2 / models.py View on Github external
def update_ttl(self, table_name, ttl_spec):
        table = self.tables.get(table_name)
        if table is None:
            raise JsonRESTError("ResourceNotFound", "Table not found")

        if "Enabled" not in ttl_spec or "AttributeName" not in ttl_spec:
            raise JsonRESTError(
                "InvalidParameterValue",
                "TimeToLiveSpecification does not contain Enabled and AttributeName",
            )

        if ttl_spec["Enabled"]:
            table.ttl["TimeToLiveStatus"] = "ENABLED"
        else:
            table.ttl["TimeToLiveStatus"] = "DISABLED"
        table.ttl["AttributeName"] = ttl_spec["AttributeName"]
github spulec / moto / moto / glue / exceptions.py View on Github external
from __future__ import unicode_literals
from moto.core.exceptions import JsonRESTError


class GlueClientError(JsonRESTError):
    code = 400


class AlreadyExistsException(GlueClientError):
    def __init__(self, typ):
        super(GlueClientError, self).__init__(
            "AlreadyExistsException", "%s already exists." % (typ)
        )


class DatabaseAlreadyExistsException(AlreadyExistsException):
    def __init__(self):
        super(DatabaseAlreadyExistsException, self).__init__("Database")


class TableAlreadyExistsException(AlreadyExistsException):
github spulec / moto / moto / config / exceptions.py View on Github external
)


class NoSuchConfigurationRecorderException(JsonRESTError):
    code = 400

    def __init__(self, name):
        message = "Cannot find configuration recorder with the specified name '{name}'.".format(
            name=name
        )
        super(NoSuchConfigurationRecorderException, self).__init__(
            "NoSuchConfigurationRecorderException", message
        )


class InvalidDeliveryChannelNameException(JsonRESTError):
    code = 400

    def __init__(self, name):
        message = "The delivery channel name '{name}' is not valid, blank string.".format(
            name=name
        )
        super(InvalidDeliveryChannelNameException, self).__init__(
            "InvalidDeliveryChannelNameException", message
        )


class NoSuchBucketException(JsonRESTError):
    """We are *only* validating that there is value that is not '' here."""

    code = 400
github spulec / moto / moto / config / exceptions.py View on Github external
)


class InvalidTagCharacters(JsonRESTError):
    code = 400

    def __init__(self, tag, param="tags.X.member.key"):
        message = "1 validation error detected: Value '{}' at '{}' failed to satisfy ".format(
            tag, param
        )
        message += "constraint: Member must satisfy regular expression pattern: [\\\\p{L}\\\\p{Z}\\\\p{N}_.:/=+\\\\-@]+"

        super(InvalidTagCharacters, self).__init__("ValidationException", message)


class TooManyTags(JsonRESTError):
    code = 400

    def __init__(self, tags, param="tags"):
        super(TooManyTags, self).__init__(
            "ValidationException",
            "1 validation error detected: Value '{}' at '{}' failed to satisfy "
            "constraint: Member must have length less than or equal to 50.".format(
                tags, param
            ),
        )


class InvalidResourceParameters(JsonRESTError):
    code = 400

    def __init__(self):
github spulec / moto / moto / ecs / models.py View on Github external
def delete_attributes(self, cluster_name, attributes=None):
        if cluster_name is None or cluster_name not in self.clusters:
            raise JsonRESTError(
                "ClusterNotFoundException", "Cluster not found", status=400
            )

        if attributes is None:
            raise JsonRESTError(
                "InvalidParameterException", "attributes value is required"
            )

        for attr in attributes:
            self._delete_attribute(
                cluster_name,
                attr["name"],
                attr.get("value"),
                attr.get("targetId"),
                attr.get("targetType"),
            )
github spulec / moto / moto / ssm / exceptions.py View on Github external
from __future__ import unicode_literals
from moto.core.exceptions import JsonRESTError


class InvalidFilterKey(JsonRESTError):
    code = 400

    def __init__(self, message):
        super(InvalidFilterKey, self).__init__("InvalidFilterKey", message)


class InvalidFilterOption(JsonRESTError):
    code = 400

    def __init__(self, message):
        super(InvalidFilterOption, self).__init__("InvalidFilterOption", message)


class InvalidFilterValue(JsonRESTError):
    code = 400
github spulec / moto / moto / config / exceptions.py View on Github external
)


class NoSuchDeliveryChannelException(JsonRESTError):
    code = 400

    def __init__(self, name):
        message = "Cannot find delivery channel with specified name '{name}'.".format(
            name=name
        )
        super(NoSuchDeliveryChannelException, self).__init__(
            "NoSuchDeliveryChannelException", message
        )


class NoAvailableConfigurationRecorderException(JsonRESTError):
    code = 400

    def __init__(self):
        message = "Configuration recorder is not available to put delivery channel."
        super(NoAvailableConfigurationRecorderException, self).__init__(
            "NoAvailableConfigurationRecorderException", message
        )


class NoAvailableDeliveryChannelException(JsonRESTError):
    code = 400

    def __init__(self):
        message = "Delivery channel is not available to start configuration recorder."
        super(NoAvailableDeliveryChannelException, self).__init__(
            "NoAvailableDeliveryChannelException", message
github spulec / moto / moto / ecs / models.py View on Github external
def _parse_resource_arn(resource_arn):
        match = re.match(
            "^arn:aws:ecs:(?P[^:]+):(?P[^:]+):(?P[^:]+)/(?P.*)$",
            resource_arn,
        )
        if not match:
            raise JsonRESTError(
                "InvalidParameterException", "The ARN provided is invalid."
            )
        return match.groupdict()