Class: Fog::CDN::Rackspace::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/cdn/rackspace.rb,
lib/fog/cdn/requests/rackspace/put_container.rb,
lib/fog/cdn/requests/rackspace/get_containers.rb,
lib/fog/cdn/requests/rackspace/head_container.rb,
lib/fog/cdn/requests/rackspace/post_container.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fog/cdn/rackspace.rb', line 44

def initialize(options={})
  require 'multi_json'
  credentials = Fog::Rackspace.authenticate(options)
  @auth_token = credentials['X-Auth-Token']
  @enabled = false

  if credentials['X-CDN-Management-Url']
    uri = URI.parse(credentials['X-CDN-Management-Url'])
    @host   = uri.host
    @path   = uri.path
    @port   = uri.port
    @scheme = uri.scheme
    @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
    @enabled = true
  end
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/fog/cdn/rackspace.rb', line 61

def enabled?
  @enabled
end

#get_containers(options = {}) ⇒ Object

List existing cdn-enabled storage containers

Parameters

  • options<~Hash>:

    • ‘enabled_only’<~Boolean> - Set to true to limit results to cdn enabled containers

    • ‘limit’<~Integer> - Upper limit to number of results returned

    • ‘marker’<~String> - Only return objects with name greater than this value

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • container<~String>: Name of container



18
19
20
21
22
23
24
25
26
# File 'lib/fog/cdn/requests/rackspace/get_containers.rb', line 18

def get_containers(options = {})
  response = request(
    :expects  => [200, 204],
    :method   => 'GET',
    :path     => '',
    :query    => {'format' => 'json'}.merge!(options)
  )
  response
end

#head_container(container) ⇒ Object

List cdn properties for a container

Parameters

  • container<~String> - Name of container to retrieve info for

Returns

  • response<~Excon::Response>:

    • headers<~Hash>:

      • ‘X-CDN-Enabled’<~Boolean> - cdn status for container

      • ‘X-CDN-URI’<~String> - cdn url for this container

      • ‘X-TTL’<~String> - integer seconds before data expires, defaults to 86400 (1 day)

      • ‘X-Log-Retention’<~Boolean> - ?

      • ‘X-User-Agent-ACL’<~String> - ?

      • ‘X-Referrer-ACL’<~String> - ?



20
21
22
23
24
25
26
27
28
# File 'lib/fog/cdn/requests/rackspace/head_container.rb', line 20

def head_container(container)
  response = request(
    :expects  => 204,
    :method   => 'HEAD',
    :path     => container,
    :query    => {'format' => 'json'}
  )
  response
end

#post_container(name, options = {}) ⇒ Object

modify CDN properties for a container

Parameters

  • name<~String> - Name for container, should be < 256 bytes and must not contain ‘/’

# options<~Hash>:

* 'X-CDN-Enabled'<~Boolean> - cdn status for container
* 'X-CDN-URI'<~String> - cdn url for this container
* 'X-TTL'<~String> - integer seconds before data expires, defaults to 86400 (1 day), in 3600..259200
* 'X-Log-Retention'<~Boolean> - ?
* 'X-User-Agent-ACL'<~String> - ?
* 'X-Referrer-ACL'<~String> - ?


17
18
19
20
21
22
23
24
25
# File 'lib/fog/cdn/requests/rackspace/post_container.rb', line 17

def post_container(name, options = {})
  response = request(
    :expects  => [201, 202],
    :headers  => options,
    :method   => 'POST',
    :path     => CGI.escape(name)
  )
  response
end

#put_container(name, options = {}) ⇒ Object

enable CDN for a container

Parameters

  • name<~String> - Name for container, should be < 256 bytes and must not contain ‘/’

# options<~Hash>:

* 'X-CDN-Enabled'<~Boolean> - cdn status for container
* 'X-CDN-URI'<~String> - cdn url for this container
* 'X-TTL'<~String> - integer seconds before data expires, defaults to 86400 (1 day), in 3600..259200
* 'X-Log-Retention'<~Boolean> - ?
* 'X-User-Agent-ACL'<~String> - ?
* 'X-Referrer-ACL'<~String> - ?


17
18
19
20
21
22
23
24
25
# File 'lib/fog/cdn/requests/rackspace/put_container.rb', line 17

def put_container(name, options = {})
  response = request(
    :expects  => [201, 202],
    :headers  => options,
    :method   => 'PUT',
    :path     => CGI.escape(name)
  )
  response
end

#reloadObject



65
66
67
# File 'lib/fog/cdn/rackspace.rb', line 65

def reload
  @cdn_connection.reset
end

#request(params, parse_json = true) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/fog/cdn/rackspace.rb', line 69

def request(params, parse_json = true)
  begin
    response = @connection.request(params.merge!({
      :headers  => {
        'Content-Type' => 'application/json',
        'X-Auth-Token' => @auth_token
      }.merge!(params[:headers] || {}),
      :host     => @host,
      :path     => "#{@path}/#{params[:path]}",
    }))
  rescue Excon::Errors::HTTPStatusError => error
    raise case error
    when Excon::Errors::NotFound
      Fog::Rackspace::Storage::NotFound.slurp(error)
    else
      error
    end
  end
  if !response.body.empty? && parse_json && response.headers['Content-Type'] =~ %r{application/json}
    response.body = MultiJson.decode(response.body)
  end
  response
end