Class: Azure::Core::Auth::SharedKey
- Defined in:
- lib/azure/core/auth/shared_key.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#account_name ⇒ Object
readonly
The Azure account’s name.
Attributes inherited from Signer
Instance Method Summary collapse
-
#canonicalized_headers(headers) ⇒ Object
Calculate the Canonicalized Headers string for a request.
-
#canonicalized_resource(uri) ⇒ Object
Calculate the Canonicalized Resource string for a request.
-
#initialize(account_name = Azure.config.storage_account_name, access_key = Azure.config.storage_access_key) ⇒ SharedKey
constructor
Public: Initialize the Signer.
-
#name ⇒ Object
Public: The name of the strategy.
-
#sign(method, uri, headers) ⇒ Object
Public: Generate a request signature.
-
#signable_string(method, uri, headers) ⇒ Object
Generate the string to sign.
Constructor Details
#initialize(account_name = Azure.config.storage_account_name, access_key = Azure.config.storage_access_key) ⇒ SharedKey
Public: Initialize the Signer.
account_name - The account name. Defaults to the one in the
global configuration.
access_key - The access_key encoded in Base64. Defaults to the
one in the global configuration.
32 33 34 35 |
# File 'lib/azure/core/auth/shared_key.rb', line 32 def initialize(account_name=Azure.config.storage_account_name, access_key=Azure.config.storage_access_key) @account_name = account_name super(access_key) end |
Instance Attribute Details
#account_name ⇒ Object (readonly)
The Azure account’s name.
24 25 26 |
# File 'lib/azure/core/auth/shared_key.rb', line 24 def account_name @account_name end |
Instance Method Details
#canonicalized_headers(headers) ⇒ Object
Calculate the Canonicalized Headers string for a request.
headers - A Hash of HTTP request headers.
Returns a string with the canonicalized headers.
87 88 89 90 91 92 93 |
# File 'lib/azure/core/auth/shared_key.rb', line 87 def canonicalized_headers(headers) headers = headers.map { |k,v| [k.to_s.downcase, v] } headers.select! { |k,v| k =~ /^x-ms-/ } headers.sort_by! { |(k,v)| k } headers.map! { |k,v| "%s:%s" % [k, v] } headers.map! { |h| h.gsub(/\s+/, " ") }.join("\n") end |
#canonicalized_resource(uri) ⇒ Object
Calculate the Canonicalized Resource string for a request.
uri - The request’s URI.
Returns a string with the canonicalized resource.
100 101 102 103 104 105 106 |
# File 'lib/azure/core/auth/shared_key.rb', line 100 def canonicalized_resource(uri) resource = "/" + account_name + (uri.path.empty? ? "/" : uri.path) params = CGI.parse(uri.query.to_s).map { |k,v| [k.downcase, v] } params.sort_by! { |k,v| k } params.map! { |k,v| "%s:%s" % [k, v.map(&:strip).sort.join(",")] } [resource, *params].join("\n") end |
#name ⇒ Object
Public: The name of the strategy.
Returns a String.
40 41 42 |
# File 'lib/azure/core/auth/shared_key.rb', line 40 def name "SharedKey" end |
#sign(method, uri, headers) ⇒ Object
Public: Generate a request signature.
verb - The HTTP request method. uri - The URI of the request we’re signing. headers - A Hash of HTTP request headers.
Returns a Base64 String signed with HMAC.
51 52 53 54 |
# File 'lib/azure/core/auth/shared_key.rb', line 51 def sign(method, uri, headers) signature = super(signable_string(method, uri, headers)) return "#{account_name}:#{signature}" end |
#signable_string(method, uri, headers) ⇒ Object
Generate the string to sign.
verb - The HTTP request method. uri - The URI of the request we’re signing. headers - A Hash of HTTP request headers.
Returns a plain text string.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/azure/core/auth/shared_key.rb', line 63 def signable_string(method, uri, headers) [ method.to_s.upcase, headers.fetch("Content-Encoding", ""), headers.fetch("Content-Language", ""), headers.fetch("Content-Length", ""), headers.fetch("Content-MD5", ""), headers.fetch("Content-Type", ""), headers.fetch("Date", ""), headers.fetch("If-Modified-Since", ""), headers.fetch("If-Match", ""), headers.fetch("If-None-Match", ""), headers.fetch("If-Unmodified-Since", ""), headers.fetch("Range", ""), canonicalized_headers(headers), canonicalized_resource(uri) ].join("\n") end |