File: exceptions.py

package info (click to toggle)
python-moto 5.1.18-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 116,520 kB
  • sloc: python: 636,725; javascript: 181; makefile: 39; sh: 3
file content (116 lines) | stat: -rw-r--r-- 3,371 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from typing import Any

from moto.core.exceptions import JsonRESTError


class LambdaClientError(JsonRESTError):
    def __init__(self, error: str, message: str):
        super().__init__(error, message)


class CrossAccountNotAllowed(LambdaClientError):
    def __init__(self) -> None:
        super().__init__(
            "AccessDeniedException", "Cross-account pass role is not allowed."
        )


class FunctionAlreadyExists(LambdaClientError):
    code = 409

    def __init__(self, function_name: str) -> None:
        message = f"Function already exist: {function_name}"
        super().__init__("ResourceConflictException", message)


class InvalidParameterValueException(LambdaClientError):
    def __init__(self, message: str):
        super().__init__("InvalidParameterValueException", message)


class InvalidRoleFormat(LambdaClientError):
    pattern = r"arn:(aws[a-zA-Z-]*)?:iam::(\d{12}):role/?[a-zA-Z_0-9+=,.@\-_/]+"

    def __init__(self, role: str):
        message = f"1 validation error detected: Value '{role}' at 'role' failed to satisfy constraint: Member must satisfy regular expression pattern: {InvalidRoleFormat.pattern}"
        super().__init__("ValidationException", message)


class PreconditionFailedException(JsonRESTError):
    code = 412

    def __init__(self, message: str):
        super().__init__("PreconditionFailedException", message)


class ConflictException(LambdaClientError):
    code = 409

    def __init__(self, message: str):
        super().__init__("ConflictException", message)


class UnknownAliasException(LambdaClientError):
    code = 404

    def __init__(self, arn: str):
        super().__init__("ResourceNotFoundException", f"Cannot find alias arn: {arn}")


class UnknownFunctionException(LambdaClientError):
    code = 404

    def __init__(self, arn: str):
        super().__init__("ResourceNotFoundException", f"Function not found: {arn}")


class GenericResourcNotFound(LambdaClientError):
    code = 404

    def __init__(self) -> None:
        super().__init__(
            "ResourceNotFoundException", "The resource you requested does not exist."
        )


class UnknownLayerException(LambdaClientError):
    code = 404

    def __init__(self) -> None:
        super().__init__("ResourceNotFoundException", "Cannot find layer")


class UnknownLayerVersionException(LambdaClientError):
    code = 404

    def __init__(self, arns: Any) -> None:
        super().__init__(
            "ResourceNotFoundException",
            f"One or more LayerVersion does not exist {arns}",
        )


class UnknownPolicyException(LambdaClientError):
    code = 404

    def __init__(self) -> None:
        super().__init__(
            "ResourceNotFoundException",
            "No policy is associated with the given resource.",
        )


class UnknownEventConfig(LambdaClientError):
    code = 404

    def __init__(self, arn: str) -> None:
        super().__init__(
            "ResourceNotFoundException",
            f"The function {arn} doesn't have an EventInvokeConfig",
        )


class ValidationException(LambdaClientError):
    def __init__(self, value: str, property_name: str, specific_message: str):
        message = f"1 validation error detected: Value '{value}' at '{property_name}' failed to satisfy constraint: {specific_message}"
        super().__init__("ValidationException", message)