Class: Azure::Core::Auth::SharedAccessSignature
- Inherits:
-
Object
- Object
- Azure::Core::Auth::SharedAccessSignature
- Defined in:
- lib/paperclip-azure.rb
Instance Attribute Summary collapse
-
#access_key ⇒ Object
Returns the value of attribute access_key.
-
#account ⇒ Object
Returns the value of attribute account.
-
#resource_type ⇒ Object
Returns the value of attribute resource_type.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #generate_token(container, key, permission = 'r', timeout = 900, content_disposition = '') ⇒ Object
-
#initialize(account = ENV['AZURE_STORAGE_ACCOUNT'], access_key = ENV['AZURE_STORAGE_ACCESS_KEY']) ⇒ SharedAccessSignature
constructor
A new instance of SharedAccessSignature.
Constructor Details
#initialize(account = ENV['AZURE_STORAGE_ACCOUNT'], access_key = ENV['AZURE_STORAGE_ACCESS_KEY']) ⇒ SharedAccessSignature
Returns a new instance of SharedAccessSignature.
14 15 16 17 18 19 |
# File 'lib/paperclip-azure.rb', line 14 def initialize(account = ENV['AZURE_STORAGE_ACCOUNT'], access_key = ENV['AZURE_STORAGE_ACCESS_KEY']) @version = '2020-02-10' @account = account @access_key = access_key @resource_type = 'b' end |
Instance Attribute Details
#access_key ⇒ Object
Returns the value of attribute access_key.
11 12 13 |
# File 'lib/paperclip-azure.rb', line 11 def access_key @access_key end |
#account ⇒ Object
Returns the value of attribute account.
10 11 12 |
# File 'lib/paperclip-azure.rb', line 10 def account @account end |
#resource_type ⇒ Object
Returns the value of attribute resource_type.
12 13 14 |
# File 'lib/paperclip-azure.rb', line 12 def resource_type @resource_type end |
#version ⇒ Object
Returns the value of attribute version.
9 10 11 |
# File 'lib/paperclip-azure.rb', line 9 def version @version end |
Instance Method Details
#generate_token(container, key, permission = 'r', timeout = 900, content_disposition = '') ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/paperclip-azure.rb', line 21 def generate_token(container, key, ='r', timeout=900, content_disposition='') expiry = (Time.now.utc + timeout.seconds).utc.iso8601 resource_path = "/blob/#{@account}/#{container}/#{key[0] == '/' ? key[1..-1] : key}" string_to_sign = "#{}\n\n#{expiry}\n#{resource_path}\n\n\n\n#{@version}\n#{@resource_type}\n\n\n#{content_disposition}\n\n\n" "se=#{URI.encode_www_form_component(expiry)}" \ "&sp=#{}" \ "&sv=#{@version}" \ "&sr=#{@resource_type}" \ "&rscd=#{URI.encode_www_form_component(content_disposition)}" \ "&sig=#{URI.encode_www_form_component(sign_string(@access_key, string_to_sign))}" end |