2010-11-01 18:01:55 -04:00
|
|
|
module Fog
|
2011-06-15 20:32:15 -04:00
|
|
|
module CDN
|
|
|
|
class AWS
|
2010-11-01 18:01:55 -04:00
|
|
|
class Real
|
|
|
|
|
2011-08-24 15:20:21 -04:00
|
|
|
require 'fog/aws/parsers/cdn/post_invalidation'
|
2010-11-01 18:01:55 -04:00
|
|
|
|
|
|
|
# List information about distributions in CloudFront
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
|
|
|
# * distribution_id<~String> - Id of distribution for invalidations
|
|
|
|
# * paths<~Array> - Array of string paths to objects to invalidate
|
|
|
|
# * caller_reference<~String> - Used to prevent replay, defaults to Time.now.to_i.to_s
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# ==== Returns
|
|
|
|
# * response<~Excon::Response>:
|
|
|
|
# * body<~Hash>:
|
|
|
|
# * 'Id'<~String> - Id of invalidation
|
|
|
|
# * 'Status'<~String> - Status of invalidation
|
|
|
|
# * 'CreateTime'<~Integer> - Time of invalidation creation
|
|
|
|
# * 'InvalidationBatch'<~Array>:
|
2010-11-01 20:44:14 -04:00
|
|
|
# * 'Path'<~Array> - Array of strings of objects to invalidate
|
|
|
|
# * 'CallerReference'<~String> - Used to prevent replay, defaults to Time.now.to_i.to_s
|
2010-11-01 18:01:55 -04:00
|
|
|
#
|
|
|
|
# ==== See Also
|
|
|
|
# http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/CreateInvalidation.html
|
|
|
|
|
|
|
|
def post_invalidation(distribution_id, paths, caller_reference = Time.now.to_i.to_s)
|
|
|
|
body = '<?xml version="1.0" encoding="UTF-8"?>'
|
|
|
|
body << "<InvalidationBatch>"
|
2010-11-01 18:05:02 -04:00
|
|
|
for path in [*paths]
|
2010-11-01 18:01:55 -04:00
|
|
|
body << "<Path>" << path << "</Path>"
|
|
|
|
end
|
|
|
|
body << "<CallerReference>" << caller_reference << "</CallerReference>"
|
|
|
|
body << "</InvalidationBatch>"
|
|
|
|
request({
|
2010-11-01 20:44:14 -04:00
|
|
|
:body => body,
|
2010-11-01 18:01:55 -04:00
|
|
|
:expects => 201,
|
|
|
|
:headers => {'Content-Type' => 'text/xml'},
|
|
|
|
:idempotent => true,
|
|
|
|
:method => 'POST',
|
2011-06-15 20:32:15 -04:00
|
|
|
:parser => Fog::Parsers::CDN::AWS::PostInvalidation.new,
|
2010-11-01 18:01:55 -04:00
|
|
|
:path => "/distribution/#{distribution_id}/invalidation"
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2012-09-27 18:00:16 -04:00
|
|
|
|
|
|
|
class Mock
|
|
|
|
|
|
|
|
def post_invalidation(distribution_id, paths, caller_reference = Time.now.to_i.to_s)
|
|
|
|
distribution = self.data[:distributions][distribution_id]
|
|
|
|
if distribution
|
|
|
|
invalidation_id = Fog::CDN::AWS::Mock.distribution_id
|
|
|
|
invalidation = {
|
|
|
|
'Id' => invalidation_id,
|
|
|
|
'Status' => 'InProgress',
|
|
|
|
'CreateTime' => Time.now.utc.iso8601,
|
|
|
|
'InvalidationBatch' => {
|
|
|
|
'CallerReference' => caller_reference,
|
|
|
|
'Path' => paths
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
distribution['InProgressInvalidationBatches'] += 1
|
|
|
|
|
|
|
|
self.data[:invalidations][distribution_id] ||= {}
|
|
|
|
self.data[:invalidations][distribution_id][invalidation_id] = invalidation
|
|
|
|
|
|
|
|
response = Excon::Response.new
|
|
|
|
response.status = 201
|
|
|
|
response.body = invalidation
|
|
|
|
response
|
|
|
|
else
|
|
|
|
Fog::CDN::AWS::Mock.error(:no_such_distribution)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2010-11-01 18:01:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|