Class: Azure::Table::Auth::SharedKey
- Inherits:
-
Core::Auth::Signer
- Object
- Core::Auth::Signer
- Azure::Table::Auth::SharedKey
- Defined in:
- lib/azure/table/auth/shared_key.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#account_name ⇒ Object
readonly
The account name.
Attributes inherited from Core::Auth::Signer
Instance Method Summary collapse
-
#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.
33 34 35 36 |
# File 'lib/azure/table/auth/shared_key.rb', line 33 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 account name
25 26 27 |
# File 'lib/azure/table/auth/shared_key.rb', line 25 def account_name @account_name end |
Instance Method Details
#canonicalized_resource(uri) ⇒ Object
Calculate the Canonicalized Resource string for a request.
uri - The request’s URI.
Returns a String with the canonicalized resource.
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/azure/table/auth/shared_key.rb', line 79 def canonicalized_resource(uri) resource = "/%s%s" % [account_name, uri.path] comp = CGI.parse(uri.query.to_s).fetch("comp", nil) if (comp) resource = [resource, "comp=" + comp[0]].join("?") end resource end |
#name ⇒ Object
Public: The name of the strategy.
Returns a String.
41 42 43 |
# File 'lib/azure/table/auth/shared_key.rb', line 41 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.
52 53 54 55 |
# File 'lib/azure/table/auth/shared_key.rb', line 52 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.
64 65 66 67 68 69 70 71 72 |
# File 'lib/azure/table/auth/shared_key.rb', line 64 def signable_string(method, uri, headers) [ method.to_s.upcase, headers.fetch("Content-MD5", ""), headers.fetch("Content-Type", ""), headers.fetch("Date") { headers.fetch("x-ms-date") }, canonicalized_resource(uri) ].join("\n") end |