Class: Cumulus::CloudFront::CacheBehaviorConfig
- Inherits:
-
Object
- Object
- Cumulus::CloudFront::CacheBehaviorConfig
- Defined in:
- lib/cloudfront/models/CacheBehaviorConfig.rb
Overview
Public: An object representing configuration for a distribution cache behavior
Instance Attribute Summary collapse
-
#allow_blank_referer ⇒ Object
readonly
Returns the value of attribute allow_blank_referer.
-
#allowed_methods ⇒ Object
readonly
Returns the value of attribute allowed_methods.
-
#cached_methods ⇒ Object
readonly
Returns the value of attribute cached_methods.
-
#compress ⇒ Object
readonly
Returns the value of attribute compress.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#default_ttl ⇒ Object
readonly
Returns the value of attribute default_ttl.
-
#field_level_encryption_id ⇒ Object
readonly
Returns the value of attribute field_level_encryption_id.
-
#forward_headers ⇒ Object
readonly
Returns the value of attribute forward_headers.
-
#forward_query_strings ⇒ Object
readonly
Returns the value of attribute forward_query_strings.
-
#forwarded_cookies ⇒ Object
readonly
Returns the value of attribute forwarded_cookies.
-
#forwarded_cookies_whitelist ⇒ Object
readonly
Returns the value of attribute forwarded_cookies_whitelist.
-
#lambda_function_associations ⇒ Object
readonly
Returns the value of attribute lambda_function_associations.
-
#max_ttl ⇒ Object
readonly
Returns the value of attribute max_ttl.
-
#min_ttl ⇒ Object
readonly
Returns the value of attribute min_ttl.
-
#path_pattern ⇒ Object
readonly
Returns the value of attribute path_pattern.
-
#referer_checks ⇒ Object
readonly
Returns the value of attribute referer_checks.
-
#referer_whitelist ⇒ Object
readonly
Returns the value of attribute referer_whitelist.
-
#smooth_streaming ⇒ Object
readonly
Returns the value of attribute smooth_streaming.
-
#target_origin_id ⇒ Object
readonly
Returns the value of attribute target_origin_id.
-
#trusted_signers ⇒ Object
readonly
Returns the value of attribute trusted_signers.
-
#viewer_protocol_policy ⇒ Object
readonly
Returns the value of attribute viewer_protocol_policy.
Instance Method Summary collapse
-
#diff(aws) ⇒ Object
Public: Produce an array of differences between this local configuration and the configuration in AWS.
-
#initialize(json = nil, default = false) ⇒ CacheBehaviorConfig
constructor
Public: Constructor.
- #name ⇒ Object
- #populate!(aws, default = false) ⇒ Object
-
#to_aws ⇒ Object
Public: Get the config in the format needed for AWS.
-
#to_local ⇒ Object
Public: Get the config as a hash.
Constructor Details
#initialize(json = nil, default = false) ⇒ CacheBehaviorConfig
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)
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 37 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"] @forward_query_string_cache_keys = json["forward-query-strings-cache-keys"] || [] @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 @lambda_function_associations = json["lambda_function_associations"] || [] @field_level_encryption_id = json["field_level_encryption_id"] || "" end end |
Instance Attribute Details
#allow_blank_referer ⇒ Object (readonly)
Returns the value of attribute allow_blank_referer.
18 19 20 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 18 def allow_blank_referer @allow_blank_referer end |
#allowed_methods ⇒ Object (readonly)
Returns the value of attribute allowed_methods.
27 28 29 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 27 def allowed_methods @allowed_methods end |
#cached_methods ⇒ Object (readonly)
Returns the value of attribute cached_methods.
28 29 30 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 28 def cached_methods @cached_methods end |
#compress ⇒ Object (readonly)
Returns the value of attribute compress.
29 30 31 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 29 def compress @compress end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
11 12 13 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 11 def default @default end |
#default_ttl ⇒ Object (readonly)
Returns the value of attribute default_ttl.
25 26 27 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 25 def default_ttl @default_ttl end |
#field_level_encryption_id ⇒ Object (readonly)
Returns the value of attribute field_level_encryption_id.
31 32 33 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 31 def field_level_encryption_id @field_level_encryption_id end |
#forward_headers ⇒ Object (readonly)
Returns the value of attribute forward_headers.
17 18 19 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 17 def forward_headers @forward_headers end |
#forward_query_strings ⇒ Object (readonly)
Returns the value of attribute forward_query_strings.
14 15 16 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 14 def forward_query_strings @forward_query_strings end |
#forwarded_cookies ⇒ Object (readonly)
Returns the value of attribute forwarded_cookies.
15 16 17 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 15 def @forwarded_cookies end |
#forwarded_cookies_whitelist ⇒ Object (readonly)
Returns the value of attribute forwarded_cookies_whitelist.
16 17 18 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 16 def @forwarded_cookies_whitelist end |
#lambda_function_associations ⇒ Object (readonly)
Returns the value of attribute lambda_function_associations.
30 31 32 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 30 def lambda_function_associations @lambda_function_associations end |
#max_ttl ⇒ Object (readonly)
Returns the value of attribute max_ttl.
24 25 26 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 24 def max_ttl @max_ttl end |
#min_ttl ⇒ Object (readonly)
Returns the value of attribute min_ttl.
23 24 25 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 23 def min_ttl @min_ttl end |
#path_pattern ⇒ Object (readonly)
Returns the value of attribute path_pattern.
12 13 14 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 12 def path_pattern @path_pattern end |
#referer_checks ⇒ Object (readonly)
Returns the value of attribute referer_checks.
19 20 21 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 19 def referer_checks @referer_checks end |
#referer_whitelist ⇒ Object (readonly)
Returns the value of attribute referer_whitelist.
20 21 22 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 20 def referer_whitelist @referer_whitelist end |
#smooth_streaming ⇒ Object (readonly)
Returns the value of attribute smooth_streaming.
26 27 28 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 26 def smooth_streaming @smooth_streaming end |
#target_origin_id ⇒ Object (readonly)
Returns the value of attribute target_origin_id.
13 14 15 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 13 def target_origin_id @target_origin_id end |
#trusted_signers ⇒ Object (readonly)
Returns the value of attribute trusted_signers.
21 22 23 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 21 def trusted_signers @trusted_signers end |
#viewer_protocol_policy ⇒ Object (readonly)
Returns the value of attribute viewer_protocol_policy.
22 23 24 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 22 def viewer_protocol_policy @viewer_protocol_policy end |
Instance Method Details
#diff(aws) ⇒ Object
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
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 160 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..forward diffs << CacheBehaviorDiff.new(CacheBehaviorChange::COOKIES, aws, self) end = if aws.forwarded_values..whitelisted_names.nil? then [] else aws.forwarded_values..whitelisted_names.items end = (@forwarded_cookies_whitelist - ) = ( - @forwarded_cookies_whitelist) if !.empty? or !.empty? diffs << CacheBehaviorDiff.(, , self) end aws_query_string_cache_keys = aws.forwarded_values.query_string_cache_keys.items || [] added_keys = (@forward_query_string_cache_keys - aws_query_string_cache_keys) removed_keys = (aws_query_string_cache_keys - @forward_query_string_cache_keys) if !(added_keys.empty? && removed_keys.empty?) diffs << CacheBehaviorDiff.query_string_cache_keys(added_keys, removed_keys, 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 aws_lambda_function_assocs = if aws.lambda_function_associations.nil? then [] else aws.lambda_function_associations.items end added_assocs = (@lambda_function_associations - aws_lambda_function_assocs) removed_assocs = (aws_lambda_function_assocs - @lambda_function_associations) unless added_allowed_methods.empty? and removed_allowed_methods.empty? diffs << CacheBehaviorDiff.lambda_function_associations(added_assocs, removed_assocs, self) end if @field_level_encryption_id != aws.field_level_encryption_id diffs << CacheBehaviorDiff.new(CacheBehaviorChange::FIELD_LEVEL_ENCRYPTION_ID, aws, self) end diffs end |
#name ⇒ Object
146 147 148 149 150 151 152 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 146 def name if @default "Default Cache" else "#{target_origin_id}/#{path_pattern}" end end |
#populate!(aws, default = false) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 61 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 @forward_query_string_cache_keys = aws.forwarded_values.query_string_cache_keys.items || [] @forwarded_cookies = aws.forwarded_values..forward @forwarded_cookies_whitelist = if aws.forwarded_values..whitelisted_names.nil? then [] else aws.forwarded_values..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 @lambda_function_associations = if aws.lambda_function_associations.nil? then [] else aws.lambda_function_associations.items end @field_level_encryption_id = aws.field_level_encryption_id end |
#to_aws ⇒ Object
Public: Get the config in the format needed for AWS
Returns the hash
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 112 def to_aws { path_pattern: @path_pattern, target_origin_id: @target_origin_id, forwarded_values: { query_string: @forward_query_strings, query_string_cache_keys: AwsUtil.aws_array(@forward_query_string_cache_keys), cookies: { forward: @forwarded_cookies, whitelisted_names: AwsUtil.aws_array(@forwarded_cookies_whitelist), }, headers: AwsUtil.aws_array(@forward_headers) }, trusted_signers: { enabled: !@trusted_signers.empty?, quantity: @trusted_signers.size, items: AwsUtil.array_or_nil(@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: { quantity: @allowed_methods.size, items: AwsUtil.array_or_nil(@allowed_methods), cached_methods: AwsUtil.aws_array(@cached_methods) }, compress: @compress, lambda_function_associations: AwsUtil.aws_array(@lambda_function_associations), field_level_encryption_id: @field_level_encryption_id } end |
#to_local ⇒ Object
Public: Get the config as a hash
Returns the hash
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 86 def to_local { "path-pattern" => @path_pattern, "target-origin-id" => @target_origin_id, "forward-query-strings" => @forward_query_strings, "forward-query-strings-cache-keys" => @forward_query_string_cache_keys, "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, "lambda_function_associations" => @lambda_function_associations, "field_level_encryption_id" => @field_level_encryption_id }.reject { |k, v| v.nil? } end |