From 6bd136c82fe3f074327cddebb0cb343b1ab8c7d1 Mon Sep 17 00:00:00 2001 From: The Magician Date: Mon, 1 Apr 2019 10:20:10 -0700 Subject: [PATCH] Add backend bucket signed URL key (for CDN) support (#209) Signed-off-by: Modular Magician --- .../google/gcp_compute_backend_bucket.py | 34 ++++++++++++++++ .../gcp_compute_backend_bucket_facts.py | 17 ++++++++ .../google/gcp_compute_backend_service.py | 40 +++++++++++++++++-- .../gcp_compute_backend_service_facts.py | 11 +++++ 4 files changed, 99 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/cloud/google/gcp_compute_backend_bucket.py b/lib/ansible/modules/cloud/google/gcp_compute_backend_bucket.py index 2fb7a3fac13bd2..2658387d8c7ed0 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_backend_bucket.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_backend_bucket.py @@ -55,6 +55,23 @@ description: - Cloud Storage bucket name. required: true + cdn_policy: + description: + - Cloud CDN configuration for this Backend Bucket. + required: false + version_added: 2.8 + suboptions: + signed_url_cache_max_age_sec: + description: + - Maximum number of seconds the response to a signed URL request will be considered + fresh. Defaults to 1hr (3600s). After this time period, the response will + be revalidated before being served. + - 'When serving responses to signed URL requests, Cloud CDN will internally + behave as though all responses from this backend had a "Cache-Control: public, + max-age=[TTL]" header, regardless of any existing Cache-Control header. + The actual headers served in responses will not be altered.' + required: false + default: '3600' description: description: - An optional textual description of the resource; provided by the client when @@ -108,6 +125,23 @@ - Cloud Storage bucket name. returned: success type: str +cdnPolicy: + description: + - Cloud CDN configuration for this Backend Bucket. + returned: success + type: complex + contains: + signedUrlCacheMaxAgeSec: + description: + - Maximum number of seconds the response to a signed URL request will be considered + fresh. Defaults to 1hr (3600s). After this time period, the response will + be revalidated before being served. + - 'When serving responses to signed URL requests, Cloud CDN will internally + behave as though all responses from this backend had a "Cache-Control: public, + max-age=[TTL]" header, regardless of any existing Cache-Control header. The + actual headers served in responses will not be altered.' + returned: success + type: int creationTimestamp: description: - Creation timestamp in RFC3339 text format. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_backend_bucket_facts.py b/lib/ansible/modules/cloud/google/gcp_compute_backend_bucket_facts.py index fe21d60bdc082d..aa1dd499205ea5 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_backend_bucket_facts.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_backend_bucket_facts.py @@ -70,6 +70,23 @@ - Cloud Storage bucket name. returned: success type: str + cdnPolicy: + description: + - Cloud CDN configuration for this Backend Bucket. + returned: success + type: complex + contains: + signedUrlCacheMaxAgeSec: + description: + - Maximum number of seconds the response to a signed URL request will be + considered fresh. Defaults to 1hr (3600s). After this time period, the + response will be revalidated before being served. + - 'When serving responses to signed URL requests, Cloud CDN will internally + behave as though all responses from this backend had a "Cache-Control: + public, max-age=[TTL]" header, regardless of any existing Cache-Control + header. The actual headers served in responses will not be altered.' + returned: success + type: int creationTimestamp: description: - Creation timestamp in RFC3339 text format. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_backend_service.py b/lib/ansible/modules/cloud/google/gcp_compute_backend_service.py index d8e98e71284a7e..aa8255214a2275 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_backend_service.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_backend_service.py @@ -182,6 +182,18 @@ or query_string_blacklist, not both. - "'&' and '=' will be percent encoded and not treated as delimiters." required: false + signed_url_cache_max_age_sec: + description: + - Maximum number of seconds the response to a signed URL request will be considered + fresh, defaults to 1hr (3600s). After this time period, the response will + be revalidated before being served. + - 'When serving responses to signed URL requests, Cloud CDN will internally + behave as though all responses from this backend had a "Cache-Control: public, + max-age=[TTL]" header, regardless of any existing Cache-Control header. + The actual headers served in responses will not be altered.' + required: false + default: '3600' + version_added: 2.8 connection_draining: description: - Settings for connection draining. @@ -476,6 +488,17 @@ - "'&' and '=' will be percent encoded and not treated as delimiters." returned: success type: list + signedUrlCacheMaxAgeSec: + description: + - Maximum number of seconds the response to a signed URL request will be considered + fresh, defaults to 1hr (3600s). After this time period, the response will + be revalidated before being served. + - 'When serving responses to signed URL requests, Cloud CDN will internally + behave as though all responses from this backend had a "Cache-Control: public, + max-age=[TTL]" header, regardless of any existing Cache-Control header. The + actual headers served in responses will not be altered.' + returned: success + type: int connectionDraining: description: - Settings for connection draining. @@ -646,7 +669,8 @@ def main(): query_string_blacklist=dict(type='list', elements='str'), query_string_whitelist=dict(type='list', elements='str'), ), - ) + ), + signed_url_cache_max_age_sec=dict(default=3600, type='int'), ), ), connection_draining=dict(type='dict', options=dict(draining_timeout_sec=dict(type='int'))), @@ -923,10 +947,20 @@ def __init__(self, request, module): self.request = {} def to_request(self): - return remove_nones_from_dict({u'cacheKeyPolicy': BackendServiceCachekeypolicy(self.request.get('cache_key_policy', {}), self.module).to_request()}) + return remove_nones_from_dict( + { + u'cacheKeyPolicy': BackendServiceCachekeypolicy(self.request.get('cache_key_policy', {}), self.module).to_request(), + u'signedUrlCacheMaxAgeSec': self.request.get('signed_url_cache_max_age_sec'), + } + ) def from_response(self): - return remove_nones_from_dict({u'cacheKeyPolicy': BackendServiceCachekeypolicy(self.request.get(u'cacheKeyPolicy', {}), self.module).from_response()}) + return remove_nones_from_dict( + { + u'cacheKeyPolicy': BackendServiceCachekeypolicy(self.request.get(u'cacheKeyPolicy', {}), self.module).from_response(), + u'signedUrlCacheMaxAgeSec': self.request.get(u'signedUrlCacheMaxAgeSec'), + } + ) class BackendServiceCachekeypolicy(object): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_backend_service_facts.py b/lib/ansible/modules/cloud/google/gcp_compute_backend_service_facts.py index e9bbb3e6c60507..e7339098bdfd37 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_backend_service_facts.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_backend_service_facts.py @@ -206,6 +206,17 @@ - "'&' and '=' will be percent encoded and not treated as delimiters." returned: success type: list + signedUrlCacheMaxAgeSec: + description: + - Maximum number of seconds the response to a signed URL request will be + considered fresh, defaults to 1hr (3600s). After this time period, the + response will be revalidated before being served. + - 'When serving responses to signed URL requests, Cloud CDN will internally + behave as though all responses from this backend had a "Cache-Control: + public, max-age=[TTL]" header, regardless of any existing Cache-Control + header. The actual headers served in responses will not be altered.' + returned: success + type: int connectionDraining: description: - Settings for connection draining.