6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/configure-s3-website/cloudfront_client.rb', line 6
def self.apply_distribution_config(options)
config_source = options[:config_source]
puts "Detected an existing CloudFront distribution (id #{config_source.cloudfront_distribution_id}) ..."
response = HttpHelper.call_cloudfront_api(
path = "/2012-07-01/distribution/#{config_source.cloudfront_distribution_id}/config",
method = Net::HTTP::Get,
body = '',
config_source
)
etag = response['ETag']
caller_reference = REXML::XPath.first(
REXML::Document.new(response.body),
'/DistributionConfig/CallerReference'
).get_text.to_s
custom_distribution_config = config_source.cloudfront_distribution_config || {}
custom_distribution_config_with_caller_ref = custom_distribution_config.merge({
'caller_reference' => caller_reference,
'comment' => 'Updated by the configure-s3-website gem'
})
HttpHelper.call_cloudfront_api(
path = "/2012-07-01/distribution/#{options[:config_source].cloudfront_distribution_id}/config",
method = Net::HTTP::Put,
body = distribution_config_xml(
config_source,
custom_distribution_config_with_caller_ref
),
config_source,
= { 'If-Match' => etag }
)
unless custom_distribution_config.empty?
print_report_on_custom_distribution_config custom_distribution_config
end
end
|