module Azure::Storage::Common::Configurable

The Azure::Storage::Common::Configurable module provides basic configuration for Azure storage activities.

Attributes

signer[R]
storage_access_key[RW]

@!attribute [w] storage_access_key

@return [String] Azure Storage access key.

@!attribute storage_account_name

@return [String] Azure Storage account name.

@!attribute storage_connection_string

@return [String] Azure Storage connection string.

@!attribute storage_blob_host

@return [String] Set the host for the Blob service. Only set this if you want
  something custom (like, for example, to point this to a LocalStorage
  emulator). This should be the complete host, including http:// at the
  start. When using the emulator, make sure to include your account name at
  the end.

@!attribute storage_table_host

@return [String] Set the host for the Table service. Only set this if you want
  something custom (like, for example, to point this to a LocalStorage
  emulator). This should be the complete host, including http:// at the
  start. When using the emulator, make sure to include your account name at
  the end.

@!attribute storage_queue_host

@return [String] Set the host for the Queue service. Only set this if you want
  something custom (like, for example, to point this to a LocalStorage
  emulator). This should be the complete host, including http:// at the
  start. When using the emulator, make sure to include your account name at
  the end.
storage_account_name[RW]

@!attribute [w] storage_access_key

@return [String] Azure Storage access key.

@!attribute storage_account_name

@return [String] Azure Storage account name.

@!attribute storage_connection_string

@return [String] Azure Storage connection string.

@!attribute storage_blob_host

@return [String] Set the host for the Blob service. Only set this if you want
  something custom (like, for example, to point this to a LocalStorage
  emulator). This should be the complete host, including http:// at the
  start. When using the emulator, make sure to include your account name at
  the end.

@!attribute storage_table_host

@return [String] Set the host for the Table service. Only set this if you want
  something custom (like, for example, to point this to a LocalStorage
  emulator). This should be the complete host, including http:// at the
  start. When using the emulator, make sure to include your account name at
  the end.

@!attribute storage_queue_host

@return [String] Set the host for the Queue service. Only set this if you want
  something custom (like, for example, to point this to a LocalStorage
  emulator). This should be the complete host, including http:// at the
  start. When using the emulator, make sure to include your account name at
  the end.
storage_blob_host[W]
storage_blob_host_secondary[W]
storage_connection_string[RW]

@!attribute [w] storage_access_key

@return [String] Azure Storage access key.

@!attribute storage_account_name

@return [String] Azure Storage account name.

@!attribute storage_connection_string

@return [String] Azure Storage connection string.

@!attribute storage_blob_host

@return [String] Set the host for the Blob service. Only set this if you want
  something custom (like, for example, to point this to a LocalStorage
  emulator). This should be the complete host, including http:// at the
  start. When using the emulator, make sure to include your account name at
  the end.

@!attribute storage_table_host

@return [String] Set the host for the Table service. Only set this if you want
  something custom (like, for example, to point this to a LocalStorage
  emulator). This should be the complete host, including http:// at the
  start. When using the emulator, make sure to include your account name at
  the end.

@!attribute storage_queue_host

@return [String] Set the host for the Queue service. Only set this if you want
  something custom (like, for example, to point this to a LocalStorage
  emulator). This should be the complete host, including http:// at the
  start. When using the emulator, make sure to include your account name at
  the end.
storage_file_host[W]
storage_file_host_secondary[W]
storage_queue_host[W]
storage_queue_host_secondary[W]
storage_sas_token[RW]

@!attribute [w] storage_access_key

@return [String] Azure Storage access key.

@!attribute storage_account_name

@return [String] Azure Storage account name.

@!attribute storage_connection_string

@return [String] Azure Storage connection string.

@!attribute storage_blob_host

@return [String] Set the host for the Blob service. Only set this if you want
  something custom (like, for example, to point this to a LocalStorage
  emulator). This should be the complete host, including http:// at the
  start. When using the emulator, make sure to include your account name at
  the end.

@!attribute storage_table_host

@return [String] Set the host for the Table service. Only set this if you want
  something custom (like, for example, to point this to a LocalStorage
  emulator). This should be the complete host, including http:// at the
  start. When using the emulator, make sure to include your account name at
  the end.

@!attribute storage_queue_host

@return [String] Set the host for the Queue service. Only set this if you want
  something custom (like, for example, to point this to a LocalStorage
  emulator). This should be the complete host, including http:// at the
  start. When using the emulator, make sure to include your account name at
  the end.
storage_table_host[W]
storage_table_host_secondary[W]

Public Class Methods

keys() click to toggle source

List of configurable keys for {Azure::Client} @return [Array] of option keys

# File lib/azure/storage/common/configurable.rb, line 74
def keys
  @keys ||= [
    :storage_access_key,
    :storage_account_name,
    :storage_connection_string,
    :storage_sas_token,
    :storage_table_host,
    :storage_blob_host,
    :storage_queue_host,
    :storage_file_host,
    :signer
  ]
end

Public Instance Methods

config() click to toggle source
# File lib/azure/storage/common/configurable.rb, line 94
def config
  self
end
configure() { |self| ... } click to toggle source

Set configuration options using a block

# File lib/azure/storage/common/configurable.rb, line 90
def configure
  yield self
end
reset_config!(options = {}) click to toggle source

Reset configuration options to default values

# File lib/azure/storage/common/configurable.rb, line 99
def reset_config!(options = {})
  Azure::Storage::Common::Configurable.keys.each do |key|
    value =
      if self == Azure::Storage::Common
        Azure::Storage::Common::Default.options[key]
      else
        self.send(key)
      end
    instance_variable_set(:"@#{key}", options.fetch(key, value))

    # Set the secondary endpoint if the primary one is given
    if key.to_s.include? "host"
      instance_variable_set(:"@#{key}_secondary", secondary_endpoint(options.fetch(key, value)))
    end
  end
  self.send(:reset_agents!) if self.respond_to?(:reset_agents!)
  setup_signer_for_service(options[:api_version])
  self
end
Also aliased as: setup
setup(options = {})
Alias for: reset_config!
storage_blob_host(isSecondary = false) click to toggle source

Storage blob host @return [String]

# File lib/azure/storage/common/configurable.rb, line 133
def storage_blob_host(isSecondary = false)
  if isSecondary
    @storage_blob_host_secondary || default_host(:blob, true)
  else
    @storage_blob_host || default_host(:blob, false)
  end
end
storage_file_host(isSecondary = false) click to toggle source

Storage file host @return [String]

# File lib/azure/storage/common/configurable.rb, line 153
def storage_file_host(isSecondary = false)
  if isSecondary
    @storage_file_host_secondary || default_host(:file, true)
  else
    @storage_file_host || default_host(:file, false)
  end
end
storage_queue_host(isSecondary = false) click to toggle source

Storage queue host @return [String]

# File lib/azure/storage/common/configurable.rb, line 123
def storage_queue_host(isSecondary = false)
  if isSecondary
    @storage_queue_host_secondary || default_host(:queue, true)
  else
    @storage_queue_host || default_host(:queue, false)
  end
end
storage_table_host(isSecondary = false) click to toggle source

Storage table host @return [String]

# File lib/azure/storage/common/configurable.rb, line 143
def storage_table_host(isSecondary = false)
  if isSecondary
    @storage_table_host_secondary || default_host(:table, true)
  else
    @storage_table_host || default_host(:table, false)
  end
end

Private Instance Methods

account_name_from_endpoint(endpoint) click to toggle source
# File lib/azure/storage/common/configurable.rb, line 175
def account_name_from_endpoint(endpoint)
  return nil if endpoint.nil?
  uri = URI::parse endpoint
  fields = uri.host.split "."
  fields[0]
end
default_host(service, isSecondary = false) click to toggle source
# File lib/azure/storage/common/configurable.rb, line 163
def default_host(service, isSecondary = false)
  "https://#{storage_account_name}#{isSecondary ? "-secondary" : ""}.#{service}.core.windows.net" if storage_account_name
end
determine_account_name() click to toggle source
# File lib/azure/storage/common/configurable.rb, line 188
def determine_account_name
  if instance_variable_get(:@storage_account_name).nil?
    hosts = [@storage_blob_host, @storage_table_host, @storage_queue_host, @storage_file_host]
    account_name = nil;
    hosts.each do |host|
      parsed = account_name_from_endpoint host
      if account_name.nil?
        account_name = parsed
      elsif !account_name.nil? && !parsed.nil? && (account_name <=> parsed) != (0)
        raise InvalidOptionsError, "Ambiguous account name in service hosts."
      end
    end
    raise InvalidOptionsError, "Cannot identify account name." if account_name.nil?
    @storage_account_name = account_name
  end
end
secondary_endpoint(primary_endpoint) click to toggle source
# File lib/azure/storage/common/configurable.rb, line 182
def secondary_endpoint(primary_endpoint)
  return nil if primary_endpoint.nil?
  account_name = account_name_from_endpoint primary_endpoint
  primary_endpoint.sub account_name, account_name + "-secondary"
end
setup_options() click to toggle source
# File lib/azure/storage/common/configurable.rb, line 167
def setup_options
  opts = {}
  Azure::Storage::Common::Configurable.keys.map do |key|
    opts[key] = self.send(key) if self.send(key)
  end
  opts
end
setup_signer_for_service(api_ver) click to toggle source
# File lib/azure/storage/common/configurable.rb, line 205
def setup_signer_for_service(api_ver)
  if @storage_sas_token
    determine_account_name
    @signer = Azure::Storage::Common::Core::Auth::SharedAccessSignatureSigner.new api_ver, @storage_account_name, @storage_sas_token
  end
end