Class: Fog::Storage::Rackspace::Real
- Inherits:
-
Rackspace::Service
- Object
- Rackspace::Service
- Fog::Storage::Rackspace::Real
- Includes:
- Utils
- Defined in:
- lib/fog/rackspace/storage.rb,
lib/fog/rackspace/requests/storage/get_object.rb,
lib/fog/rackspace/requests/storage/put_object.rb,
lib/fog/rackspace/requests/storage/copy_object.rb,
lib/fog/rackspace/requests/storage/head_object.rb,
lib/fog/rackspace/requests/storage/delete_object.rb,
lib/fog/rackspace/requests/storage/get_container.rb,
lib/fog/rackspace/requests/storage/put_container.rb,
lib/fog/rackspace/requests/storage/get_containers.rb,
lib/fog/rackspace/requests/storage/head_container.rb,
lib/fog/rackspace/requests/storage/head_containers.rb,
lib/fog/rackspace/requests/storage/delete_container.rb,
lib/fog/rackspace/requests/storage/put_object_manifest.rb,
lib/fog/rackspace/requests/storage/get_object_https_url.rb,
lib/fog/rackspace/requests/storage/delete_multiple_objects.rb,
lib/fog/rackspace/requests/storage/put_static_obj_manifest.rb,
lib/fog/rackspace/requests/storage/put_dynamic_obj_manifest.rb,
lib/fog/rackspace/requests/storage/delete_static_large_object.rb,
lib/fog/rackspace/requests/storage/post_set_meta_temp_url_key.rb
Instance Attribute Summary collapse
-
#rackspace_cdn_ssl ⇒ Object
readonly
Returns the value of attribute rackspace_cdn_ssl.
Instance Method Summary collapse
-
#account ⇒ Fog::Storage::Rackspace::Account
Return Account Details.
- #authenticate ⇒ Object
-
#copy_object(source_container_name, source_object_name, target_container_name, target_object_name, options = {}) ⇒ Object
Copy object.
-
#delete_container(name) ⇒ Object
Delete an existing container.
-
#delete_multiple_objects(container, object_names, options = {}) ⇒ Excon::Response
Deletes multiple objects or containers with a single request.
-
#delete_object(container, object) ⇒ Object
Delete an existing object.
-
#delete_static_large_object(container, object, options = {}) ⇒ Excon::Response
Delete a static large object.
- #endpoint_uri(service_endpoint_url = nil) ⇒ Object
-
#get_container(container, options = {}) ⇒ Object
Get details for container and total bytes stored.
-
#get_containers(options = {}) ⇒ Object
List existing storage containers.
-
#get_object(container, object, &block) ⇒ Object
Get details for object.
-
#get_object_https_url(container, object, expires, options = {}) ⇒ Object
Get an expiring object https url from Cloud Files.
-
#head_container(container) ⇒ Object
List number of objects and total bytes stored.
-
#head_containers ⇒ Object
List number of containers and total bytes stored.
-
#head_object(container, object) ⇒ Object
Get headers for object.
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
-
#post_set_meta_temp_url_key(key) ⇒ Object
Set the account wide Temp URL Key.
-
#put_container(name, options = {}) ⇒ Object
Create a new container.
-
#put_dynamic_obj_manifest(container, object, options = {}) ⇒ Object
Create a new dynamic large object manifest.
-
#put_object(container, object, data, options = {}, &block) ⇒ Object
Create a new object.
-
#put_object_manifest(container, object, options = {}) ⇒ Object
Create a new dynamic large object manifest.
-
#put_static_obj_manifest(container, object, segments, options = {}) ⇒ Object
Create a new static large object manifest.
- #region ⇒ Object
-
#reload ⇒ Object
Resets presistent service connections.
- #request(params, parse_json = true, &block) ⇒ Object
- #request_id_header ⇒ Object
- #service_name ⇒ Object
- #service_net? ⇒ Boolean
-
#ssl? ⇒ Boolean
Using SSL?.
Methods included from Utils
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/fog/rackspace/storage.rb', line 105 def initialize(={}) require 'mime/types' @rackspace_api_key = [:rackspace_api_key] @rackspace_username = [:rackspace_username] @rackspace_cdn_ssl = [:rackspace_cdn_ssl] @rackspace_auth_url = [:rackspace_auth_url] @rackspace_servicenet = [:rackspace_servicenet] @rackspace_auth_token = [:rackspace_auth_token] @rackspace_storage_url = [:rackspace_storage_url] @rackspace_cdn_url = [:rackspace_cdn_url] @rackspace_region = [:rackspace_region] || :dfw @rackspace_temp_url_key = [:rackspace_temp_url_key] @rackspace_must_reauthenticate = false @connection_options = [:connection_options] || {} authenticate @persistent = [:persistent] || false Excon.defaults[:ssl_verify_peer] = false if service_net? @connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options) end |
Instance Attribute Details
#rackspace_cdn_ssl ⇒ Object (readonly)
Returns the value of attribute rackspace_cdn_ssl.
103 104 105 |
# File 'lib/fog/rackspace/storage.rb', line 103 def rackspace_cdn_ssl @rackspace_cdn_ssl end |
Instance Method Details
#account ⇒ Fog::Storage::Rackspace::Account
Return Account Details
128 129 130 131 |
# File 'lib/fog/rackspace/storage.rb', line 128 def account account = Fog::Storage::Rackspace::Account.new(:service => self) account.reload end |
#authenticate ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/fog/rackspace/storage.rb', line 161 def authenticate if @rackspace_must_reauthenticate || @rackspace_auth_token.nil? = { :rackspace_api_key => @rackspace_api_key, :rackspace_username => @rackspace_username, :rackspace_auth_url => @rackspace_auth_url, :connection_options => @connection_options } super() else @auth_token = @rackspace_auth_token @uri = URI.parse(@rackspace_storage_url) end end |
#copy_object(source_container_name, source_object_name, target_container_name, target_object_name, options = {}) ⇒ Object
Copy object
Parameters
-
source_container_name<~String> - Name of source bucket
-
source_object_name<~String> - Name of source object
-
target_container_name<~String> - Name of bucket to create copy in
-
target_object_name<~String> - Name for new copy of object
-
options<~Hash> - Additional headers
18 19 20 21 22 23 24 25 26 |
# File 'lib/fog/rackspace/requests/storage/copy_object.rb', line 18 def copy_object(source_container_name, source_object_name, target_container_name, target_object_name, ={}) headers = { 'X-Copy-From' => "/#{source_container_name}/#{source_object_name}" }.merge() request({ :expects => 201, :headers => headers, :method => 'PUT', :path => "#{Fog::Rackspace.escape(target_container_name)}/#{Fog::Rackspace.escape(target_object_name)}" }) end |
#delete_container(name) ⇒ Object
Delete an existing container
Parameters
-
name<~String> - Name of container to delete
14 15 16 17 18 19 20 |
# File 'lib/fog/rackspace/requests/storage/delete_container.rb', line 14 def delete_container(name) request( :expects => 204, :method => 'DELETE', :path => Fog::Rackspace.escape(name) ) end |
#delete_multiple_objects(container, object_names, options = {}) ⇒ Excon::Response
Deletes multiple objects or containers with a single request.
To delete objects from a single container, container
may be provided and object_names
should be an Array of object names within the container.
To delete objects from multiple containers or delete containers, container
should be nil
and all object_names
should be prefixed with a container name.
Containers must be empty when deleted. object_names
are processed in the order given, so objects within a container should be listed first to empty the container.
Up to 10,000 objects may be deleted in a single request. The server will respond with 200 OK for all requests. response.body
must be inspected for actual results.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/fog/rackspace/requests/storage/delete_multiple_objects.rb', line 54 def delete_multiple_objects(container, object_names, = {}) body = object_names.map do |name| object_name = container ? "#{ container }/#{ name }" : name URI.encode(object_name) end.join("\n") response = request({ :expects => 200, :method => 'DELETE', :headers => .merge('Content-Type' => 'text/plain', 'Accept' => 'application/json'), :body => body, :query => { 'bulk-delete' => true } }, false) response.body = Fog::JSON.decode(response.body) response end |
#delete_object(container, object) ⇒ Object
Delete an existing object
Parameters
-
container<~String> - Name of container to delete
-
object<~String> - Name of object to delete
15 16 17 18 19 20 21 |
# File 'lib/fog/rackspace/requests/storage/delete_object.rb', line 15 def delete_object(container, object) request( :expects => 204, :method => 'DELETE', :path => "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}" ) end |
#delete_static_large_object(container, object, options = {}) ⇒ Excon::Response
Delete a static large object.
Deletes the SLO manifest object
and all segments that it references. The server will respond with 200 OK for all requests. response.body
must be inspected for actual results.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fog/rackspace/requests/storage/delete_static_large_object.rb', line 33 def delete_static_large_object(container, object, = {}) response = request({ :expects => 200, :method => 'DELETE', :headers => .merge('Content-Type' => 'text/plain', 'Accept' => 'application/json'), :path => "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}", :query => { 'multipart-manifest' => 'delete' } }, false) response.body = Fog::JSON.decode(response.body) response end |
#endpoint_uri(service_endpoint_url = nil) ⇒ Object
188 189 190 191 192 193 194 |
# File 'lib/fog/rackspace/storage.rb', line 188 def endpoint_uri(service_endpoint_url=nil) return @uri if @uri @uri = super(@rackspace_storage_url || service_endpoint_url, :rackspace_storage_url) @uri.host = "snet-#{@uri.host}" if service_net? @uri end |
#get_container(container, options = {}) ⇒ Object
Get details for container and total bytes stored
Parameters
-
container<~String> - Name of container to retrieve info for
-
options<~String>:
-
‘limit’<~String> - Maximum number of objects to return
-
‘marker’<~String> - Only return objects whose name is greater than marker
-
‘prefix’<~String> - Limits results to those starting with prefix
-
‘path’<~String> - Return objects nested in the pseudo path
-
Returns
-
response<~Excon::Response>:
-
headers<~Hash>:
-
‘X-Account-Container-Count’<~String> - Count of containers
-
‘X-Account-Bytes-Used’<~String> - Bytes used
-
-
body<~Array>:
-
‘bytes’<~Integer> - Number of bytes used by container
-
‘count’<~Integer> - Number of items in container
-
‘name’<~String> - Name of container
-
item<~Hash>:
-
‘bytes’<~String> - Size of object
-
‘content_type’<~String> Content-Type of object
-
‘hash’<~String> - Hash of object (etag?)
-
‘last_modified’<~String> - Last modified timestamp
-
‘name’<~String> - Name of object
-
-
-
35 36 37 38 39 40 41 42 43 |
# File 'lib/fog/rackspace/requests/storage/get_container.rb', line 35 def get_container(container, = {}) = .reject {|key, value| value.nil?} request( :expects => 200, :method => 'GET', :path => Fog::Rackspace.escape(container), :query => {'format' => 'json'}.merge!() ) end |
#get_containers(options = {}) ⇒ Object
List existing storage containers
Parameters
-
options<~Hash>:
-
‘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<~Hash>:
-
‘bytes’<~Integer>: - Number of bytes used by container
-
‘count’<~Integer>: - Number of items in container
-
‘name’<~String>: - Name of container
-
-
-
24 25 26 27 28 29 30 31 32 |
# File 'lib/fog/rackspace/requests/storage/get_containers.rb', line 24 def get_containers( = {}) = .reject {|key, value| value.nil?} request( :expects => [200, 204], :method => 'GET', :path => '', :query => {'format' => 'json'}.merge!() ) end |
#get_object(container, object, &block) ⇒ Object
Get details for object
Parameters
-
container<~String> - Name of container to look in
-
object<~String> - Name of object to look for
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fog/rackspace/requests/storage/get_object.rb', line 15 def get_object(container, object, &block) params = {} if block_given? params[:response_block] = Proc.new end request(params.merge!({ :expects => 200, :method => 'GET', :path => "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}" }), false, &block) end |
#get_object_https_url(container, object, expires, options = {}) ⇒ Object
Get an expiring object https url from Cloud Files
Parameters
-
container<~String> - Name of container containing object
-
object<~String> - Name of object to get expiring url for
-
expires<~Time> - An expiry time for this url
Returns
-
response<~Excon::Response>:
-
body<~String> - url for object
-
See Also
docs.rackspace.com/files/api/v1/cf-devguide/content/Create_TempURL-d1a444.html
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fog/rackspace/requests/storage/get_object_https_url.rb', line 23 def get_object_https_url(container, object, expires, = {}) if @rackspace_temp_url_key.nil? raise ArgumentError, "Storage must my instantiated with the :rackspace_temp_url_key option" end method = 'GET' expires = expires.to_i object_path_escaped = "#{@uri.path}/#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object,"/")}" object_path_unescaped = "#{@uri.path}/#{Fog::Rackspace.escape(container)}/#{object}" string_to_sign = "#{method}\n#{expires}\n#{object_path_unescaped}" hmac = Fog::HMAC.new('sha1', @rackspace_temp_url_key) sig = sig_to_hex(hmac.sign(string_to_sign)) "https://#{@uri.host}#{object_path_escaped}?temp_url_sig=#{sig}&temp_url_expires=#{expires}" end |
#head_container(container) ⇒ Object
List number of objects and total bytes stored
Parameters
-
container<~String> - Name of container to retrieve info for
Returns
-
response<~Excon::Response>:
-
headers<~Hash>:
-
‘X-Container-Object-Count’<~String> - Count of containers
-
‘X-Container-Bytes-Used’<~String> - Bytes used
-
-
20 21 22 23 24 25 26 27 |
# File 'lib/fog/rackspace/requests/storage/head_container.rb', line 20 def head_container(container) request( :expects => 204, :method => 'HEAD', :path => Fog::Rackspace.escape(container), :query => {'format' => 'json'} ) end |
#head_containers ⇒ Object
List number of containers and total bytes stored
Returns
-
response<~Excon::Response>:
-
headers<~Hash>:
-
‘X-Account-Container-Count’<~String> - Count of containers
-
‘X-Account-Bytes-Used’<~String> - Bytes used
-
-
17 18 19 20 21 22 23 24 |
# File 'lib/fog/rackspace/requests/storage/head_containers.rb', line 17 def head_containers request( :expects => 204, :method => 'HEAD', :path => '', :query => {'format' => 'json'} ) end |
#head_object(container, object) ⇒ Object
Get headers for object
Parameters
-
container<~String> - Name of container to look in
-
object<~String> - Name of object to look for
15 16 17 18 19 20 21 |
# File 'lib/fog/rackspace/requests/storage/head_object.rb', line 15 def head_object(container, object) request({ :expects => 200, :method => 'HEAD', :path => "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}" }, false) end |
#post_set_meta_temp_url_key(key) ⇒ Object
Set the account wide Temp URL Key. This is a secret key that’s used to generate signed expiring URLs.
Once the key has been set with this request you should create new Storage objects with the :rackspace_temp_url_key option then use the get_object_https_url method to generate expiring URLs.
*** CAUTION *** changing this secret key will invalidate any expiring URLS generated with old keys.
Parameters
-
key<~String> - The new Temp URL Key
Returns
-
response<~Excon::Response>
See Also
docs.rackspace.com/files/api/v1/cf-devguide/content/Set_Account_Metadata-d1a4460.html
28 29 30 31 32 33 34 |
# File 'lib/fog/rackspace/requests/storage/post_set_meta_temp_url_key.rb', line 28 def (key) request( :expects => [201, 202, 204], :method => 'POST', :headers => {'X-Account-Meta-Temp-Url-Key' => key} ) end |
#put_container(name, options = {}) ⇒ Object
Create a new container
Parameters
-
name<~String> - Name for container, should be < 256 bytes and must not contain ‘/’
14 15 16 17 18 19 20 21 |
# File 'lib/fog/rackspace/requests/storage/put_container.rb', line 14 def put_container(name, ={}) request( :expects => [201, 202], :method => 'PUT', :headers => , :path => Fog::Rackspace.escape(name) ) end |
#put_dynamic_obj_manifest(container, object, options = {}) ⇒ Object
Create a new dynamic large object manifest
Creates an object with a X-Object-Manifest
header that specifies the common prefix (“<container>/<prefix>”) for all uploaded segments. Retrieving the manifest object streams all segments matching this prefix. Segments must sort in the order they should be concatenated. Note that any future objects stored in the container along with the segments that match the prefix will be included when retrieving the manifest object.
All segments must be stored in the same container, but may be in a different container than the manifest object. The default X-Object-Manifest
header is set to “container
/object
”, but may be overridden in options
to specify the prefix and/or the container where segments were stored. If overridden, names should be CGI escaped (excluding spaces) if needed (see Rackspace.escape).
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fog/rackspace/requests/storage/put_dynamic_obj_manifest.rb', line 30 def put_dynamic_obj_manifest(container, object, = {}) path = "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}" headers = {'X-Object-Manifest' => path}.merge() request( :expects => 201, :headers => headers, :method => 'PUT', :path => path ) end |
#put_object(container, object, data, options = {}, &block) ⇒ Object
Create a new object
Parameters
-
container<~String> - Name for container, should be < 256 bytes and must not contain ‘/’
-
object<~String> - Name for object
-
data<~String|File> - data to upload
-
options<~Hash> - config headers for object. Defaults to {}.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/fog/rackspace/requests/storage/put_object.rb', line 17 def put_object(container, object, data, = {}, &block) data = Fog::Storage.parse_data(data) headers = data[:headers].merge!() params = block_given? ? { :request_block => block } : { :body => data[:body] } params.merge!( :expects => 201, :idempotent => !params[:request_block], :headers => headers, :method => 'PUT', :path => "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}" ) request(params) end |
#put_object_manifest(container, object, options = {}) ⇒ Object
Create a new dynamic large object manifest
This is an alias for #put_dynamic_obj_manifest for backward compatibility.
9 10 11 |
# File 'lib/fog/rackspace/requests/storage/put_object_manifest.rb', line 9 def put_object_manifest(container, object, = {}) put_dynamic_obj_manifest(container, object, ) end |
#put_static_obj_manifest(container, object, segments, options = {}) ⇒ Object
Create a new static large object manifest.
A static large object is similar to a dynamic large object. Whereas a GET for a dynamic large object manifest will stream segments based on the manifest’s X-Object-Manifest
object name prefix, a static large object manifest streams segments which are defined by the user within the manifest. Information about each segment is provided in segments
as an Array of Hash objects, ordered in the sequence which the segments should be streamed.
When the SLO manifest is received, each segment’s etag
and size_bytes
will be verified. The etag
for each segment is returned in the response to #put_object, but may also be calculated. e.g. Digest::MD5.hexdigest(segment_data)
The maximum number of segments for a static large object is 1000, and all segments (except the last) must be at least 1 MiB in size. Unlike a dynamic large object, segments are not required to be in the same container.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fog/rackspace/requests/storage/put_static_obj_manifest.rb', line 44 def put_static_obj_manifest(container, object, segments, = {}) request( :expects => 201, :method => 'PUT', :headers => , :body => Fog::JSON.encode(segments), :path => "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}", :query => { 'multipart-manifest' => 'put' } ) end |
#region ⇒ Object
184 185 186 |
# File 'lib/fog/rackspace/storage.rb', line 184 def region @rackspace_region end |
#reload ⇒ Object
Resets presistent service connections
141 142 143 |
# File 'lib/fog/rackspace/storage.rb', line 141 def reload @connection.reset end |
#request(params, parse_json = true, &block) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/fog/rackspace/storage.rb', line 145 def request(params, parse_json = true, &block) super(params, parse_json, &block) rescue Excon::Errors::NotFound => error raise NotFound.slurp(error, self) rescue Excon::Errors::BadRequest => error raise BadRequest.slurp(error, self) rescue Excon::Errors::InternalServerError => error raise InternalServerError.slurp(error, self) rescue Excon::Errors::HTTPStatusError => error raise ServiceError.slurp(error, self) end |
#request_id_header ⇒ Object
180 181 182 |
# File 'lib/fog/rackspace/storage.rb', line 180 def request_id_header "X-Trans-Id" end |
#service_name ⇒ Object
176 177 178 |
# File 'lib/fog/rackspace/storage.rb', line 176 def service_name :cloudFiles end |
#service_net? ⇒ Boolean
157 158 159 |
# File 'lib/fog/rackspace/storage.rb', line 157 def service_net? @rackspace_servicenet == true end |
#ssl? ⇒ Boolean
Using SSL?
136 137 138 |
# File 'lib/fog/rackspace/storage.rb', line 136 def ssl? !rackspace_cdn_ssl.nil? end |