CloudFront: Persist origin changes made via update-distribution calls (#5736) (#5737)

This commit is contained in:
g-dx 2022-12-08 00:02:01 +00:00 committed by GitHub
parent 623be47c4d
commit 8f074b0799
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 5 deletions

View File

@ -113,6 +113,7 @@ class Origin:
def __init__(self, origin: Dict[str, Any]):
self.id = origin["Id"]
self.domain_name = origin["DomainName"]
self.origin_path = origin.get("OriginPath") or ""
self.custom_headers: List[Any] = []
self.s3_access_identity = ""
self.custom_origin = None
@ -329,8 +330,14 @@ class CloudFrontBackend(BaseBackend):
dist = self.distributions[_id]
aliases = dist_config["Aliases"]["Items"]["CNAME"]
origin = dist_config["Origins"]["Items"]["Origin"]
dist.distribution_config.config = dist_config
dist.distribution_config.aliases = aliases
dist.distribution_config.origins = (
[Origin(o) for o in origin]
if isinstance(origin, list)
else [Origin(origin)]
)
self.distributions[_id] = dist
dist.advance()
return dist, dist.location, dist.etag

View File

@ -12,7 +12,10 @@ def example_distribution_config(ref):
{
"Id": "origin1",
"DomainName": "asdf.s3.us-east-1.amazonaws.com",
"S3OriginConfig": {"OriginAccessIdentity": ""},
"OriginPath": "/example",
"S3OriginConfig": {
"OriginAccessIdentity": "origin-access-identity/cloudfront/00000000000001"
},
}
],
},

View File

@ -23,6 +23,7 @@ def test_update_distribution():
dist_config = dist["Distribution"]["DistributionConfig"]
aliases = ["alias1", "alias2"]
dist_config["Origins"]["Items"][0]["OriginPath"] = "/updated"
dist_config["Aliases"] = {"Quantity": len(aliases), "Items": aliases}
resp = client.update_distribution(
@ -64,14 +65,16 @@ def test_update_distribution():
origin = origins["Items"][0]
origin.should.have.key("Id").equals("origin1")
origin.should.have.key("DomainName").equals("asdf.s3.us-east-1.amazonaws.com")
origin.should.have.key("OriginPath").equals("")
origin.should.have.key("OriginPath").equals("/updated")
origin.should.have.key("CustomHeaders")
origin["CustomHeaders"].should.have.key("Quantity").equals(0)
origin.should.have.key("ConnectionAttempts").equals(3)
origin.should.have.key("ConnectionTimeout").equals(10)
origin.should.have.key("OriginShield").equals({"Enabled": False})
origin.should.have.key("OriginShield").equals(
{"Enabled": False, "OriginShieldRegion": "None"}
)
config.should.have.key("OriginGroups").equals({"Quantity": 0})

View File

@ -49,7 +49,7 @@ def test_create_distribution_s3_minimum():
origin = origins["Items"][0]
origin.should.have.key("Id").equals("origin1")
origin.should.have.key("DomainName").equals("asdf.s3.us-east-1.amazonaws.com")
origin.should.have.key("OriginPath").equals("")
origin.should.have.key("OriginPath").equals("/example")
origin.should.have.key("CustomHeaders")
origin["CustomHeaders"].should.have.key("Quantity").equals(0)
@ -656,7 +656,7 @@ def test_get_distribution_config():
origin = origins["Items"][0]
origin.should.have.key("Id").equals("origin1")
origin.should.have.key("DomainName").equals("asdf.s3.us-east-1.amazonaws.com")
origin.should.have.key("OriginPath").equals("")
origin.should.have.key("OriginPath").equals("/example")
origin.should.have.key("CustomHeaders")
origin["CustomHeaders"].should.have.key("Quantity").equals(0)