feat(CloudFront): Include missing fields (#5659)

This commit is contained in:
Pepe Fagoaga 2022-11-12 00:29:44 +01:00 committed by GitHub
parent e7850246ee
commit 4b946ce208
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 85 additions and 5 deletions

View File

@ -73,17 +73,20 @@ class DefaultCacheBehaviour:
self.compress = config.get("Compress", "true").lower() == "true"
self.lambda_function_associations: List[Any] = []
self.function_associations: List[Any] = []
self.field_level_encryption_id = ""
self.field_level_encryption_id = config.get("FieldLevelEncryptionId") or ""
self.forwarded_values = ForwardedValues(config.get("ForwardedValues", {}))
self.min_ttl = config.get("MinTTL") or 0
self.default_ttl = config.get("DefaultTTL") or 0
self.max_ttl = config.get("MaxTTL") or 0
self.realtime_log_config_arn = config.get("RealtimeLogConfigArn") or ""
class Logging:
def __init__(self) -> None:
self.enabled = False
self.include_cookies = False
def __init__(self, config: Dict[str, Any]) -> None:
self.enabled = config.get("Enabled") or False
self.include_cookies = config.get("IncludeCookies") or False
self.bucket = config.get("Bucket") or ""
self.prefix = config.get("Prefix") or ""
class ViewerCertificate:
@ -149,7 +152,7 @@ class DistributionConfig:
)
self.cache_behaviors: List[Any] = []
self.custom_error_responses: List[Any] = []
self.logging = Logging()
self.logging = Logging(config.get("Logging") or {})
self.enabled = config.get("Enabled") or False
self.viewer_certificate = ViewerCertificate()
self.geo_restriction = GeoRestrictions(config.get("Restrictions") or {})
@ -169,6 +172,7 @@ class DistributionConfig:
self.http_version = config.get("HttpVersion", "http2")
self.is_ipv6_enabled = config.get("IsIPV6Enabled", "true").lower() == "true"
self.default_root_object = config.get("DefaultRootObject") or ""
self.web_acl_id = config.get("WebACLId") or ""
class Distribution(BaseModel, ManagedState):

View File

@ -125,6 +125,82 @@ def test_create_distribution_s3_minimum():
restriction.should.have.key("RestrictionType").equals("none")
restriction.should.have.key("Quantity").equals(0)
config.should.have.key("WebACLId")
config.should.have.key("WebACLId").equals("")
@mock_cloudfront
def test_create_distribution_with_logging():
client = boto3.client("cloudfront", region_name="us-west-1")
config = scaffold.example_distribution_config("ref")
config["Logging"] = {
"Enabled": True,
"IncludeCookies": True,
"Bucket": "logging-bucket",
"Prefix": "logging-bucket",
}
resp = client.create_distribution(DistributionConfig=config)
resp.should.have.key("Distribution")
distribution = resp["Distribution"]
distribution.should.have.key("DistributionConfig")
config = distribution["DistributionConfig"]
config.should.have.key("Logging")
logging = config["Logging"]
logging.should.have.key("Enabled").equals(True)
logging.should.have.key("IncludeCookies").equals(True)
logging.should.have.key("Bucket").equals("logging-bucket")
logging.should.have.key("Prefix").equals("logging-bucket")
@mock_cloudfront
def test_create_distribution_with_web_acl():
client = boto3.client("cloudfront", region_name="us-west-1")
config = scaffold.example_distribution_config("ref")
config["WebACLId"] = "test-web-acl"
resp = client.create_distribution(DistributionConfig=config)
resp.should.have.key("Distribution")
distribution = resp["Distribution"]
distribution.should.have.key("DistributionConfig")
config = distribution["DistributionConfig"]
config.should.have.key("WebACLId")
config.should.have.key("WebACLId").equals("test-web-acl")
@mock_cloudfront
def test_create_distribution_with_field_level_encryption_and_real_time_log_config_arn():
client = boto3.client("cloudfront", region_name="us-west-1")
config = scaffold.example_distribution_config("ref")
real_time_log_config_arn = f"arn:aws:cloudfront::{ACCOUNT_ID}:realtime-log-config/ExampleNameForRealtimeLogConfig"
config["DefaultCacheBehavior"]["RealtimeLogConfigArn"] = real_time_log_config_arn
config["DefaultCacheBehavior"]["FieldLevelEncryptionId"] = "K3D5EWEUDCCXON"
resp = client.create_distribution(DistributionConfig=config)
resp.should.have.key("Distribution")
distribution = resp["Distribution"]
distribution.should.have.key("DistributionConfig")
config = distribution["DistributionConfig"]
config.should.have.key("DefaultCacheBehavior")
default_cache = config["DefaultCacheBehavior"]
default_cache.should.have.key("FieldLevelEncryptionId")
default_cache.should.have.key("FieldLevelEncryptionId").equals("K3D5EWEUDCCXON")
default_cache.should.have.key("RealtimeLogConfigArn")
default_cache.should.have.key("RealtimeLogConfigArn").equals(
real_time_log_config_arn
)
@mock_cloudfront
def test_create_distribution_with_georestriction():