Cloudfront update_distribution - apply configuration changes (#7423)

This commit is contained in:
izipris 2024-03-05 01:16:38 +02:00 committed by GitHub
parent d815421072
commit 274fdae642
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 14 deletions

View File

@ -354,20 +354,7 @@ class CloudFrontBackend(BaseBackend):
raise NoSuchDistribution
dist = self.distributions[_id]
if dist_config.get("Aliases", {}).get("Items") is not None:
aliases = dist_config["Aliases"]["Items"]["CNAME"]
dist.distribution_config.aliases = aliases
origin = dist_config["Origins"]["Items"]["Origin"]
dist.distribution_config.config = dist_config
dist.distribution_config.origins = (
[Origin(o) for o in origin]
if isinstance(origin, list)
else [Origin(origin)]
)
if dist_config.get("DefaultRootObject") is not None:
dist.distribution_config.default_root_object = dist_config[
"DefaultRootObject"
]
dist.distribution_config = DistributionConfig(dist_config)
self.distributions[_id] = dist
dist.advance()
return dist, dist.location, dist.etag

View File

@ -248,3 +248,34 @@ def test_update_default_root_object():
dist_config = client.get_distribution_config(Id=dist_id)
assert dist_config["DistributionConfig"]["DefaultRootObject"] == "index.html"
@mock_aws
def test_update_distribution_applies_changes():
client = boto3.client("cloudfront", region_name="us-east-1")
# Create standard distribution
config = scaffold.example_distribution_config(ref="ref")
dist = client.create_distribution(DistributionConfig=config)
dist_id = dist["Distribution"]["Id"]
# Assert that default 'Enabled' value is false
actual_dist_config = client.get_distribution(Id=dist_id)["Distribution"][
"DistributionConfig"
]
assert not actual_dist_config["Enabled"]
# Update 'Enabled' value to true
get_config_response = client.get_distribution_config(Id=dist_id)
actual_dist_config = get_config_response["DistributionConfig"]
etag = get_config_response["ETag"]
actual_dist_config["Enabled"] = True
client.update_distribution(
DistributionConfig=actual_dist_config, Id=dist_id, IfMatch=etag
)
# Assert that 'Enabled' value is true
actual_dist_config = client.get_distribution(Id=dist_id)["Distribution"][
"DistributionConfig"
]
assert actual_dist_config["Enabled"]