class Azure::Contrib::Auth::SharedAccessSignature
Attributes
options[RW]
uri[RW]
Public Class Methods
new(uri, options = {}, account = ENV['AZURE_STORAGE_ACCOUNT'])
click to toggle source
# File lib/azure-contrib/shared_access_signature.rb, line 24 def initialize(uri, options = {}, account = ENV['AZURE_STORAGE_ACCOUNT']) # This is the uri that we are signing @uri = Addressable::URI.parse(uri) is_blob = options[:resource] == 'b' # Create the options hash that will be turned into a query string @options = Version20130815.new(options.merge(canonicalized_resource: canonicalized_resource(@uri, account, is_blob))) end
Public Instance Methods
canonicalized_resource(uri, account = ENV['AZURE_STORAGE_ACCOUNT'], is_blob = false)
click to toggle source
Create a “canonicalized resource” from the full uri to be signed
# File lib/azure-contrib/shared_access_signature.rb, line 35 def canonicalized_resource(uri, account = ENV['AZURE_STORAGE_ACCOUNT'], is_blob = false) path = URI.unescape(uri.path) # Addressable::URI # There is only really one level deep for containers, the remainder is the BLOB key (that looks like a path) path_array = path.split('/').reject {|p| p == ''} container = path_array.shift string = if is_blob File.join('/', account, container, path_array.join('/')) else File.join('/', account, container) end string end
create_query_values(options = Version20130815.new)
click to toggle source
When creating the query string from the options, we only include the no-empty fields
-
this is opposed to the string that gets signed which includes them as blank.
# File lib/azure-contrib/shared_access_signature.rb, line 52 def create_query_values(options = Version20130815.new) # Parts parts = {} parts[:st] = URI.unescape(options[:start]) unless options[:start] == '' parts[:se] = URI.unescape(options[:expiry]) parts[:sr] = URI.unescape(options[:resource]) parts[:sp] = URI.unescape(options[:permissions]) parts[:si] = URI.unescape(options[:identifier]) unless options[:identifier] == '' parts[:sig] = URI.unescape( create_signature(options) ) parts end
create_signature(options = Version20130815)
click to toggle source
# File lib/azure-contrib/shared_access_signature.rb, line 65 def create_signature(options = Version20130815) string_to_sign = [] string_to_sign << options[:permissions] string_to_sign << options[:start] string_to_sign << options[:expiry] string_to_sign << options[:canonicalized_resource] string_to_sign << options[:identifier] Azure::Core::Auth::Signer.new.sign(string_to_sign.join("\n").force_encoding("UTF-8")) end
sign()
click to toggle source
# File lib/azure-contrib/shared_access_signature.rb, line 78 def sign @uri.query_values = (@uri.query_values || {}).merge(create_query_values(@options)) @uri.to_s end