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 (194 lines) | stat: -rw-r--r-- 5,920 bytes parent folder | download
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
from typing import Any, Optional

from moto.core.exceptions import ServiceException


class ELBClientError(ServiceException):
    pass


class DuplicateTagKeysError(ELBClientError):
    def __init__(self, cidr: Any):
        super().__init__(
            "DuplicateTagKeys", f"Tag key was specified more than once: {cidr}"
        )


class LoadBalancerNotFoundError(ELBClientError):
    code = "LoadBalancerNotFound"
    message = "The specified load balancer does not exist."


class ListenerNotFoundError(ELBClientError):
    def __init__(self) -> None:
        super().__init__("ListenerNotFound", "The specified listener does not exist.")


class SubnetNotFoundError(ELBClientError):
    def __init__(self) -> None:
        super().__init__("SubnetNotFound", "The specified subnet does not exist.")


class TargetGroupNotFoundError(ELBClientError):
    def __init__(self) -> None:
        super().__init__("TargetGroupNotFound", "One or more target groups not found")


class TooManyTagsError(ELBClientError):
    code = "TooManyTags"
    message = "The quota for the number of tags that can be assigned to a load balancer has been reached"


class TooManyCertificatesError(ELBClientError):
    code = "TooManyCertificates"
    message = "You've reached the limit on the number of certificates per load balancer"


class BadHealthCheckDefinition(ELBClientError):
    code = "ValidationError"
    message = "HealthCheck Target must begin with one of HTTP, TCP, HTTPS, SSL"


class DuplicateListenerError(ELBClientError):
    code = "DuplicateListener"
    message = "A listener with the specified port already exists."


class DuplicateLoadBalancerName(ELBClientError):
    code = "DuplicateLoadBalancerName"
    message = "A load balancer with the specified name already exists."


class DuplicateTargetGroupName(ELBClientError):
    code = "DuplicateTargetGroupName"
    message = "A target group with the specified name already exists."


class InvalidTargetError(ELBClientError):
    code = "InvalidTarget"
    message = "The specified target does not exist or is not in the same VPC as the target group."


class TargetNotRunning(ELBClientError):
    def __init__(self, instance_id: str) -> None:
        super().__init__(
            "InvalidTarget",
            f"The following targets are not in a running state and cannot be registered: '{instance_id}'",
        )


class EmptyListenersError(ELBClientError):
    def __init__(self) -> None:
        super().__init__("ValidationError", "Listeners cannot be empty")


class PriorityInUseError(ELBClientError):
    def __init__(self) -> None:
        super().__init__("PriorityInUse", "The specified priority is in use.")


class InvalidConditionFieldError(ELBClientError):
    VALID_FIELDS = [
        "path-pattern",
        "host-header",
        "http-header",
        "http-request-method",
        "query-string",
        "source-ip",
    ]

    def __init__(self, invalid_name: str):
        valid = ",".join(self.VALID_FIELDS)
        super().__init__(
            "ValidationError",
            f"Condition field '{invalid_name}' must be one of '[{valid}]'",
        )


class InvalidConditionValueError(ELBClientError):
    code = "ValidationError"


class InvalidActionTypeError(ELBClientError):
    def __init__(self, invalid_name: Any, index: int):
        super().__init__(
            "ValidationError",
            f"1 validation error detected: Value '{invalid_name}' at 'actions.{index}.member.type' failed to satisfy constraint: Member must satisfy enum value set: [forward, redirect, fixed-response]",
        )


class ActionTargetGroupNotFoundError(ELBClientError):
    def __init__(self, arn: str):
        super().__init__("TargetGroupNotFound", f"Target group '{arn}' not found")


class ListenerOrBalancerMissingError(ELBClientError):
    def __init__(self) -> None:
        super().__init__(
            "ValidationError",
            "You must specify either listener ARNs or a load balancer ARN",
        )


class InvalidDescribeRulesRequest(ELBClientError):
    code = "ValidationError"


class ResourceInUseError(ELBClientError):
    def __init__(self, msg: str = "A specified resource is in use"):
        super().__init__("ResourceInUse", msg)


class RuleNotFoundError(ELBClientError):
    def __init__(self, msg: Optional[str] = None):
        msg = msg or "The specified rule does not exist."
        super().__init__("RuleNotFound", msg)


class DuplicatePriorityError(ELBClientError):
    def __init__(self, invalid_value: str):
        super().__init__(
            "ValidationError", f"Priority '{invalid_value}' was provided multiple times"
        )


class InvalidTargetGroupNameError(ELBClientError):
    code = "ValidationError"


class InvalidModifyRuleArgumentsError(ELBClientError):
    def __init__(self) -> None:
        super().__init__(
            "ValidationError", "Either conditions or actions must be specified"
        )


class InvalidStatusCodeActionTypeError(ELBClientError):
    code = "ValidationError"


class InvalidLoadBalancerActionException(ELBClientError):
    code = "InvalidLoadBalancerAction"


class ValidationError(ELBClientError):
    code = "ValidationError"


class InvalidConfigurationRequest(ELBClientError):
    code = "InvalidConfigurationRequest"


class InvalidProtocol(ELBClientError):
    def __init__(self, protocol: str, valid_protocols: list[str]):
        msg = f"Listener protocol '{protocol}' must be one of '{', '.join(valid_protocols)}'"
        super().__init__("ValidationError", msg)


class InvalidProtocolValue(ELBClientError):
    def __init__(self, protocol: str, valid_protocols: list[str]):
        msg = (
            f"1 validation error detected: Value '{protocol}' at 'protocol' failed to satisfy constraint: "
            f"Member must satisfy enum value set: [{', '.join(valid_protocols)}]"
        )
        super().__init__("ValidationError", msg)