Class: Fog::AWS::CDN::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/aws/cdn.rb,
lib/fog/aws/requests/cdn/get_distribution.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

Instance Method Summary collapse

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.



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/fog/aws/cdn.rb', line 64

def initialize(options={})
  @aws_access_key_id = options[:aws_access_key_id]
  @aws_secret_access_key = options[:aws_secret_access_key]
  @hmac     = Fog::HMAC.new('sha1', @aws_secret_access_key)
  @host     = options[:host]      || 'cloudfront.amazonaws.com'
  @path     = options[:path]      || '/'
  @port     = options[:port]      || 443
  @scheme   = options[:scheme]    || 'https'
  @version  = options[:version]  || '2010-08-01'
  @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", options[:persistent] || true)
end

Instance Method Details

#delete_distribution(distribution_id, etag) ⇒ Object

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

docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/DeleteDistribution.html



15
16
17
18
19
20
21
22
23
# File 'lib/fog/aws/requests/cdn/delete_distribution.rb', line 15

def delete_distribution(distribution_id, etag)
  request({
    :expects    => 204,
    :headers    => { 'If-Match' => etag },
    :idempotent => true,
    :method     => 'DELETE',
    :path       => "/distribution/#{distribution_id}"
  })
end

#get_distribution(distribution_id) ⇒ Object

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

docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/GetDistribution.html



34
35
36
37
38
39
40
41
42
# File 'lib/fog/aws/requests/cdn/get_distribution.rb', line 34

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 = {}) ⇒ Object

List information about distributions in CloudFront

Parameters

  • options<~Hash> - config arguments for list. Defaults to {}.

    • ‘Marker’<~String> - limits object keys to only those that appear lexicographically after its value.

    • ‘MaxItems’<~Integer> - limits number of object keys returned

Returns

  • response<~Excon::Response>:

    • 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>:

        • ‘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

docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/ListDistributions.html



37
38
39
40
41
42
43
44
45
46
# File 'lib/fog/aws/requests/cdn/get_distribution_list.rb', line 37

def get_distribution_list(options = {})
  request({
    :expects    => 200,
    :idempotent => true,
    :method   => 'GET',
    :parser   => Fog::Parsers::AWS::CDN::GetDistributionList.new,
    :path       => "/distribution",
    :query      => options
  })
end

#post_distribution(origin, options = {}) ⇒ Object

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

docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/CreateDistribution.html



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/post_distribution.rb', line 46

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

#post_invalidation(distribution_id, paths, caller_reference = Time.now.to_i.to_s) ⇒ Object

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

docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/CreateInvalidation.html



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fog/aws/requests/cdn/post_invalidation.rb', line 29

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

#reloadObject



76
77
78
# File 'lib/fog/aws/cdn.rb', line 76

def reload
  @connection.reset
end