Class: Fog::Storage::Ninefold::Real
- Inherits:
-
Object
- Object
- Fog::Storage::Ninefold::Real
- Includes:
- Utils
- Defined in:
- lib/fog/storage/ninefold.rb,
lib/fog/storage/requests/ninefold/get_namespace.rb,
lib/fog/storage/requests/ninefold/put_namespace.rb,
lib/fog/storage/requests/ninefold/post_namespace.rb,
lib/fog/storage/requests/ninefold/delete_namespace.rb
Instance Method Summary collapse
- #delete_namespace(namespace = '', options = {}) ⇒ Object
- #get_namespace(namespace = '', options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
- #post_namespace(namespace = '', options = {}) ⇒ Object
- #put_namespace(namespace = '', options = {}) ⇒ Object
- #reload ⇒ Object
- #request(params, &block) ⇒ Object
- #sign(string) ⇒ Object
- #uid ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
48 49 50 51 52 53 54 55 56 |
# File 'lib/fog/storage/ninefold.rb', line 48 def initialize(={}) require 'mime/types' @ninefold_storage_token = [:ninefold_storage_token] @ninefold_storage_secret = [:ninefold_storage_secret] @ninefold_storage_secret_decoded = Base64.decode64( @ninefold_storage_secret ) Excon.ssl_verify_peer = false if [:rackspace_servicenet] == true @connection = Fog::Connection.new("#{Fog::Storage::Ninefold::STORAGE_SCHEME}://#{Fog::Storage::Ninefold::STORAGE_HOST}:#{Fog::Storage::Ninefold::STORAGE_PORT}", true) # persistent end |
Instance Method Details
#delete_namespace(namespace = '', options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/storage/requests/ninefold/delete_namespace.rb', line 6 def delete_namespace(namespace = '', = {}) = .reject {|key, value| value.nil?} request({ :expects => 204, :method => 'DELETE', :path => "namespace/" + namespace, :query => }.merge()) end |
#get_namespace(namespace = '', options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fog/storage/requests/ninefold/get_namespace.rb', line 6 def get_namespace(namespace = '', = {}) = .reject {|key, value| value.nil?} request({ :expects => 200, :method => 'GET', :path => "namespace/" + namespace, :query => {}, :parse => true }.merge()) end |
#post_namespace(namespace = '', options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fog/storage/requests/ninefold/post_namespace.rb', line 6 def post_namespace(namespace = '', = {}) = .reject {|key, value| value.nil?} request({ :expects => 201, :method => 'POST', :path => "namespace/" + namespace, :query => {}, :parse => true }.merge()) end |
#put_namespace(namespace = '', options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fog/storage/requests/ninefold/put_namespace.rb', line 6 def put_namespace(namespace = '', = {}) = .reject {|key, value| value.nil?} request({ :expects => 200, :method => 'PUT', :path => "namespace/" + namespace, :query => {}, :parse => true }.merge()) end |
#reload ⇒ Object
67 68 69 |
# File 'lib/fog/storage/ninefold.rb', line 67 def reload @connection.reset end |
#request(params, &block) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/fog/storage/ninefold.rb', line 71 def request(params, &block) req_path = params[:path] # Force set host and port params.merge!({ :host => Fog::Storage::Ninefold::STORAGE_HOST, :path => "#{Fog::Storage::Ninefold::STORAGE_PATH}/rest/#{params[:path]}", }) # Set default method and headers params = {:method => 'GET', :headers => {}}.merge params params[:headers]["Content-Type"] ||= "application/octet-stream" # Add request date params[:headers]["date"] = Time.now().httpdate() params[:headers]["x-emc-uid"] = @ninefold_storage_token # Build signature string signstring = "" signstring += params[:method] signstring += "\n" signstring += params[:headers]["Content-Type"] signstring += "\n" if( params[:headers]["range"] ) signstring += params[:headers]["range"] end signstring += "\n" signstring += params[:headers]["date"] signstring += "\n" signstring += "/rest/" + URI.unescape( req_path ).downcase query_str = params[:query].map{|k,v| "#{k}=#{v}"}.join('&') signstring += '?' + query_str unless query_str.empty? signstring += "\n" customheaders = {} params[:headers].each { |key,value| if key == "x-emc-date" #skip elsif key =~ /^x-emc-/ customheaders[ key.downcase ] = value end } header_arr = customheaders.sort() first = true header_arr.each { |key,value| # Values are lowercase and whitespace-normalized signstring += key + ":" + value.strip.chomp.squeeze( " " ) + "\n" } digest = ::HMAC::SHA1.digest( @ninefold_storage_secret_decoded, signstring.chomp() ) signature = Base64.encode64( digest ).chomp() params[:headers]["x-emc-signature"] = signature begin response = @connection.request(params, &block) rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound Fog::Storage::Ninefold::NotFound.slurp(error) else error end end unless response.body.empty? if params[:parse] document = Fog::ToHashDocument.new parser = Nokogiri::XML::SAX::PushParser.new(document) parser << response.body parser.finish response.body = document.body end end response end |
#sign(string) ⇒ Object
62 63 64 65 |
# File 'lib/fog/storage/ninefold.rb', line 62 def sign(string) value = ::HMAC::SHA1.digest( @ninefold_storage_secret_decoded, string ) Base64.encode64( value ).chomp() end |
#uid ⇒ Object
58 59 60 |
# File 'lib/fog/storage/ninefold.rb', line 58 def uid @ninefold_storage_token#.split('/')[-1] end |