CloudFront: Bug distribution with tags (#5467)

This commit is contained in:
eloymg 2022-09-14 12:08:26 +02:00 committed by GitHub
parent 2c2b1c76fa
commit 62033d0a42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View File

@ -613,7 +613,7 @@
- [ ] create_cache_policy
- [ ] create_cloud_front_origin_access_identity
- [X] create_distribution
- [ ] create_distribution_with_tags
- [X] create_distribution_with_tags
- [ ] create_field_level_encryption_config
- [ ] create_field_level_encryption_profile
- [ ] create_function
@ -6465,4 +6465,4 @@
- workspaces
- workspaces-web
- xray
</details>
</details>

View File

@ -41,6 +41,8 @@ class CloudFrontResponse(BaseResponse):
if "DistributionConfigWithTags" in params:
config = params.get("DistributionConfigWithTags")
tags = (config.get("Tags", {}).get("Items") or {}).get("Tag", [])
if not isinstance(tags, list):
tags = [tags]
else:
config = params
tags = []

View File

@ -19,3 +19,19 @@ def test_create_distribution_with_tags():
resp["Tags"].should.have.key("Items").length_of(2)
resp["Tags"]["Items"].should.contain({"Key": "k1", "Value": "v1"})
resp["Tags"]["Items"].should.contain({"Key": "k2", "Value": "v2"})
@mock_cloudfront
def test_create_distribution_with_tags_only_one_tag():
client = boto3.client("cloudfront", region_name="us-west-1")
config = scaffold.example_distribution_config("ref")
tags = {"Items": [{"Key": "k1", "Value": "v1"}]}
config = {"DistributionConfig": config, "Tags": tags}
resp = client.create_distribution_with_tags(DistributionConfigWithTags=config)
resp.should.have.key("Distribution")
resp = client.list_tags_for_resource(Resource=resp["Distribution"]["ARN"])
resp.should.have.key("Tags")
resp["Tags"].should.have.key("Items").length_of(1)
resp["Tags"]["Items"].should.contain({"Key": "k1", "Value": "v1"})