Skip to content

Commit

Permalink
RDS: add enable_http_endpoint attribute (#5470)
Browse files Browse the repository at this point in the history
  • Loading branch information
marshall7m authored Sep 19, 2022
1 parent 03a43a9 commit b0e7814
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
27 changes: 26 additions & 1 deletion moto/rds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,31 @@ def __init__(self, **kwargs):
self.enabled_cloudwatch_logs_exports = (
kwargs.get("enable_cloudwatch_logs_exports") or []
)
self.enable_http_endpoint = False
# instead of raising an error on aws rds create-db-cluster commands with
# incompatible configurations with enable_http_endpoint
# (e.g. engine_mode is not set to "serverless"), the API
# automatically sets the enable_http_endpoint parameter to False
if kwargs.get("enable_http_endpoint"):
if self.engine_mode == "serverless":
if self.engine == "aurora-mysql" and self.engine_version in [
"5.6.10a",
"5.6.1",
"2.07.1",
"5.7.2",
]:
self.enable_http_endpoint = kwargs.get(
"enable_http_endpoint", False
)
elif self.engine == "aurora-postgresql" and self.engine_version in [
"10.12",
"10.14",
"10.18",
"11.13",
]:
self.enable_http_endpoint = kwargs.get(
"enable_http_endpoint", False
)

@property
def db_cluster_arn(self):
Expand Down Expand Up @@ -170,7 +195,7 @@ def to_xml(self):
<IAMDatabaseAuthenticationEnabled>false</IAMDatabaseAuthenticationEnabled>
<EngineMode>{{ cluster.engine_mode }}</EngineMode>
<DeletionProtection>{{ 'true' if cluster.deletion_protection else 'false' }}</DeletionProtection>
<HttpEndpointEnabled>false</HttpEndpointEnabled>
<HttpEndpointEnabled>{{ cluster.enable_http_endpoint }}</HttpEndpointEnabled>
<CopyTagsToSnapshot>{{ cluster.copy_tags_to_snapshot }}</CopyTagsToSnapshot>
<CrossAccountClone>false</CrossAccountClone>
<DomainMemberships></DomainMemberships>
Expand Down
1 change: 1 addition & 0 deletions moto/rds/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def _get_db_cluster_kwargs(self):
"parameter_group": self._get_param("DBClusterParameterGroup"),
"region": self.region,
"db_cluster_instance_class": self._get_param("DBClusterInstanceClass"),
"enable_http_endpoint": self._get_param("EnableHttpEndpoint"),
"copy_tags_to_snapshot": self._get_param("CopyTagsToSnapshot"),
"tags": self.unpack_complex_list_params("Tags.Tag", ("Key", "Value")),
}
Expand Down
36 changes: 36 additions & 0 deletions tests/test_rds/test_rds_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,3 +716,39 @@ def test_add_tags_to_cluster_snapshot():

tags = conn.list_tags_for_resource(ResourceName=snapshot_arn)["TagList"]
tags.should.equal([{"Key": "k2", "Value": "v2"}])


@mock_rds
def test_create_db_cluster_with_enable_http_endpoint_valid():
client = boto3.client("rds", region_name="eu-north-1")

resp = client.create_db_cluster(
DBClusterIdentifier="cluster-id",
DatabaseName="users",
Engine="aurora-mysql",
EngineMode="serverless",
EngineVersion="5.6.10a",
MasterUsername="root",
MasterUserPassword="hunter2_",
EnableHttpEndpoint=True,
)
cluster = resp["DBCluster"]
cluster.should.have.key("HttpEndpointEnabled").equal(True)


@mock_rds
def test_create_db_cluster_with_enable_http_endpoint_invalid():
client = boto3.client("rds", region_name="eu-north-1")

resp = client.create_db_cluster(
DBClusterIdentifier="cluster-id",
DatabaseName="users",
Engine="aurora-mysql",
EngineMode="serverless",
EngineVersion="5.7.0",
MasterUsername="root",
MasterUserPassword="hunter2_",
EnableHttpEndpoint=True,
)
cluster = resp["DBCluster"]
cluster.should.have.key("HttpEndpointEnabled").equal(False)

0 comments on commit b0e7814

Please sign in to comment.