Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Add backend bucket signed URL key (for CDN) support
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
emilymye authored and modular-magician committed Mar 28, 2019
1 parent d1f6550 commit c501e6e
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 5 deletions.
4 changes: 4 additions & 0 deletions docs/resources/google_compute_backend_bucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Properties that can be accessed from the `google_compute_backend_bucket` resourc

* `bucket_name`: Cloud Storage bucket name.

* `cdn_policy`: Cloud CDN configuration for this Backend Bucket.

* `signedUrlCacheMaxAgeSec`: 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.

* `creation_timestamp`: Creation timestamp in RFC3339 text format.

* `description`: An optional textual description of the resource; provided by the client when the resource is created.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/google_compute_backend_buckets.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Properties that can be accessed from the `google_compute_backend_buckets` resour

See [google_compute_backend_bucket.md](google_compute_backend_bucket.md) for more detailed information
* `bucket_names`: an array of `google_compute_backend_bucket` bucket_name
* `cdn_policies`: an array of `google_compute_backend_bucket` cdn_policy
* `creation_timestamps`: an array of `google_compute_backend_bucket` creation_timestamp
* `descriptions`: an array of `google_compute_backend_bucket` description
* `enable_cdns`: an array of `google_compute_backend_bucket` enable_cdn
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/google_compute_backend_service.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Properties that can be accessed from the `google_compute_backend_service` resour

* `cache_key_policy`: The CacheKeyPolicy for this CdnPolicy.

* `signedUrlCacheMaxAgeSec`: 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.

* `connection_draining`: Settings for connection draining

* `draining_timeout_sec`: Time for which instance will be drained (not accept new connections, but still work to finish started).
Expand Down
34 changes: 34 additions & 0 deletions libraries/google/compute/property/backendbucket_cdn_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: false

# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
#
# ----------------------------------------------------------------------------
#
# This file is automatically generated by Magic Modules and manual
# changes will be clobbered when the file is regenerated.
#
# Please read more about how to change this file in README.md and
# CONTRIBUTING.md located at the root of this package.
#
# ----------------------------------------------------------------------------
module GoogleInSpec
module Compute
module Property
class BackendBucketCdnPolicy
attr_reader :signed_url_cache_max_age_sec

def initialize(args = nil, parent_identifier = nil)
return if args.nil?
@parent_identifier = parent_identifier
@signed_url_cache_max_age_sec = args['signedUrlCacheMaxAgeSec']
end

def to_s
"#{@parent_identifier} BackendBucketCdnPolicy"
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ module Property
class BackendServiceCdnPolicy
attr_reader :cache_key_policy

attr_reader :signed_url_cache_max_age_sec

def initialize(args = nil, parent_identifier = nil)
return if args.nil?
@parent_identifier = parent_identifier
@cache_key_policy = GoogleInSpec::Compute::Property::BackendServiceCdnPolicyCacheKeyPolicy.new(args['cacheKeyPolicy'], to_s)
@signed_url_cache_max_age_sec = args['signedUrlCacheMaxAgeSec']
end

def to_s
Expand Down
3 changes: 3 additions & 0 deletions libraries/google_compute_backend_bucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#
# ----------------------------------------------------------------------------
require 'gcp_backend'
require 'google/compute/property/backendbucket_cdn_policy'

# A provider to manage Compute Engine resources.
class BackendBucket < GcpResourceBase
Expand All @@ -23,6 +24,7 @@ class BackendBucket < GcpResourceBase

attr_reader :params
attr_reader :bucket_name
attr_reader :cdn_policy
attr_reader :creation_timestamp
attr_reader :description
attr_reader :enable_cdn
Expand All @@ -38,6 +40,7 @@ def initialize(params)

