class Azure::Blob::Auth::SharedAccessSignature

Constants

DEFAULTS
KEY_MAPPINGS
OPTIONAL_QUERY_PARAMS

Attributes

account_name[R]
options[R]
path[R]

Public Class Methods

new(path, options, account_name=Azure.config.storage_account_name, access_key=Azure.config.storage_access_key) click to toggle source

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.

Calls superclass method
# File lib/azure/blob/auth/shared_access_signature.rb, line 79
def initialize(path, options, account_name=Azure.config.storage_account_name, access_key=Azure.config.storage_access_key)
  @path = path
  @account_name = account_name
  @options = DEFAULTS.merge(options)

  super(access_key)
end

Public Instance Methods

canonicalized_resource() click to toggle source
# File lib/azure/blob/auth/shared_access_signature.rb, line 108
def canonicalized_resource
  "/#{account_name}/#{path}"
end
signable_string() click to toggle source

Public: Construct the plaintext to the spec required for signatures

# 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_uri() click to toggle source

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

# File lib/azure/blob/auth/shared_access_signature.rb, line 113
def signed_uri
  query_params = URI.encode_www_form(query_hash)
  "https://#{account_name}.blob.core.windows.net/#{path}?#{query_params}"
end
to_s() click to toggle source
# File lib/azure/blob/auth/shared_access_signature.rb, line 118
def to_s
  signed_uri
end

Private Instance Methods

query_hash() click to toggle source
# File lib/azure/blob/auth/shared_access_signature.rb, line 128
def query_hash
  Hash[options.map { |k, v|
    [KEY_MAPPINGS[k], v]
  }].reject { |k,v|
    OPTIONAL_QUERY_PARAMS.include?(k) && v.to_s == ''
  }.merge(
    sig: signature
  )
end
signature() click to toggle source
# File lib/azure/blob/auth/shared_access_signature.rb, line 124
def signature
  sign(signable_string)
end