mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
e877f95034
This patch adds support for mocking the cloudfront API. CDN Tests now can both be run with mocking and non mocking activated. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
60 lines
1.8 KiB
Ruby
60 lines
1.8 KiB
Ruby
module Fog
|
|
module CDN
|
|
class AWS
|
|
class Real
|
|
|
|
require 'fog/aws/parsers/cdn/get_invalidation'
|
|
|
|
# ==== Parameters
|
|
#
|
|
# ==== Returns
|
|
# * response<~Excon::Response>:
|
|
# * body<~Hash>:
|
|
# * 'Id'<~String> - Invalidation id
|
|
# * 'Status'<~String>
|
|
# * 'CreateTime'<~String>
|
|
# * 'InvalidationBatch'<~Array>:
|
|
# * 'Path'<~String>
|
|
# ==== See Also
|
|
# http://docs.amazonwebservices.com/AmazonCloudFront/2010-11-01/APIReference/GetInvalidation.html
|
|
|
|
def get_invalidation(distribution_id, invalidation_id)
|
|
request({
|
|
:expects => 200,
|
|
:idempotent => true,
|
|
:method => 'GET',
|
|
:parser => Fog::Parsers::CDN::AWS::GetInvalidation.new,
|
|
:path => "/distribution/#{distribution_id}/invalidation/#{invalidation_id}"
|
|
})
|
|
end
|
|
|
|
end
|
|
|
|
class Mock
|
|
|
|
def get_invalidation(distribution_id, invalidation_id)
|
|
distribution = self.data[:distributions][distribution_id]
|
|
unless distribution
|
|
Fog::CDN::AWS::Mock.error(:no_such_distribution)
|
|
end
|
|
|
|
invalidation = self.data[:invalidations][distribution_id][invalidation_id]
|
|
unless invalidation
|
|
Fog::CDN::AWS::Mock.error(:no_such_invalidation)
|
|
end
|
|
|
|
if invalidation['Status'] == 'InProgress' && (Time.now - Time.parse(invalidation['CreateTime']) >= Fog::Mock.delay * 2)
|
|
invalidation['Status'] = 'Completed'
|
|
distribution['InProgressInvalidationBatches'] -= 1
|
|
end
|
|
|
|
response = Excon::Response.new
|
|
response.status = 200
|
|
response.body = invalidation
|
|
response
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|
|
end
|