CloudFront - Add default timeouts for CustomOrigins (#6508)
This commit is contained in:
		
							parent
							
								
									7d31fe378d
								
							
						
					
					
						commit
						971568f226
					
				| @ -101,9 +101,9 @@ class CustomOriginConfig: | |||||||
|     def __init__(self, config: Dict[str, Any]): |     def __init__(self, config: Dict[str, Any]): | ||||||
|         self.http_port = config.get("HTTPPort") |         self.http_port = config.get("HTTPPort") | ||||||
|         self.https_port = config.get("HTTPSPort") |         self.https_port = config.get("HTTPSPort") | ||||||
|         self.keep_alive = config.get("OriginKeepaliveTimeout") |         self.keep_alive = config.get("OriginKeepaliveTimeout") or 5 | ||||||
|         self.protocol_policy = config.get("OriginProtocolPolicy") |         self.protocol_policy = config.get("OriginProtocolPolicy") | ||||||
|         self.read_timeout = config.get("OriginReadTimeout") |         self.read_timeout = config.get("OriginReadTimeout") or 30 | ||||||
|         self.ssl_protocols = ( |         self.ssl_protocols = ( | ||||||
|             config.get("OriginSslProtocols", {}).get("Items", {}).get("SslProtocol") |             config.get("OriginSslProtocols", {}).get("Items", {}).get("SslProtocol") | ||||||
|             or [] |             or [] | ||||||
|  | |||||||
| @ -50,9 +50,9 @@ def example_dist_custom_config(ref): | |||||||
|                     "CustomOriginConfig": { |                     "CustomOriginConfig": { | ||||||
|                         "HTTPPort": 80, |                         "HTTPPort": 80, | ||||||
|                         "HTTPSPort": 443, |                         "HTTPSPort": 443, | ||||||
|                         "OriginKeepaliveTimeout": 5, |                         "OriginKeepaliveTimeout": 10, | ||||||
|                         "OriginProtocolPolicy": "http-only", |                         "OriginProtocolPolicy": "http-only", | ||||||
|                         "OriginReadTimeout": 30, |                         "OriginReadTimeout": 15, | ||||||
|                         "OriginSslProtocols": { |                         "OriginSslProtocols": { | ||||||
|                             "Quantity": 2, |                             "Quantity": 2, | ||||||
|                             "Items": ["TLSv1", "SSLv3"], |                             "Items": ["TLSv1", "SSLv3"], | ||||||
| @ -70,3 +70,38 @@ def example_dist_custom_config(ref): | |||||||
|         "Comment": "an optional comment that's not actually optional", |         "Comment": "an optional comment that's not actually optional", | ||||||
|         "Enabled": False, |         "Enabled": False, | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def minimal_dist_custom_config(ref: str): | ||||||
|  |     return { | ||||||
|  |         "CallerReference": ref, | ||||||
|  |         "Origins": { | ||||||
|  |             "Quantity": 1, | ||||||
|  |             "Items": [ | ||||||
|  |                 { | ||||||
|  |                     "Id": "my-origin", | ||||||
|  |                     "DomainName": "example.com", | ||||||
|  |                     "CustomOriginConfig": { | ||||||
|  |                         "HTTPPort": 80, | ||||||
|  |                         "HTTPSPort": 443, | ||||||
|  |                         "OriginProtocolPolicy": "http-only", | ||||||
|  |                     }, | ||||||
|  |                 } | ||||||
|  |             ], | ||||||
|  |         }, | ||||||
|  |         "DefaultCacheBehavior": { | ||||||
|  |             "TargetOriginId": "my-origin", | ||||||
|  |             "ViewerProtocolPolicy": "redirect-to-https", | ||||||
|  |             "DefaultTTL": 86400, | ||||||
|  |             "AllowedMethods": {"Quantity": 2, "Items": ["GET", "HEAD"]}, | ||||||
|  |             "ForwardedValues": { | ||||||
|  |                 "QueryString": False, | ||||||
|  |                 "Cookies": {"Forward": "none"}, | ||||||
|  |                 "Headers": {"Quantity": 0}, | ||||||
|  |             }, | ||||||
|  |             "TrustedSigners": {"Enabled": False, "Quantity": 0}, | ||||||
|  |             "MinTTL": 0, | ||||||
|  |         }, | ||||||
|  |         "Comment": "My CloudFront distribution", | ||||||
|  |         "Enabled": True, | ||||||
|  |     } | ||||||
|  | |||||||
| @ -446,6 +446,8 @@ def test_create_distribution_custom_config(): | |||||||
| 
 | 
 | ||||||
|     assert custom_config["HTTPPort"] == 80 |     assert custom_config["HTTPPort"] == 80 | ||||||
|     assert custom_config["HTTPSPort"] == 443 |     assert custom_config["HTTPSPort"] == 443 | ||||||
|  |     assert custom_config["OriginReadTimeout"] == 15 | ||||||
|  |     assert custom_config["OriginKeepaliveTimeout"] == 10 | ||||||
|     assert custom_config["OriginProtocolPolicy"] == "http-only" |     assert custom_config["OriginProtocolPolicy"] == "http-only" | ||||||
|     assert custom_config["OriginSslProtocols"] == { |     assert custom_config["OriginSslProtocols"] == { | ||||||
|         "Items": ["TLSv1", "SSLv3"], |         "Items": ["TLSv1", "SSLv3"], | ||||||
| @ -453,6 +455,28 @@ def test_create_distribution_custom_config(): | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @mock_cloudfront | ||||||
|  | def test_create_distribution_minimal_custom_config(): | ||||||
|  |     client = boto3.client("cloudfront", region_name="us-west-1") | ||||||
|  |     config = scaffold.minimal_dist_custom_config("ref") | ||||||
|  | 
 | ||||||
|  |     dist = client.create_distribution(DistributionConfig=config)["Distribution"] | ||||||
|  |     dist_config = dist["DistributionConfig"] | ||||||
|  |     assert len(dist_config["Origins"]["Items"]) == 1 | ||||||
|  |     custom_config = dist_config["Origins"]["Items"][0]["CustomOriginConfig"] | ||||||
|  | 
 | ||||||
|  |     assert custom_config["HTTPPort"] == 80 | ||||||
|  |     assert custom_config["HTTPSPort"] == 443 | ||||||
|  |     assert custom_config["OriginReadTimeout"] == 30 | ||||||
|  |     assert custom_config["OriginKeepaliveTimeout"] == 5 | ||||||
|  |     assert custom_config["OriginProtocolPolicy"] == "http-only" | ||||||
|  | 
 | ||||||
|  |     dist = client.get_distribution(Id=dist["Id"])["Distribution"] | ||||||
|  |     dist_config = dist["DistributionConfig"] | ||||||
|  |     get_custom_config = dist_config["Origins"]["Items"][0]["CustomOriginConfig"] | ||||||
|  |     assert custom_config == get_custom_config | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| @mock_cloudfront | @mock_cloudfront | ||||||
| def test_list_distributions_without_any(): | def test_list_distributions_without_any(): | ||||||
|     client = boto3.client("cloudfront", region_name="us-east-1") |     client = boto3.client("cloudfront", region_name="us-east-1") | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user