def parse
@bucket_name = @fetched['bucketName']
@cdn_policy = GoogleInSpec::Compute::Property::BackendBucketCdnPolicy.new(@fetched['cdnPolicy'], to_s)
@creation_timestamp = parse_time_string(@fetched['creationTimestamp'])
@description = @fetched['description']
@enable_cdn = @fetched['enableCdn']
Expand Down
2 changes: 2 additions & 0 deletions libraries/google_compute_backend_buckets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class BackendBuckets < GcpResourceBase
filter_table_config = FilterTable.create

filter_table_config.add(:bucket_names, field: :bucket_name)
filter_table_config.add(:cdn_policies, field: :cdn_policy)
filter_table_config.add(:creation_timestamps, field: :creation_timestamp)
filter_table_config.add(:descriptions, field: :description)
filter_table_config.add(:enable_cdns, field: :enable_cdn)
Expand Down Expand Up @@ -69,6 +70,7 @@ def transform(key, value)
def transformers
{
'bucketName' => ->(obj) { return :bucket_name, obj['bucketName'] },
'cdnPolicy' => ->(obj) { return :cdn_policy, GoogleInSpec::Compute::Property::BackendBucketCdnPolicy.new(obj['cdnPolicy'], to_s) },
'creationTimestamp' => ->(obj) { return :creation_timestamp, parse_time_string(obj['creationTimestamp']) },
'description' => ->(obj) { return :description, obj['description'] },
'enableCdn' => ->(obj) { return :enable_cdn, obj['enableCdn'] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
title 'Test GCP google_cloudfunctions_cloud_function resource.'

gcp_project_id = attribute(:gcp_project_id, default: 'gcp_project_id', description: 'The GCP project identifier.')
gcp_cloud_function_region = attribute(:gcp_cloud_function_region, default: 'gcp_cloud_function_region', description: 'The Cloud Function region.')
cloudfunction = attribute('cloudfunction', default: {
"name": "inspec-gcp-function",
"location": "europe-west1",
"description": "A description of the function",
"available_memory_mb": 128,
"trigger_http": true,
Expand All @@ -29,7 +29,7 @@
impact 1.0
title 'google_cloudfunctions_cloud_function resource test'

describe google_cloudfunctions_cloud_function(project: gcp_project_id, location: gcp_cloud_function_region, name: cloudfunction['name']) do
describe google_cloudfunctions_cloud_function(project: gcp_project_id, location: cloudfunction['location'], name: cloudfunction['name']) do
it { should exist }
its('description') { should eq cloudfunction['description'] }
its('available_memory_mb') { should eq cloudfunction['available_memory_mb'] }
Expand All @@ -38,7 +38,7 @@
its('environment_variables') { should include('MY_ENV_VAR' => cloudfunction['env_var_value']) }
end

describe google_cloudfunctions_cloud_function(project: gcp_project_id, location: gcp_cloud_function_region, name: 'nonexistent') do
describe google_cloudfunctions_cloud_function(project: gcp_project_id, location: cloudfunction['location'], name: 'nonexistent') do
it { should_not exist }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
title 'Test GCP google_cloudfunctions_cloud_functions resource.'

gcp_project_id = attribute(:gcp_project_id, default: 'gcp_project_id', description: 'The GCP project identifier.')
gcp_cloud_function_region = attribute(:gcp_cloud_function_region, default: 'gcp_cloud_function_region', description: 'The Cloud Function region.')
cloudfunction = attribute('cloudfunction', default: {
"name": "inspec-gcp-function",
"location": "europe-west1",
"description": "A description of the function",
"available_memory_mb": 128,
"trigger_http": true,
Expand All @@ -29,7 +29,7 @@
impact 1.0
title 'google_cloudfunctions_cloud_functions resource test'

describe google_cloudfunctions_cloud_functions(project: gcp_project_id, location: gcp_cloud_function_region) do
describe google_cloudfunctions_cloud_functions(project: gcp_project_id, location: cloudfunction['location']) do
its('descriptions') { should include cloudfunction['description'] }
its('entry_points') { should include cloudfunction['entry_point'] }
end
Expand Down

0 comments on commit c501e6e

Please sign in to comment.