1from jinja2 import Template
2from werkzeug.exceptions import BadRequest
3
4
5class RDSClientError(BadRequest):
6    def __init__(self, code, message):
7        super(RDSClientError, self).__init__()
8        template = Template(
9            """
10        <RDSClientError>
11            <Error>
12              <Code>{{ code }}</Code>
13              <Message>{{ message }}</Message>
14              <Type>Sender</Type>
15            </Error>
16            <RequestId>6876f774-7273-11e4-85dc-39e55ca848d1</RequestId>
17        </RDSClientError>"""
18        )
19        self.description = template.render(code=code, message=message)
20
21
22class DBInstanceNotFoundError(RDSClientError):
23    def __init__(self, database_identifier):
24        super(DBInstanceNotFoundError, self).__init__(
25            "DBInstanceNotFound",
26            "DBInstance {0} not found.".format(database_identifier),
27        )
28
29
30class DBSnapshotNotFoundError(RDSClientError):
31    def __init__(self, snapshot_identifier):
32        super(DBSnapshotNotFoundError, self).__init__(
33            "DBSnapshotNotFound",
34            "DBSnapshot {} not found.".format(snapshot_identifier),
35        )
36
37
38class DBSecurityGroupNotFoundError(RDSClientError):
39    def __init__(self, security_group_name):
40        super(DBSecurityGroupNotFoundError, self).__init__(
41            "DBSecurityGroupNotFound",
42            "Security Group {0} not found.".format(security_group_name),
43        )
44
45
46class DBSubnetGroupNotFoundError(RDSClientError):
47    def __init__(self, subnet_group_name):
48        super(DBSubnetGroupNotFoundError, self).__init__(
49            "DBSubnetGroupNotFound",
50            "Subnet Group {0} not found.".format(subnet_group_name),
51        )
52
53
54class DBParameterGroupNotFoundError(RDSClientError):
55    def __init__(self, db_parameter_group_name):
56        super(DBParameterGroupNotFoundError, self).__init__(
57            "DBParameterGroupNotFound",
58            "DB Parameter Group {0} not found.".format(db_parameter_group_name),
59        )
60
61
62class OptionGroupNotFoundFaultError(RDSClientError):
63    def __init__(self, option_group_name):
64        super(OptionGroupNotFoundFaultError, self).__init__(
65            "OptionGroupNotFoundFault",
66            "Specified OptionGroupName: {0} not found.".format(option_group_name),
67        )
68
69
70class InvalidDBClusterStateFaultError(RDSClientError):
71    def __init__(self, database_identifier):
72        super(InvalidDBClusterStateFaultError, self).__init__(
73            "InvalidDBClusterStateFault",
74            "Invalid DB type, when trying to perform StopDBInstance on {0}e. See AWS RDS documentation on rds.stop_db_instance".format(
75                database_identifier
76            ),
77        )
78
79
80class InvalidDBInstanceStateError(RDSClientError):
81    def __init__(self, database_identifier, istate):
82        estate = (
83            "in available state"
84            if istate == "stop"
85            else "stopped, it cannot be started"
86        )
87        super(InvalidDBInstanceStateError, self).__init__(
88            "InvalidDBInstanceState",
89            "Instance {} is not {}.".format(database_identifier, estate),
90        )
91
92
93class SnapshotQuotaExceededError(RDSClientError):
94    def __init__(self):
95        super(SnapshotQuotaExceededError, self).__init__(
96            "SnapshotQuotaExceeded",
97            "The request cannot be processed because it would exceed the maximum number of snapshots.",
98        )
99
100
101class DBSnapshotAlreadyExistsError(RDSClientError):
102    def __init__(self, database_snapshot_identifier):
103        super(DBSnapshotAlreadyExistsError, self).__init__(
104            "DBSnapshotAlreadyExists",
105            "Cannot create the snapshot because a snapshot with the identifier {} already exists.".format(
106                database_snapshot_identifier
107            ),
108        )
109
110
111class InvalidParameterValue(RDSClientError):
112    def __init__(self, message):
113        super(InvalidParameterValue, self).__init__("InvalidParameterValue", message)
114
115
116class InvalidParameterCombination(RDSClientError):
117    def __init__(self, message):
118        super(InvalidParameterCombination, self).__init__(
119            "InvalidParameterCombination", message
120        )
121
122
123class InvalidDBClusterStateFault(RDSClientError):
124    def __init__(self, message):
125        super().__init__("InvalidDBClusterStateFault", message)
126
127
128class DBClusterNotFoundError(RDSClientError):
129    def __init__(self, cluster_identifier):
130        super(DBClusterNotFoundError, self).__init__(
131            "DBClusterNotFoundFault",
132            "DBCluster {} not found.".format(cluster_identifier),
133        )
134