Class: Azure::Core::Auth::SharedAccessSignature

Inherits:
Object
  • Object
show all
Defined in:
lib/paperclip-azure.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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( = ENV['AZURE_STORAGE_ACCOUNT'], access_key = ENV['AZURE_STORAGE_ACCESS_KEY'])
  @version = '2020-02-10'
  @account = 
  @access_key = access_key
  @resource_type = 'b'
end

Instance Attribute Details

#access_keyObject

Returns the value of attribute access_key.



11
12
13
# File 'lib/paperclip-azure.rb', line 11

def access_key
  @access_key
end

#accountObject

Returns the value of attribute account.



10
11
12
# File 'lib/paperclip-azure.rb', line 10

def 
  @account
end

#resource_typeObject

Returns the value of attribute resource_type.



12
13
14
# File 'lib/paperclip-azure.rb', line 12

def resource_type
  @resource_type
end

#versionObject

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, permission='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 = "#{permission}\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=#{permission}" \
  "&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