mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|cdn] first pass at post_invalidation
This commit is contained in:
parent
4b2b6ccef1
commit
2a77066d4d
3 changed files with 87 additions and 0 deletions
|
@ -8,6 +8,7 @@ module Fog
|
|||
|
||||
request_path 'fog/aws/requests/cdn'
|
||||
request 'get_distribution_list'
|
||||
request 'post_invalidation'
|
||||
|
||||
class Mock
|
||||
|
||||
|
|
28
lib/fog/aws/parsers/cdn/post_invalidation.rb
Normal file
28
lib/fog/aws/parsers/cdn/post_invalidation.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module CDN
|
||||
|
||||
class PostInvalidation < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@response = { 'InvalidationBatch' => { 'Path' => [] } }
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'CallerReference'
|
||||
@response['InvalidationBatch'][name] = @value
|
||||
when 'CreateTime', 'ID', 'Status'
|
||||
@response[name] = @value
|
||||
when 'Path'
|
||||
@response['InvalidationBatch'][name] << @value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
58
lib/fog/aws/requests/cdn/post_invalidation.rb
Normal file
58
lib/fog/aws/requests/cdn/post_invalidation.rb
Normal file
|
@ -0,0 +1,58 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class CDN
|
||||
class Real
|
||||
|
||||
require 'fog/aws/parsers/cdn/post_invalidation'
|
||||
|
||||
# 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>:
|
||||
# * 'Path'<~Array>: Array of strings of objects to invalidate
|
||||
# * 'CallerReference'<~String>: Used to prevent replay, defaults to Time.now.to_i.to_s
|
||||
#
|
||||
# ==== 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>"
|
||||
for path in paths
|
||||
body << "<Path>" << path << "</Path>"
|
||||
end
|
||||
body << "<CallerReference>" << caller_reference << "</CallerReference>"
|
||||
body << "</InvalidationBatch>"
|
||||
request({
|
||||
:expects => 201,
|
||||
:headers => {'Content-Type' => 'text/xml'},
|
||||
:idempotent => true,
|
||||
:method => 'POST',
|
||||
:parser => Fog::Parsers::AWS::CDN::PostInvalidation.new,
|
||||
:path => "/distribution/#{distribution_id}/invalidation"
|
||||
})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock # :nodoc:all
|
||||
|
||||
def post_invalidation(distribution_id, paths, caller_reference = Time.now.to_i.to_s)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue