Class: Fog::CDN::HP::Real
- Inherits:
-
Object
- Object
- Fog::CDN::HP::Real
- Includes:
- Utils
- Defined in:
- lib/fog/hp/cdn.rb,
lib/fog/hp/requests/cdn/put_container.rb,
lib/fog/hp/requests/cdn/get_containers.rb,
lib/fog/hp/requests/cdn/head_container.rb,
lib/fog/hp/requests/cdn/post_container.rb,
lib/fog/hp/requests/cdn/delete_container.rb
Instance Method Summary collapse
-
#delete_container(name) ⇒ Object
Delete an existing container.
- #enabled? ⇒ Boolean
-
#get_containers(options = {}) ⇒ Object
List existing cdn-enabled storage containers.
-
#head_container(name) ⇒ Object
List cdn properties for a container.
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
-
#post_container(name, options = {}) ⇒ Object
modify CDN properties for a container.
-
#put_container(name, options = {}) ⇒ Object
enable CDN for a container.
- #reload ⇒ Object
- #request(params, parse_json = true, &block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
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 87 88 89 90 91 92 93 94 |
# File 'lib/fog/hp/cdn.rb', line 58 def initialize(={}) @connection_options = [:connection_options] || {} ### Set an option to use the style of authentication desired; :v1 or :v2 (default) auth_version = [:hp_auth_version] || :v2 ### Pass the service type for object storage to the authentication call [:hp_service_type] = "hpext:cdn" ### Make the authentication call if (auth_version == :v2) # Call the control services authentication credentials = Fog::HP.authenticate_v2(, @connection_options) ### When using the v2 CS authentication, the CDN Mgmt comes from the service catalog @hp_cdn_uri = credentials[:endpoint_url] cdn_mgmt_url = @hp_cdn_uri else # Call the legacy v1.0/v1.1 authentication credentials = Fog::HP.authenticate_v1(, @connection_options) # In case of legacy authentication systems, the user can pass the CDN Mgmt Uri @hp_cdn_uri = [:hp_cdn_uri] || "https://region-a.geo-1.cdnmgmt.hpcloudsvc.com/v1.0" # In case of legacy authentication systems, the :cdn_endpoint_url will carry the cdn storage url cdn_mgmt_url = "#{@hp_cdn_uri}#{URI.parse(credentials[:cdn_endpoint_url]).path}" end @auth_token = credentials[:auth_token] @enabled = false @persistent = [:persistent] || false if cdn_mgmt_url uri = URI.parse(cdn_mgmt_url) @host = uri.host @path = uri.path.chomp("/") @port = uri.port @scheme = uri.scheme @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) @enabled = true end end |
Instance Method Details
#delete_container(name) ⇒ Object
Delete an existing container
Parameters
-
name<~String> - Name of container to delete
11 12 13 14 15 16 17 18 |
# File 'lib/fog/hp/requests/cdn/delete_container.rb', line 11 def delete_container(name) response = request( :expects => 204, :method => 'DELETE', :path => Fog::HP.escape(name) ) response end |
#enabled? ⇒ Boolean
96 97 98 |
# File 'lib/fog/hp/cdn.rb', line 96 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/hp/requests/cdn/get_containers.rb', line 18 def get_containers( = {}) response = request( :expects => [200, 204], :method => 'GET', :path => '', :query => {'format' => 'json'}.merge!() ) response end |
#head_container(name) ⇒ Object
List cdn properties for a container
Parameters
-
name<~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> - ?
-
-
18 19 20 21 22 23 24 25 26 |
# File 'lib/fog/hp/requests/cdn/head_container.rb', line 18 def head_container(name) response = request( :expects => 204, :method => 'HEAD', :path => Fog::HP.escape(name), :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 900 (15 min.) to 1577836800 (50 years)
* 'X-Log-Retention'<~Boolean> - ?
15 16 17 18 19 20 21 22 23 |
# File 'lib/fog/hp/requests/cdn/post_container.rb', line 15 def post_container(name, = {}) response = request( :expects => [201, 202], :headers => , :method => 'POST', :path => Fog::HP.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 900 (15 min.) to 1577836800 (50 years)
* 'X-Log-Retention'<~Boolean> - ?
15 16 17 18 19 20 21 22 23 |
# File 'lib/fog/hp/requests/cdn/put_container.rb', line 15 def put_container(name, = {}) response = request( :expects => [201, 202], :headers => , :method => 'PUT', :path => Fog::HP.escape(name) ) response end |
#reload ⇒ Object
100 101 102 |
# File 'lib/fog/hp/cdn.rb', line 100 def reload @cdn_connection.reset end |
#request(params, parse_json = true, &block) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/fog/hp/cdn.rb', line 104 def request(params, parse_json = true, &block) 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]}", }), &block) rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound Fog::CDN::HP::NotFound.slurp(error) else error end end if !response.body.empty? && parse_json && response.headers['Content-Type'] =~ %r{application/json} response.body = Fog::JSON.decode(response.body) end response end |