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.
103 104 105 106 107 108 |
# File 'lib/azure/core/auth/shared_key.rb', line 103 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] }.join("\n") end |
#canonicalized_resource(uri) ⇒ String
Calculate the Canonicalized Resource string for a request.
115 116 117 118 119 120 121 |
# File 'lib/azure/core/auth/shared_key.rb', line 115 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 63 64 65 66 67 68 69 70 |
# File 'lib/azure/core/auth/shared_key.rb', line 59 def sign_request(req) # Need to make sure Content-Length is correctly set. if ((!req.body.nil?)) then if (req.body.respond_to? :bytesize) then req.headers['Content-Length'] = req.body.bytesize.to_s elsif (req.body.respond_to? :size) req.headers['Content-Length'] = req.body.size.to_s end end req.headers['Authorization'] = "#{name} #{sign(req.method, req.uri, req.headers)}" req end |
#signable_string(method, uri, headers) ⇒ String
Generate the string to sign.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/azure/core/auth/shared_key.rb', line 79 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 |