class Cumulus::CloudFront::CacheBehaviorConfig
Public: An object representing configuration for a distribution cache behavior
Attributes
allow_blank_referer[R]
allowed_methods[R]
cached_methods[R]
compress[R]
default[R]
default_ttl[R]
forward_headers[R]
forward_query_strings[R]
max_ttl[R]
min_ttl[R]
path_pattern[R]
referer_checks[R]
referer_whitelist[R]
smooth_streaming[R]
target_origin_id[R]
trusted_signers[R]
viewer_protocol_policy[R]
Public Class Methods
new(json = nil, default = false)
click to toggle source
Public: Constructor
json - a hash containing the JSON configuration for the distribution cache behavior default - indicates if the cache configuration is the default config (ignore path_pattern
if so)
# File lib/cloudfront/models/CacheBehaviorConfig.rb, line 34 def initialize(json = nil, default = false) if !json.nil? @default = default @path_pattern = json["path-pattern"] if !default @target_origin_id = json["target-origin-id"] @forward_query_strings = json["forward-query-strings"] @forwarded_cookies = json["forwarded-cookies"] @forwarded_cookies_whitelist = json["forwarded-cookies-whitelist"] || [] @forward_headers = json["forward-headers"] || [] @trusted_signers = json["trusted-signers"] || [] @viewer_protocol_policy = json["viewer-protocol-policy"] @min_ttl = json["min-ttl"] @max_ttl = json["max-ttl"] @default_ttl = json["default-ttl"] @smooth_streaming = json["smooth-streaming"] @allowed_methods = json["allowed-methods"] || [] @cached_methods = json["cached-methods"] || [] @compress = json["compress"] || false end end
Public Instance Methods
diff(aws)
click to toggle source
Public: Produce an array of differences between this local configuration and the configuration in AWS
aws - the AWS resource
Returns an array of the CacheBehaviorDiffs that were found
# File lib/cloudfront/models/CacheBehaviorConfig.rb, line 154 def diff(aws) diffs = [] if !default and @path_pattern != aws.path_pattern diffs << CacheBehaviorDiff.new(CacheBehaviorChange::PATH, aws, self) end if @target_origin_id != aws.target_origin_id diffs << CacheBehaviorDiff.new(CacheBehaviorChange::TARGET, aws, self) end if @forward_query_strings != aws.forwarded_values.query_string diffs << CacheBehaviorDiff.new(CacheBehaviorChange::QUERY, aws, self) end if @forwarded_cookies != aws.forwarded_values.cookies.forward diffs << CacheBehaviorDiff.new(CacheBehaviorChange::COOKIES, aws, self) end aws_whitelist_cookies = if aws.forwarded_values.cookies.whitelisted_names.nil? then [] else aws.forwarded_values.cookies.whitelisted_names.items end added_cookies = (@forwarded_cookies_whitelist - aws_whitelist_cookies) removed_cookies = (aws_whitelist_cookies - @forwarded_cookies_whitelist) if !added_cookies.empty? or !removed_cookies.empty? diffs << CacheBehaviorDiff.cookies_whitelist(added_cookies, removed_cookies, self) end aws_headers = if aws.forwarded_values.headers.nil? then [] else aws.forwarded_values.headers.items end added_headers = (@forward_headers - aws_headers) removed_headers = (aws_headers - @forward_headers) if !added_headers.empty? or !removed_headers.empty? diffs << CacheBehaviorDiff.headers(added_headers, removed_headers, self) end aws_signers = if !aws.trusted_signers.enabled then [] else aws.trusted_signers.items end added_signers = (@trusted_signers - aws_signers) removed_signers = (aws_signers - @trusted_signers) if !added_signers.empty? or !removed_signers.empty? diffs << CacheBehaviorDiff.signers(added_signers, removed_signers, self) end if @viewer_protocol_policy != aws.viewer_protocol_policy diffs << CacheBehaviorDiff.new(CacheBehaviorChange::VIEWER_PROTOCOL, aws, self) end if @min_ttl != aws.min_ttl diffs << CacheBehaviorDiff.new(CacheBehaviorChange::MINTTL, aws, self) end if @max_ttl != aws.max_ttl diffs << CacheBehaviorDiff.new(CacheBehaviorChange::MAXTTL, aws, self) end if @default_ttl != aws.default_ttl diffs << CacheBehaviorDiff.new(CacheBehaviorChange::DEFTTL, aws, self) end if @smooth_streaming != aws.smooth_streaming diffs << CacheBehaviorDiff.new(CacheBehaviorChange::STREAMING, aws, self) end aws_allowed_methods = if aws.allowed_methods.nil? then [] else aws.allowed_methods.items end added_allowed_methods = (@allowed_methods - aws_allowed_methods) removed_allowed_methods = (aws_allowed_methods - @allowed_methods) if !added_allowed_methods.empty? or !removed_allowed_methods.empty? diffs << CacheBehaviorDiff.allowed_methods(added_allowed_methods, removed_allowed_methods, self) end aws_cached_methods = if aws.allowed_methods.nil? or aws.allowed_methods.cached_methods.nil? then [] else aws.allowed_methods.cached_methods.items end added_cached_methods = (@cached_methods - aws_cached_methods) removed_cached_methods = (aws_cached_methods - @cached_methods) if !added_cached_methods.empty? or !removed_cached_methods.empty? diffs << CacheBehaviorDiff.cached_methods(added_cached_methods, removed_cached_methods, self) end if @compress != aws.compress diffs << CacheBehaviorDiff.new(CacheBehaviorChange::COMPRESS, aws, self) end diffs end
name()
click to toggle source
# File lib/cloudfront/models/CacheBehaviorConfig.rb, line 140 def name if @default "Default Cache" else "#{target_origin_id}/#{path_pattern}" end end
populate!(aws, default = false)
click to toggle source
# File lib/cloudfront/models/CacheBehaviorConfig.rb, line 55 def populate!(aws, default = false) @default = default @path_pattern = aws.path_pattern if !default @target_origin_id = aws.target_origin_id @forward_query_strings = aws.forwarded_values.query_string @forwarded_cookies = aws.forwarded_values.cookies.forward @forwarded_cookies_whitelist = if aws.forwarded_values.cookies.whitelisted_names.nil? then [] else aws.forwarded_values.cookies.whitelisted_names.items end @forward_headers = if aws.forwarded_values.headers.nil? then [] else aws.forwarded_values.headers.items end @trusted_signers = if aws.trusted_signers.enabled then aws.trusted_signers.items else [] end @viewer_protocol_policy = aws.viewer_protocol_policy @min_ttl = aws.min_ttl @max_ttl = aws.max_ttl @default_ttl = aws.default_ttl @smooth_streaming = aws.smooth_streaming @allowed_methods = aws.allowed_methods.items @cached_methods = aws.allowed_methods.cached_methods.items @compress = aws.compress end
to_aws()
click to toggle source
Public: Get the config in the format needed for AWS
Returns the hash
# File lib/cloudfront/models/CacheBehaviorConfig.rb, line 100 def to_aws { path_pattern: @path_pattern, target_origin_id: @target_origin_id, forwarded_values: { query_string: @forward_query_strings, cookies: { forward: @forwarded_cookies, whitelisted_names: { quantity: @forwarded_cookies_whitelist.size, items: if @forwarded_cookies_whitelist.empty? then nil else @forwarded_cookies_whitelist end } }, headers: { quantity: @forward_headers.size, items: if @forward_headers.empty? then nil else @forward_headers end } }, trusted_signers: { enabled: !@trusted_signers.empty?, quantity: @trusted_signers.size, items: if @trusted_signers.empty? then nil else @trusted_signers end }, viewer_protocol_policy: @viewer_protocol_policy, min_ttl: @min_ttl, max_ttl: @max_ttl, default_ttl: @default_ttl, smooth_streaming: @smooth_streaming, allowed_methods: { quantity: @allowed_methods.size, items: if @allowed_methods.empty? then nil else @allowed_methods end, cached_methods: { quantity: @cached_methods.size, items: if @cached_methods.empty? then nil else @cached_methods end } }, compress: @compress } end
to_local()
click to toggle source
Public: Get the config as a hash
Returns the hash
# File lib/cloudfront/models/CacheBehaviorConfig.rb, line 77 def to_local { "path-pattern" => @path_pattern, "target-origin-id" => @target_origin_id, "forward-query-strings" => @forward_query_strings, "forwarded-cookies" => @forwarded_cookies, "forwarded-cookies-whitelist" => @forwarded_cookies_whitelist, "forward-headers" => @forward_headers, "trusted-signers" => @trusted_signers, "viewer-protocol-policy" => @viewer_protocol_policy, "min-ttl" => @min_ttl, "max-ttl" => @max_ttl, "default-ttl" => @default_ttl, "smooth-streaming" => @smooth_streaming, "allowed-methods" => @allowed_methods, "cached-methods" => @cached_methods, "compress" => @compress }.reject { |k, v| v.nil? } end