# File lib/fog/hp/storage.rb, line 47 def cdn unless @hp_cdn_uri.nil? @cdn ||= Fog::CDN.new( :provider => 'HP', :hp_access_key => @hp_access_key, :hp_secret_key => @hp_secret_key, :hp_auth_uri => @hp_auth_uri, :hp_cdn_uri => @hp_cdn_uri, :hp_tenant_id => @hp_tenant_id, :hp_avl_zone => @hp_avl_zone, :connection_options => @connection_options ) if @cdn.enabled? @cdn end else nil end end
# File lib/fog/hp/storage.rb, line 147 def generate_object_temp_url(container, object, expires_secs, method) return unless (container && object && expires_secs && method) # POST not allowed allowed_methods = %{GET PUT HEAD} unless allowed_methods.include?(method) raise ArgumentError.new("Invalid method '#{method}' specified. Valid methods are: #{allowed_methods.join(', ')}") end expires = (Time.now + expires_secs.to_i).to_i # split up the storage uri uri = URI.parse(@hp_storage_uri) host = uri.host path = uri.path port = uri.port scheme = uri.scheme # do not encode before signature generation, encode after sig_path = "#{path}/#{container}/#{object}" encoded_path = "#{path}/#{Fog::HP.escape(container)}/#{Fog::HP.escape(object)}" string_to_sign = "#{method}\n#{expires}\n#{sig_path}" # Only works with 1.9+ Not compatible with 1.8.7 #signed_string = Digest::HMAC.hexdigest(string_to_sign, @hp_secret_key, Digest::SHA1) # Compatible with 1.8.7 onwards hmac = OpenSSL::HMAC.new(@hp_secret_key, OpenSSL::Digest::SHA1.new) signed_string = hmac.update(string_to_sign).hexdigest signature = @hp_tenant_id.to_s + ":" + @hp_access_key.to_s + ":" + signed_string signature = Fog::HP.escape(signature) # generate the temp url using the signature and expiry "#{scheme}://#{host}:#{port}#{encoded_path}?temp_url_sig=#{signature}&temp_url_expires=#{expires}" end
# File lib/fog/hp/storage.rb, line 140 def header_to_perm_acl(read_header=nil, write_header=nil) read_h, write_h = nil read_h = read_header.split(',') unless read_header.nil? write_h = write_header.split(',') unless write_header.nil? return read_h, write_h end
# File lib/fog/hp/storage.rb, line 126 def perm_acl_to_header(read_perm_acl, write_perm_acl) header = {} if read_perm_acl.nil? && write_perm_acl.nil? header = {'X-Container-Read' => "", 'X-Container-Write' => ""} elsif !read_perm_acl.nil? && write_perm_acl.nil? header = {'X-Container-Read' => "#{read_perm_acl.join(',')}", 'X-Container-Write' => ""} elsif read_perm_acl.nil? && !write_perm_acl.nil? header = {'X-Container-Read' => "", 'X-Container-Write' => "#{write_perm_acl.join(',')}"} elsif !read_perm_acl.nil? && !write_perm_acl.nil? header = {'X-Container-Read' => "#{read_perm_acl.join(',')}", 'X-Container-Write' => "#{write_perm_acl.join(',')}"} end header end
# File lib/fog/hp/storage.rb, line 85 def perm_to_acl(perm, users=[]) read_perm_acl = [] write_perm_acl = [] valid_public_perms = ['pr', 'pw', 'prw'] valid_account_perms = ['r', 'w', 'rw'] valid_perms = valid_public_perms + valid_account_perms unless valid_perms.include?(perm) raise ArgumentError.new("permission must be one of [#{valid_perms.join(', ')}]") end # tackle the public access differently if valid_public_perms.include?(perm) case perm when "pr" read_perm_acl = [".r:*",".rlistings"] when "pw" write_perm_acl = ["*"] when "prw" read_perm_acl = [".r:*",".rlistings"] write_perm_acl = ["*"] end elsif valid_account_perms.include?(perm) # tackle the user access differently unless (users.nil? || users.empty?) # return the correct acls tenant_id = "*" # this might change later acl_array = users.map { |u| "#{tenant_id}:#{u}" } #acl_string = acl_array.join(',') case perm when "r" read_perm_acl = acl_array when "w" write_perm_acl = acl_array when "rw" read_perm_acl = acl_array write_perm_acl = acl_array end end end return read_perm_acl, write_perm_acl end
# File lib/fog/hp/storage.rb, line 71 def public_url(container=nil, object=nil) public_url = nil unless container.nil? if object.nil? # return container public url public_url = "#{url}/#{Fog::HP.escape(container)}" else # return object public url public_url = "#{url}/#{Fog::HP.escape(container)}/#{Fog::HP.escape(object)}" end end public_url end
Generated with the Darkfish Rdoc Generator 2.