Class: Cumulus::CloudFront::CacheBehaviorConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudfront/models/CacheBehaviorConfig.rb

Overview

Public: An object representing configuration for a distribution cache behavior

Instance Attribute Summary collapse

Instance Method Summary collapse

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)



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 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

Instance Attribute Details

#allow_blank_refererObject (readonly)

Returns the value of attribute allow_blank_referer.



17
18
19
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 17

def allow_blank_referer
  @allow_blank_referer
end

#allowed_methodsObject (readonly)

Returns the value of attribute allowed_methods.



26
27
28
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 26

def allowed_methods
  @allowed_methods
end

#cached_methodsObject (readonly)

Returns the value of attribute cached_methods.



27
28
29
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 27

def cached_methods
  @cached_methods
end

#compressObject (readonly)

Returns the value of attribute compress.



28
29
30
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 28

def compress
  @compress
end

#defaultObject (readonly)

Returns the value of attribute default.



10
11
12
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 10

def default
  @default
end

#default_ttlObject (readonly)

Returns the value of attribute default_ttl.



24
25
26
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 24

def default_ttl
  @default_ttl
end

#forward_headersObject (readonly)

Returns the value of attribute forward_headers.



16
17
18
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 16

def forward_headers
  @forward_headers
end

#forward_query_stringsObject (readonly)

Returns the value of attribute forward_query_strings.



13
14
15
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 13

def forward_query_strings
  @forward_query_strings
end

#forwarded_cookiesObject (readonly)

Returns the value of attribute forwarded_cookies.



14
15
16
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 14

def forwarded_cookies
  @forwarded_cookies
end

#forwarded_cookies_whitelistObject (readonly)

Returns the value of attribute forwarded_cookies_whitelist.



15
16
17
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 15

def forwarded_cookies_whitelist
  @forwarded_cookies_whitelist
end

#max_ttlObject (readonly)

Returns the value of attribute max_ttl.



23
24
25
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 23

def max_ttl
  @max_ttl
end

#min_ttlObject (readonly)

Returns the value of attribute min_ttl.



22
23
24
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 22

def min_ttl
  @min_ttl
end

#path_patternObject (readonly)

Returns the value of attribute path_pattern.



11
12
13
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 11

def path_pattern
  @path_pattern
end

#referer_checksObject (readonly)

Returns the value of attribute referer_checks.



18
19
20
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 18

def referer_checks
  @referer_checks
end

#referer_whitelistObject (readonly)

Returns the value of attribute referer_whitelist.



19
20
21
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 19

def referer_whitelist
  @referer_whitelist
end

#smooth_streamingObject (readonly)

Returns the value of attribute smooth_streaming.



25
26
27
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 25

def smooth_streaming
  @smooth_streaming
end

#target_origin_idObject (readonly)

Returns the value of attribute target_origin_id.



12
13
14
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 12

def target_origin_id
  @target_origin_id
end

#trusted_signersObject (readonly)

Returns the value of attribute trusted_signers.



20
21
22
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 20

def trusted_signers
  @trusted_signers
end

#viewer_protocol_policyObject (readonly)

Returns the value of attribute viewer_protocol_policy.



21
22
23
# File 'lib/cloudfront/models/CacheBehaviorConfig.rb', line 21

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



154
155
156
157
158
159
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
# 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

#nameObject



140
141
142
143
144
145
146
# 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) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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_awsObject

Public: Get the config in the format needed for AWS

Returns the hash



100
101
102
103
104
105
106
107
108
109
110
111
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
# 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_localObject

Public: Get the config as a hash

Returns the hash



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# 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