Class: Fog::AWS::CDN::Real
- Inherits:
-
Object
- Object
- Fog::AWS::CDN::Real
- Defined in:
- lib/fog/aws/cdn.rb,
lib/fog/aws/requests/cdn/get_distribution.rb,
lib/fog/aws/requests/cdn/get_invalidation.rb,
lib/fog/aws/requests/cdn/post_distribution.rb,
lib/fog/aws/requests/cdn/post_invalidation.rb,
lib/fog/aws/requests/cdn/delete_distribution.rb,
lib/fog/aws/requests/cdn/get_distribution_list.rb,
lib/fog/aws/requests/cdn/get_invalidation_list.rb,
lib/fog/aws/requests/cdn/put_distribution_config.rb,
lib/fog/aws/requests/cdn/get_streaming_distribution.rb,
lib/fog/aws/requests/cdn/post_streaming_distribution.rb,
lib/fog/aws/requests/cdn/delete_streaming_distribution.rb,
lib/fog/aws/requests/cdn/get_streaming_distribution_list.rb,
lib/fog/aws/requests/cdn/put_streaming_distribution_config.rb
Instance Method Summary collapse
-
#delete_distribution(distribution_id, etag) ⇒ Object
Delete a distribution from CloudFront.
-
#delete_streaming_distribution(distribution_id, etag) ⇒ Object
Delete a streaming distribution from CloudFront.
-
#get_distribution(distribution_id) ⇒ Excon::Response
Get information about a distribution from CloudFront.
-
#get_distribution_list(options = {}) ⇒ Excon::Response
-
body [Hash]: * IsTruncated [Boolean] - Whether or not the listing is truncated.
-
-
#get_invalidation(distribution_id, invalidation_id) ⇒ Excon::Response
Get invalidation.
-
#get_invalidation_list(distribution_id, options = {}) ⇒ Excon::Response
Get invalidation list.
-
#get_streaming_distribution(distribution_id) ⇒ Excon::Response
Get information about a streaming distribution from CloudFront.
-
#get_streaming_distribution_list(options = {}) ⇒ Excon::Response
List information about distributions in CloudFront.
-
#initialize(options = {}) ⇒ Real
constructor
Initialize connection to Cloudfront.
-
#post_distribution(options = {}) ⇒ Excon::Response
Create a new distribution in CloudFront.
-
#post_invalidation(distribution_id, paths, caller_reference = Time.now.to_i.to_s) ⇒ Excon::Response
List information about distributions in CloudFront.
-
#post_streaming_distribution(options = {}) ⇒ Excon::Response
Create a new streaming distribution in CloudFront.
-
#put_distribution_config(distribution_id, etag, options = {}) ⇒ Excon::Response
Update a distribution in CloudFront.
-
#put_streaming_distribution_config(distribution_id, etag, options = {}) ⇒ Excon::Response
Update a streaming distribution in CloudFront.
- #reload ⇒ Object
Methods included from Fog::AWS::CredentialFetcher::ConnectionMethods
#refresh_credentials_if_expired
Constructor Details
#initialize(options = {}) ⇒ Real
Initialize connection to Cloudfront
Notes
options parameter must include values for :aws_access_key_id and :aws_secret_access_key in order to create a connection
Examples
cdn = Fog::AWS::CDN.new(
:aws_access_key_id => your_aws_access_key_id,
:aws_secret_access_key => your_aws_secret_access_key
)
Parameters
-
options<~Hash> - config arguments for connection. Defaults to {}.
Returns
-
cdn object with connection to aws.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/fog/aws/cdn.rb', line 142 def initialize(={}) @use_iam_profile = [:use_iam_profile] setup_credentials() @instrumentor = [:instrumentor] @instrumentor_name = [:instrumentor_name] || 'fog.aws.cdn' @connection_options = [:connection_options] || {} @host = [:host] || 'cloudfront.amazonaws.com' @path = [:path] || '/' @persistent = .fetch(:persistent, true) @port = [:port] || 443 @scheme = [:scheme] || 'https' @version = [:version] || '2010-11-01' @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options) end |
Instance Method Details
#delete_distribution(distribution_id, etag) ⇒ Object
Delete a distribution from CloudFront.
12 13 14 15 16 17 18 19 20 |
# File 'lib/fog/aws/requests/cdn/delete_distribution.rb', line 12 def delete_distribution(distribution_id, etag) request({ :expects => 204, :headers => { 'If-Match' => etag }, :idempotent => true, :method => 'DELETE', :path => "/distribution/#{distribution_id}" }) end |
#delete_streaming_distribution(distribution_id, etag) ⇒ Object
Delete a streaming distribution from CloudFront.
12 13 14 15 16 17 18 19 20 |
# File 'lib/fog/aws/requests/cdn/delete_streaming_distribution.rb', line 12 def delete_streaming_distribution(distribution_id, etag) request({ :expects => 204, :headers => { 'If-Match' => etag }, :idempotent => true, :method => 'DELETE', :path => "/streaming-distribution/#{distribution_id}" }) end |
#get_distribution(distribution_id) ⇒ Excon::Response
Get information about a distribution from CloudFront.
40 41 42 43 44 45 46 47 48 |
# File 'lib/fog/aws/requests/cdn/get_distribution.rb', line 40 def get_distribution(distribution_id) request({ :expects => 200, :idempotent => true, :method => 'GET', :parser => Fog::Parsers::AWS::CDN::Distribution.new, :path => "/distribution/#{distribution_id}" }) end |
#get_distribution_list(options = {}) ⇒ Excon::Response
Returns * body [Hash]:
* IsTruncated [Boolean] - Whether or not the listing is truncated.
* Marker [String] Marker specified for query.
* 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]:
* S3Origin [Hash]:
* DNSName [String] - Origin to associate with distribution, ie 'mybucket.s3.amazonaws.com'.
* OriginAccessIdentity [String] - Optional: Used when serving private content.
or
* CustomOrigin [Hash]:
* DNSName [String] - Origin to associate with distribution, ie 'www.example.com'.
* HTTPPort [Integer] - HTTP port of origin, in [80, 443] or (1024...65535).
* HTTPSPort [Integer] - HTTPS port of origin, in [80, 443] or (1024...65535).
* OriginProtocolPolicy [String] - Policy on using http vs https, in ['http-only', 'match-viewer'].
* Comment [String] - Comment associated with distribution.
* CNAME [Array] - Array of associated cnames.
* 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.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fog/aws/requests/cdn/get_distribution_list.rb', line 40 def get_distribution_list( = {}) request({ :expects => 200, :idempotent => true, :method => 'GET', :parser => Fog::Parsers::AWS::CDN::GetDistributionList.new, :path => "/distribution", :query => }) end |
#get_invalidation(distribution_id, invalidation_id) ⇒ Excon::Response
Get invalidation.
22 23 24 25 26 27 28 29 30 |
# File 'lib/fog/aws/requests/cdn/get_invalidation.rb', line 22 def get_invalidation(distribution_id, invalidation_id) request({ :expects => 200, :idempotent => true, :method => 'GET', :parser => Fog::Parsers::AWS::CDN::GetInvalidation.new, :path => "/distribution/#{distribution_id}/invalidation/#{invalidation_id}" }) end |
#get_invalidation_list(distribution_id, options = {}) ⇒ Excon::Response
Get invalidation list.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/fog/aws/requests/cdn/get_invalidation_list.rb', line 25 def get_invalidation_list(distribution_id, = {}) request({ :expects => 200, :idempotent => true, :method => 'GET', :parser => Fog::Parsers::AWS::CDN::GetInvalidationList.new, :path => "/distribution/#{distribution_id}/invalidation", :query => }) end |
#get_streaming_distribution(distribution_id) ⇒ Excon::Response
Get information about a streaming distribution from CloudFront.
33 34 35 36 37 38 39 40 41 |
# File 'lib/fog/aws/requests/cdn/get_streaming_distribution.rb', line 33 def get_streaming_distribution(distribution_id) request({ :expects => 200, :idempotent => true, :method => 'GET', :parser => Fog::Parsers::AWS::CDN::StreamingDistribution.new, :path => "/streaming-distribution/#{distribution_id}" }) end |
#get_streaming_distribution_list(options = {}) ⇒ Excon::Response
List information about distributions in CloudFront.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fog/aws/requests/cdn/get_streaming_distribution_list.rb', line 40 def get_streaming_distribution_list( = {}) request({ :expects => 200, :idempotent => true, :method => 'GET', :parser => Fog::Parsers::AWS::CDN::GetStreamingDistributionList.new, :path => "/streaming-distribution", :query => }) end |
#post_distribution(options = {}) ⇒ Excon::Response
Create a new distribution in CloudFront.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/fog/aws/requests/cdn/post_distribution.rb', line 53 def post_distribution( = {}) ['CallerReference'] = Time.now.to_i.to_s data = '<?xml version="1.0" encoding="UTF-8"?>' data << "<DistributionConfig xmlns=\"http://cloudfront.amazonaws.com/doc/#{@version}/\">" for key, value in case value when Array for item in value 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 |
#post_invalidation(distribution_id, paths, caller_reference = Time.now.to_i.to_s) ⇒ Excon::Response
List information about distributions in CloudFront.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fog/aws/requests/cdn/post_invalidation.rb', line 24 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({ :body => body, :expects => 201, :headers => {'Content-Type' => 'text/xml'}, :idempotent => true, :method => 'POST', :parser => Fog::Parsers::AWS::CDN::PostInvalidation.new, :path => "/distribution/#{distribution_id}/invalidation" }) end |
#post_streaming_distribution(options = {}) ⇒ Excon::Response
Create a new streaming distribution in CloudFront.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/fog/aws/requests/cdn/post_streaming_distribution.rb', line 40 def post_streaming_distribution( = {}) ['CallerReference'] = Time.now.to_i.to_s data = '<?xml version="1.0" encoding="UTF-8"?>' data << "<StreamingDistributionConfig xmlns=\"http://cloudfront.amazonaws.com/doc/#{@version}/\">" for key, value in case value when Array for item in value 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 << "</StreamingDistributionConfig>" request({ :body => data, :expects => 201, :headers => { 'Content-Type' => 'text/xml' }, :idempotent => true, :method => 'POST', :parser => Fog::Parsers::AWS::CDN::StreamingDistribution.new, :path => "/streaming-distribution" }) end |
#put_distribution_config(distribution_id, etag, options = {}) ⇒ Excon::Response
Update a distribution in CloudFront.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/fog/aws/requests/cdn/put_distribution_config.rb', line 54 def put_distribution_config(distribution_id, etag, = {}) data = '<?xml version="1.0" encoding="UTF-8"?>' data << "<DistributionConfig xmlns=\"http://cloudfront.amazonaws.com/doc/#{@version}/\">" for key, value in case value when Array for item in value 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 => 200, :headers => { 'Content-Type' => 'text/xml', 'If-Match' => etag }, :idempotent => true, :method => 'PUT', :parser => Fog::Parsers::AWS::CDN::Distribution.new, :path => "/distribution/#{distribution_id}/config" }) end |
#put_streaming_distribution_config(distribution_id, etag, options = {}) ⇒ Excon::Response
Update a streaming distribution in CloudFront.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/fog/aws/requests/cdn/put_streaming_distribution_config.rb', line 43 def put_streaming_distribution_config(distribution_id, etag, = {}) data = '<?xml version="1.0" encoding="UTF-8"?>' data << "<StreamingDistributionConfig xmlns=\"http://cloudfront.amazonaws.com/doc/#{@version}/\">" for key, value in case value when Array for item in value 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 << "</StreamingDistributionConfig>" request({ :body => data, :expects => 200, :headers => { 'Content-Type' => 'text/xml', 'If-Match' => etag }, :idempotent => true, :method => 'PUT', :parser => Fog::Parsers::AWS::CDN::StreamingDistribution.new, :path => "/streaming-distribution/#{distribution_id}/config" }) end |
#reload ⇒ Object
158 159 160 |
# File 'lib/fog/aws/cdn.rb', line 158 def reload @connection.reset end |