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) ⇒ String
Calculate the Canonicalized Headers string for a request.
-
#canonicalized_resource(uri) ⇒ String
Calculate the Canonicalized Resource string for a request.
-
#initialize(account_name = Azure.storage_account_name, access_key = Azure.storage_access_key) ⇒ SharedKey
constructor
Initialize the Signer.
-
#name ⇒ String
The name of the strategy.
-
#sign(method, uri, headers) ⇒ String
Create the signature for the request parameters.
-
#sign_request(req) ⇒ Azure::Core::Http::HttpRequest
Sign the request.
-
#signable_string(method, uri, headers) ⇒ String
Generate the string to sign.
Constructor Details
#initialize(account_name = Azure.storage_account_name, access_key = Azure.storage_access_key) ⇒ SharedKey
Initialize the Signer.
31 32 33 34 |
# File 'lib/azure/core/auth/shared_key.rb', line 31 def initialize(account_name=Azure.storage_account_name, access_key=Azure.storage_access_key) @account_name = account_name super(access_key) end |
Instance Attribute Details
#account_name ⇒ Object (readonly)
The Azure account’s name.
23 24 25 |
# File 'lib/azure/core/auth/shared_key.rb', line 23 def account_name @account_name end |
Instance Method Details
#canonicalized_headers(headers) ⇒ String
Calculate the Canonicalized Headers string for a request.
95 96 97 98 99 100 101 |
# File 'lib/azure/core/auth/shared_key.rb', line 95 def canonicalized_headers(headers) headers = headers.map { |k,v| [k.to_s.downcase, v] } headers.select! { |k,_| k =~ /^x-ms-/ } headers.sort_by! { |(k,_)| k } headers.map! { |k,v| '%s:%s' % [k, v] } headers.map! { |h| h.gsub(/\s+/, ' ') }.join("\n") end |
#canonicalized_resource(uri) ⇒ String
Calculate the Canonicalized Resource string for a request.
108 109 110 111 112 113 114 |
# File 'lib/azure/core/auth/shared_key.rb', line 108 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,_| k } params.map! { |k,v| '%s:%s' % [k, v.map(&:strip).sort.join(',')] } [resource, *params].join("\n") end |
#name ⇒ String
The name of the strategy.
39 40 41 |
# File 'lib/azure/core/auth/shared_key.rb', line 39 def name 'SharedKey' end |
#sign(method, uri, headers) ⇒ String
Create the signature for the request parameters
50 51 52 |
# File 'lib/azure/core/auth/shared_key.rb', line 50 def sign(method, uri, headers) "#{account_name}:#{super(signable_string(method, uri, headers))}" end |
#sign_request(req) ⇒ Azure::Core::Http::HttpRequest
Sign the request
59 60 61 62 |
# File 'lib/azure/core/auth/shared_key.rb', line 59 def sign_request(req) req.headers['Authorization'] = "#{name} #{sign(req.method, req.uri, req.headers)}" req end |
#signable_string(method, uri, headers) ⇒ String
Generate the string to sign.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/azure/core/auth/shared_key.rb', line 71 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 |