Class: AzureBlob::SharedKeySigner
- Inherits:
-
Object
- Object
- AzureBlob::SharedKeySigner
- Defined in:
- lib/azure_blob/shared_key_signer.rb
Overview
:nodoc:
Defined Under Namespace
Modules: SAS
Instance Method Summary collapse
- #authorization_header(uri:, verb:, headers: {}) ⇒ Object
-
#initialize(account_name:, access_key:, host:) ⇒ SharedKeySigner
constructor
A new instance of SharedKeySigner.
- #sas_token(uri, options = {}) ⇒ Object
Constructor Details
#initialize(account_name:, access_key:, host:) ⇒ SharedKeySigner
Returns a new instance of SharedKeySigner.
10 11 12 13 14 15 |
# File 'lib/azure_blob/shared_key_signer.rb', line 10 def initialize(account_name:, access_key:, host:) @account_name = account_name @access_key = Base64.decode64(access_key) @host = host @remove_prefix = @host.end_with?("/#{@account_name}") end |
Instance Method Details
#authorization_header(uri:, verb:, headers: {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/azure_blob/shared_key_signer.rb', line 17 def (uri:, verb:, headers: {}) canonicalized_headers = CanonicalizedHeaders.new(headers) canonicalized_resource = CanonicalizedResource.new(uri, account_name) to_sign = [ verb, *sanitize_headers(headers).fetch_values( :"Content-Encoding", :"Content-Language", :"Content-Length", :"Content-MD5", :"Content-Type", :"Date", :"If-Modified-Since", :"If-Match", :"If-None-Match", :"If-Unmodified-Since", :"Range" ) { nil }, canonicalized_headers, canonicalized_resource, ].join("\n") "SharedKey #{account_name}:#{sign(to_sign)}" end |
#sas_token(uri, options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/azure_blob/shared_key_signer.rb', line 43 def sas_token(uri, = {}) if remove_prefix uri = uri.clone uri.path = uri.path.delete_prefix("/#{account_name}") end to_sign = [ [:permissions], [:start], [:expiry], CanonicalizedResource.new(uri, account_name, url_safe: false, service_name: :blob), [:identifier], [:ip], [:protocol], SAS::Version, SAS::Resources::Blob, nil, nil, nil, [:content_disposition], nil, nil, [:content_type], ].join("\n") query = { SAS::Fields::Permissions => [:permissions], SAS::Fields::Version => SAS::Version, SAS::Fields::Expiry => [:expiry], SAS::Fields::Resource => SAS::Resources::Blob, SAS::Fields::Disposition => [:content_disposition], SAS::Fields::Type => [:content_type], SAS::Fields::Signature => sign(to_sign), }.reject { |_, value| value.nil? } URI.encode_www_form(**query) end |