Class: Azure::Blob::Auth::SharedAccessSignature

Inherits:
Core::Auth::Signer show all
Defined in:
lib/azure/blob/auth/shared_access_signature.rb

Constant Summary collapse

DEFAULTS =
{
  resource: 'b',
  permissions: 'r',
  version: '2013-08-15'
}
KEY_MAPPINGS =
{
  permissions:         :sp,
  start:               :st,
  expiry:              :se,
  resource:            :sr,
  identifier:          :si,
  version:             :sv,
  cache_control:       :rscc,
  content_disposition: :rscd,
  content_encoding:    :rsce,
  content_language:    :rscl,
  content_type:        :rsct
}
OPTIONAL_QUERY_PARAMS =
[:sp, :si, :rscc, :rscd, :rsce, :rscl, :rsct]

Instance Attribute Summary collapse

Attributes inherited from Core::Auth::Signer

#access_key

Instance Method Summary collapse

Methods inherited from Core::Auth::Signer

#sign

Constructor Details

#initialize(path, options, account_name = Azure.config.storage_account_name, access_key = Azure.config.storage_access_key) ⇒ SharedAccessSignature

Public: Initialize the Signer.

Attributes

  • path - the container or blob path

  • options - Hash. Required and optional parameters

  • 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.
    

Options

  • :resource - String. Resource type, either ‘b’ (blob) or ‘c’ (container). Default ‘b’

  • :permissions - String. Combination of ‘r’,‘w’,‘d’,‘l’ (container only) in this order. Default ‘r’

  • :start - String. UTC Date/Time in ISO8601 format. Optional.

  • :expiry - String. UTC Date/Time in ISO8601 format. Required.

  • :identifier - String. Identifier for stored access policy. Optional

  • :version - String. API version. Default ‘2013-08-15’

  • +:cache_control - String. Response header override. Optional.

  • +:content_disposition - String. Response header override. Optional.

  • +:content_encoding - String. Response header override. Optional.

  • +:content_language - String. Response header override. Optional.

  • +:content_type - String. Response header override. Optional.



79
80
81
82
83
84
85
# File 'lib/azure/blob/auth/shared_access_signature.rb', line 79

def initialize(path, options, =Azure.config., access_key=Azure.config.storage_access_key)
  @path = path
  @account_name = 
  @options = DEFAULTS.merge(options)

  super(access_key)
end

Instance Attribute Details

#account_nameObject (readonly)

Returns the value of attribute account_name.



52
53
54
# File 'lib/azure/blob/auth/shared_access_signature.rb', line 52

def 
  @account_name
end

#optionsObject (readonly)

Returns the value of attribute options.



51
52
53
# File 'lib/azure/blob/auth/shared_access_signature.rb', line 51

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



50
51
52
# File 'lib/azure/blob/auth/shared_access_signature.rb', line 50

def path
  @path
end

Instance Method Details

#canonicalized_resourceObject



108
109
110
# File 'lib/azure/blob/auth/shared_access_signature.rb', line 108

def canonicalized_resource
  "/#{}/#{path}"
end

#signable_stringObject

Public: Construct the plaintext to the spec required for signatures



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/azure/blob/auth/shared_access_signature.rb', line 88

def signable_string
  # Order is significant
  # The newlines from empty strings here are required
  [
    options[:permissions],
    options[:start],
    options[:expiry],
    canonicalized_resource,
    options[:identifier],

    options[:version],

    options[:cache_control],
    options[:content_disposition],
    options[:content_encoding],
    options[:content_language],
    options[:content_type]
  ].join("\n")
end

#signed_uriObject

Public: A customised URI reflecting options for the resource signed with the Shared Access Signature



113
114
115
116
# File 'lib/azure/blob/auth/shared_access_signature.rb', line 113

def signed_uri
  query_params = URI.encode_www_form(query_hash)
  "https://#{}.blob.core.windows.net/#{path}?#{query_params}"
end

#to_sObject



118
119
120
# File 'lib/azure/blob/auth/shared_access_signature.rb', line 118

def to_s
  signed_uri
end