How to use the moto.core.exceptions.RESTError 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 / sqs / models.py View on Github external
raise RESTError(
                "InvalidParameterValue",
                "Redrive policy does not contain deadLetterTargetArn",
            )
        if "maxReceiveCount" not in self.redrive_policy:
            raise RESTError(
                "InvalidParameterValue",
                "Redrive policy does not contain maxReceiveCount",
            )

        for queue in sqs_backends[self.region].queues.values():
            if queue.queue_arn == self.redrive_policy["deadLetterTargetArn"]:
                self.dead_letter_queue = queue

                if self.fifo_queue and not queue.fifo_queue:
                    raise RESTError(
                        "InvalidParameterCombination",
                        "Fifo queues cannot use non fifo dead letter queues",
                    )
                break
        else:
            raise RESTError(
                "AWS.SimpleQueueService.NonExistentQueue",
                "Could not find DLQ for {0}".format(
                    self.redrive_policy["deadLetterTargetArn"]
                ),
github spulec / moto / moto / ec2 / exceptions.py View on Github external
from __future__ import unicode_literals
from moto.core.exceptions import RESTError


class EC2ClientError(RESTError):
    code = 400


class DependencyViolationError(EC2ClientError):
    def __init__(self, message):
        super(DependencyViolationError, self).__init__("DependencyViolation", message)


class MissingParameterError(EC2ClientError):
    def __init__(self, parameter):
        super(MissingParameterError, self).__init__(
            "MissingParameter",
            "The request must contain the parameter {0}".format(parameter),
        )
github spulec / moto / moto / iam / exceptions.py View on Github external
from __future__ import unicode_literals
from moto.core.exceptions import RESTError


class IAMNotFoundException(RESTError):
    code = 404

    def __init__(self, message):
        super(IAMNotFoundException, self).__init__("NoSuchEntity", message)


class IAMConflictException(RESTError):
    code = 409

    def __init__(self, code="Conflict", message=""):
        super(IAMConflictException, self).__init__(code, message)


class IAMReportNotPresentException(RESTError):
    code = 410

    def __init__(self, message):
        super(IAMReportNotPresentException, self).__init__("ReportNotPresent", message)


class IAMLimitExceededException(RESTError):
    code = 400
github spulec / moto / moto / sns / exceptions.py View on Github external
def __init__(self, message):
        super(InvalidParameterValue, self).__init__("InvalidParameterValue", message)


class TagLimitExceededError(RESTError):
    code = 400

    def __init__(self):
        super(TagLimitExceededError, self).__init__(
            "TagLimitExceeded",
            "Could not complete request: tag quota of per resource exceeded",
        )


class InternalError(RESTError):
    code = 500

    def __init__(self, message):
        super(InternalError, self).__init__("InternalFailure", message)
github spulec / moto / moto / iam / exceptions.py View on Github external
code = 400

    def __init__(self, message):
        super(IAMLimitExceededException, self).__init__("LimitExceeded", message)


class MalformedCertificate(RESTError):
    code = 400

    def __init__(self, cert):
        super(MalformedCertificate, self).__init__(
            "MalformedCertificate", "Certificate {cert} is malformed".format(cert=cert)
        )


class MalformedPolicyDocument(RESTError):
    code = 400

    def __init__(self, message=""):
        super(MalformedPolicyDocument, self).__init__(
            "MalformedPolicyDocument", message
        )


class DuplicateTags(RESTError):
    code = 400

    def __init__(self):
        super(DuplicateTags, self).__init__(
            "InvalidInput",
            "Duplicate tag keys found. Please note that Tag keys are case insensitive.",
        )
github spulec / moto / moto / awslambda / models.py View on Github external
def create_function(self, spec):
        function_name = spec.get("FunctionName", None)
        if function_name is None:
            raise RESTError("InvalidParameterValueException", "Missing FunctionName")

        fn = LambdaFunction(spec, self.region_name, version="$LATEST")

        self._lambdas.put_function(fn)

        if spec.get("Publish"):
            ver = self.publish_function(function_name)
            fn.version = ver.version
        return fn
github spulec / moto / moto / sqs / exceptions.py View on Github external
"There should be at least one SendMessageBatchRequestEntry in the request.",
        )


class InvalidBatchEntryId(RESTError):
    code = 400

    def __init__(self):
        super(InvalidBatchEntryId, self).__init__(
            "InvalidBatchEntryId",
            "A batch entry id can only contain alphanumeric characters, "
            "hyphens and underscores. It can be at most 80 letters long.",
        )


class BatchRequestTooLong(RESTError):
    code = 400

    def __init__(self, length):
        super(BatchRequestTooLong, self).__init__(
            "BatchRequestTooLong",
            "Batch requests cannot be longer than 262144 bytes. "
            "You have sent {} bytes.".format(length),
        )


class BatchEntryIdsNotDistinct(RESTError):
    code = 400

    def __init__(self, entry_id):
        super(BatchEntryIdsNotDistinct, self).__init__(
            "BatchEntryIdsNotDistinct", "Id {} repeated.".format(entry_id)
github spulec / moto / moto / sqs / models.py View on Github external
"InvalidParameterValue",
                "Redrive policy does not contain maxReceiveCount",
            )

        for queue in sqs_backends[self.region].queues.values():
            if queue.queue_arn == self.redrive_policy["deadLetterTargetArn"]:
                self.dead_letter_queue = queue

                if self.fifo_queue and not queue.fifo_queue:
                    raise RESTError(
                        "InvalidParameterCombination",
                        "Fifo queues cannot use non fifo dead letter queues",
                    )
                break
        else:
            raise RESTError(
                "AWS.SimpleQueueService.NonExistentQueue",
                "Could not find DLQ for {0}".format(
                    self.redrive_policy["deadLetterTargetArn"]
                ),
github spulec / moto / moto / organizations / models.py View on Github external
def describe_policy(self, **kwargs):
        if re.compile(utils.SCP_ID_REGEX).match(kwargs["PolicyId"]):
            policy = next(
                (p for p in self.policies if p.id == kwargs["PolicyId"]), None
            )
            if policy is None:
                raise RESTError(
                    "PolicyNotFoundException",
                    "You specified a policy that doesn't exist.",
                )
        else:
            raise RESTError("InvalidInputException", "You specified an invalid value.")
        return policy.describe()
github spulec / moto / moto / sqs / exceptions.py View on Github external
"BatchEntryIdsNotDistinct", "Id {} repeated.".format(entry_id)
        )


class TooManyEntriesInBatchRequest(RESTError):
    code = 400

    def __init__(self, number):
        super(TooManyEntriesInBatchRequest, self).__init__(
            "TooManyEntriesInBatchRequest",
            "Maximum number of entries per request are 10. "
            "You have sent {}.".format(number),
        )


class InvalidAttributeName(RESTError):
    code = 400

    def __init__(self, attribute_name):
        super(InvalidAttributeName, self).__init__(
            "InvalidAttributeName", "Unknown Attribute {}.".format(attribute_name)
        )