1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/aws/requests/cdn/delete_distribution.rb
Brice Figureau e877f95034 [aws|cdn] add request mock support for AWS Cloudfront
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>
2012-09-28 11:24:36 +02:00

59 lines
1.7 KiB
Ruby

module Fog
module CDN
class AWS
class Real
# Delete a distribution from CloudFront
#
# ==== Parameters
# * distribution_id<~String> - Id of distribution to delete
# * etag<~String> - etag of that distribution from earlier get or put
#
# ==== See Also
# http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/DeleteDistribution.html
def delete_distribution(distribution_id, etag)
request({
:expects => 204,
:headers => { 'If-Match' => etag },
:idempotent => true,
:method => 'DELETE',
:path => "/distribution/#{distribution_id}"
})
end
end
class Mock
def delete_distribution(distribution_id, etag)
distribution = self.data[:distributions][distribution_id]
if distribution
if distribution['ETag'] != etag
Fog::CDN::AWS::Mock.error(:invalid_if_match_version)
end
unless distribution['DistributionConfig']['CallerReference']
Fog::CDN::AWS::Mock.error(:illegal_update)
end
if distribution['DistributionConfig']['Enabled']
Fog::CDN::AWS::Mock.error(:distribution_not_disabled)
end
self.data[:distributions].delete(distribution_id)
self.data[:invalidations].delete(distribution_id)
response = Excon::Response.new
response.status = 204
response.body = "x-amz-request-id: #{Fog::AWS::Mock.request_id}"
response
else
Fog::CDN::AWS::Mock.error(:no_such_distribution)
end
end
end
end
end
end