mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|cdn] continuing to flesh out distribution requests
This commit is contained in:
parent
3d6104e383
commit
cf75ce1dee
9 changed files with 240 additions and 13 deletions
|
@ -7,7 +7,10 @@ module Fog
|
|||
model_path 'fog/aws/models/cdn'
|
||||
|
||||
request_path 'fog/aws/requests/cdn'
|
||||
request 'delete_distribution'
|
||||
request 'get_distribution'
|
||||
request 'get_distribution_list'
|
||||
request 'post_distribution'
|
||||
request 'post_invalidation'
|
||||
|
||||
class Mock
|
||||
|
|
|
@ -15,7 +15,7 @@ module Fog
|
|||
when 'DistributionSummary'
|
||||
@response['DistributionSummary'] << @distribution_summary
|
||||
@distribution_summary = { 'CNAME' => [], 'TrustedSigners' => [] }
|
||||
when 'Comment', 'DomainName', 'ID', 'Origin', 'Status'
|
||||
when 'Comment', 'DomainName', 'Id', 'Origin', 'Status'
|
||||
@distribution_summary[name] = @value
|
||||
when 'CNAME'
|
||||
@distribution_summary[name] << @value
|
||||
|
|
44
lib/fog/aws/parsers/cdn/post_distribution.rb
Normal file
44
lib/fog/aws/parsers/cdn/post_distribution.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module CDN
|
||||
|
||||
class Distribution < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@response = { 'DistributionConfig' => { 'CNAME' => [], 'Logging' => {}, 'TrustedSigners' => [] } }
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'AwsAccountNumber'
|
||||
@response['DistributionConfig']['TrustedSigners'] << @value
|
||||
when 'Bucket', 'Prefix'
|
||||
@response['DistributionConfig']['Logging'][name] = @value
|
||||
when 'CNAME'
|
||||
@response['DistributionConfig']['CNAME'] << @value
|
||||
when 'DomainName', 'Id', 'Status'
|
||||
@response[name] = @value
|
||||
when 'CallerReference', 'Comment', 'DefaultRootObject', 'Origin', 'OriginAccessIdentity'
|
||||
@response['DistributionConfig'][name] << @value
|
||||
when 'Enabled'
|
||||
if @value == 'true'
|
||||
@response['DistributionConfig'][name] = true
|
||||
else
|
||||
@response['DistributionConfig'][name] = false
|
||||
end
|
||||
when 'LastModifiedTime'
|
||||
@response[name] = Time.parse(@value)
|
||||
when 'Protocol'
|
||||
@response['DistributionConfig']['RequireProtocols'] = @value
|
||||
when 'Self'
|
||||
@response['DistributionConfig']['TrustedSigners'] << 'Self'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -13,7 +13,7 @@ module Fog
|
|||
case name
|
||||
when 'CallerReference'
|
||||
@response['InvalidationBatch'][name] = @value
|
||||
when 'CreateTime', 'ID', 'Status'
|
||||
when 'CreateTime', 'Id', 'Status'
|
||||
@response[name] = @value
|
||||
when 'Path'
|
||||
@response['InvalidationBatch'][name] << @value
|
||||
|
|
36
lib/fog/aws/requests/cdn/delete_distribution.rb
Normal file
36
lib/fog/aws/requests/cdn/delete_distribution.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class CDN
|
||||
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 # :nodoc:all
|
||||
|
||||
def delete_distribution(distribution_id, etag)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
55
lib/fog/aws/requests/cdn/get_distribution.rb
Normal file
55
lib/fog/aws/requests/cdn/get_distribution.rb
Normal file
|
@ -0,0 +1,55 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class CDN
|
||||
class Real
|
||||
|
||||
require 'fog/aws/parsers/cdn/distribution'
|
||||
|
||||
# Get information about a distribution from CloudFront
|
||||
#
|
||||
# ==== Parameters
|
||||
# * distribution_id<~String> - id of distribution
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'DomainName'<~String>: Domain name of distribution
|
||||
# * 'Id'<~String> - Id of distribution
|
||||
# * 'LastModifiedTime'<~String> - Timestamp of last modification of distribution
|
||||
# * 'Status'<~String> - Status of distribution
|
||||
# * 'DistributionConfig'<~Array>:
|
||||
# * 'CallerReference'<~String> - Used to prevent replay, defaults to Time.now.to_i.to_s
|
||||
# * 'CNAME'<~Array> - array of associated cnames
|
||||
# * 'Comment'<~String> - comment associated with distribution
|
||||
# * 'Enabled'<~Boolean> - whether or not distribution is enabled
|
||||
# * 'Logging'<~Hash>:
|
||||
# * 'Bucket'<~String> - bucket logs are stored in
|
||||
# * 'Prefix'<~String> - prefix logs are stored with
|
||||
# * 'Origin'<~String> - s3 origin bucket
|
||||
# * 'TrustedSigners'<~Array> - trusted signers
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/GetDistribution.html
|
||||
|
||||
def get_distribution(distribution_id)
|
||||
request({
|
||||
:expects => 200,
|
||||
:idempotent => true,
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::AWS::CDN::Distribution.new,
|
||||
:path => "/distribution/#{distribution_id}"
|
||||
})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock # :nodoc:all
|
||||
|
||||
def get_distribution(distribution_id)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -21,15 +21,15 @@ module Fog
|
|||
# * 'MaxItems'<~Integer> - Maximum number of keys specified for query
|
||||
# * 'NextMarker'<~String> - Marker to specify for next page (id of last result of current page)
|
||||
# * 'DistributionSummary'<~Array>:
|
||||
# * 'Id'<~String>: Id of distribution
|
||||
# * 'LastModifiedTime'<~String>: Timestamp of last modification of distribution
|
||||
# * 'Status'<~String>: Status of distribution
|
||||
# * 'DomainName'<~String>: Domain name of distribution
|
||||
# * 'Origin'<~String>: s3 origin bucket
|
||||
# * 'CNAME'<~Array>: array of associated cnames
|
||||
# * 'Comment'<~String>: comment associated with distribution
|
||||
# * 'Enabled'<~Boolean>: whether or not distribution is enabled
|
||||
# * 'TrustedSigners'<~Array>: trusted signers
|
||||
# * 'Comment'<~String> - comment associated with distribution
|
||||
# * 'CNAME'<~Array> - array of associated cnames
|
||||
# * 'DomainName'<~String> - Domain name of distribution
|
||||
# * 'Enabled'<~Boolean> - whether or not distribution is enabled
|
||||
# * 'Id'<~String> - Id of distribution
|
||||
# * 'LastModifiedTime'<~String> - Timestamp of last modification of distribution
|
||||
# * 'Origin'<~String> - s3 origin bucket
|
||||
# * 'Status'<~String> - Status of distribution
|
||||
# * 'TrustedSigners'<~Array> - trusted signers
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/ListDistributions.html
|
||||
|
|
88
lib/fog/aws/requests/cdn/post_distribution.rb
Normal file
88
lib/fog/aws/requests/cdn/post_distribution.rb
Normal file
|
@ -0,0 +1,88 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class CDN
|
||||
class Real
|
||||
|
||||
require 'fog/aws/parsers/cdn/distribution'
|
||||
|
||||
# create a new distribution in CloudFront
|
||||
#
|
||||
# ==== Parameters
|
||||
# * origin<~String> - s3 bucket, ie 'mybucket.s3.amazonaws.com'
|
||||
# * config<~Hash> - config for distribution. Defaults to {}.
|
||||
# * 'CallerReference'<~String> - Used to prevent replay, defaults to Time.now.to_i.to_s
|
||||
# * 'Comment'<~String> - Optional comment about distribution
|
||||
# * 'CNAME'<~Array> - Optional array of strings to set as CNAMEs
|
||||
# * 'DefaultRootObject'<~String> - Optional default object to return for '/'
|
||||
# * 'Enabled'<~Boolean> - Whether or not distribution should accept requests, defaults to true
|
||||
# * 'Logging'<~Hash>: Optional logging config
|
||||
# * 'Bucket'<~String> - Bucket to store logs in, ie 'mylogs.s3.amazonaws.com'
|
||||
# * 'Prefix'<~String> - Optional prefix for log filenames, ie 'myprefix/'
|
||||
# * 'OriginAccessIdentity'<~String> - Used for serving private content, in format 'origin-access-identity/cloudfront/ID'
|
||||
# * 'RequiredProtocols'<~String> - Optional, set to 'https' to force https connections
|
||||
# * 'TrustedSigners'<~Array> - Optional grant of rights to up to 5 aws accounts to generate signed URLs for private content, elements are either 'Self' for your own account or an AWS Account Number
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'DomainName'<~String>: Domain name of distribution
|
||||
# * 'Id'<~String> - Id of distribution
|
||||
# * 'LastModifiedTime'<~String> - Timestamp of last modification of distribution
|
||||
# * 'Status'<~String> - Status of distribution
|
||||
# * 'DistributionConfig'<~Array>:
|
||||
# * 'CallerReference'<~String> - Used to prevent replay, defaults to Time.now.to_i.to_s
|
||||
# * 'CNAME'<~Array> - array of associated cnames
|
||||
# * 'Comment'<~String> - comment associated with distribution
|
||||
# * 'Enabled'<~Boolean> - whether or not distribution is enabled
|
||||
# * 'Logging'<~Hash>:
|
||||
# * 'Bucket'<~String> - bucket logs are stored in
|
||||
# * 'Prefix'<~String> - prefix logs are stored with
|
||||
# * 'Origin'<~String> - s3 origin bucket
|
||||
# * 'TrustedSigners'<~Array> - trusted signers
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/CreateDistribution.html
|
||||
|
||||
def post_distribution(origin, options = {})
|
||||
data = '<?xml version="1.0" encoding="UTF-8"?>'
|
||||
data << "<DistributionConfig xmlns=\"http://cloudfront.amazonaws.com/doc/#{@version}/\">"
|
||||
for key, value in options
|
||||
case value
|
||||
when Array
|
||||
for item in array
|
||||
data << "<#{key}>#{item}</#{key}>"
|
||||
end
|
||||
when Hash
|
||||
data << "<#{key}>"
|
||||
for inner_key, inner_value in value
|
||||
data << "<#{inner_key}>#{inner_value}</#{inner_key}>"
|
||||
end
|
||||
data << "</#{key}>"
|
||||
else
|
||||
data << "<#{key}>#{value}</#{key}>"
|
||||
end
|
||||
end
|
||||
data << "</DistributionConfig>"
|
||||
request({
|
||||
:body => data,
|
||||
:expects => 201,
|
||||
:headers => { 'Content-Type' => 'text/xml' },
|
||||
:idempotent => true,
|
||||
:method => 'POST',
|
||||
:parser => Fog::Parsers::AWS::CDN::Distribution.new,
|
||||
:path => "/distribution"
|
||||
})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock # :nodoc:all
|
||||
|
||||
def post_distribution(origin, options = {})
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -20,8 +20,8 @@ module Fog
|
|||
# * '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
|
||||
# * '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
|
||||
|
@ -35,6 +35,7 @@ module Fog
|
|||
body << "<CallerReference>" << caller_reference << "</CallerReference>"
|
||||
body << "</InvalidationBatch>"
|
||||
request({
|
||||
:body => body,
|
||||
:expects => 201,
|
||||
:headers => {'Content-Type' => 'text/xml'},
|
||||
:idempotent => true,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue