module Azure::Configurable

The Azure::Configurable module provides basic configuration for Azure activities.

Attributes

acs_host[R]
ca_file[RW]

@!attribute [w] #storage_access_key

@return [String] Azure Storage access key.

@!attribute #storage_account_name

@return [String] Azure Storage account name

@!attribute #sb_access_key

@return [String] Azure Service Bus access key

@!attribute #sb_sas_key

@return [String] Azure Service Bus Shared Access Signature key

@!attribute #sb_sas_key_name

@return [String] Azure Service Bus Shared Access Signature key name

@!attribute #sb_namespace

@return [String] Azure Service Bus namespace

@!attribute #sb_issuer

@return [String] Azure Service Bus issuer

@!attribute #ca_file

@return [String] Location of the Certificate Authority bundle to be used for HTTPS

@!attribute #management_certificate

@return [String|File] Azure Service Management certificate (pfx or pem)

@!attribute #subscription_id

@return [String] Azure Subscription ID

@!attribute #http_private_key

@return [String] Private key used for HTTPS certificate based authentication (derived from the management cert)

@!attribute #http_certificate_key

@return [String] Public key used for HTTPS certificate based authentication (derived from the management cert)

@!attribute #sql_database_management_endpoint

@return [String] Azure SQL database management endpoint. default: https://management.core.windows.net:8443/

@!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] Get the host for this service. If you set something using #storage_table_host=,
  then we use that. Else we default to Azure's default hosts, based
  on your account name.

@!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.

@!attribute #management_endpoint

@return [String] Azure Service Management Endpoint. default: https://management.core.windows.net
http_certificate_key[R]
http_private_key[R]
management_endpoint[W]
sb_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 #sb_access_key

@return [String] Azure Service Bus access key

@!attribute #sb_sas_key

@return [String] Azure Service Bus Shared Access Signature key

@!attribute #sb_sas_key_name

@return [String] Azure Service Bus Shared Access Signature key name

@!attribute #sb_namespace

@return [String] Azure Service Bus namespace

@!attribute #sb_issuer

@return [String] Azure Service Bus issuer

@!attribute #ca_file

@return [String] Location of the Certificate Authority bundle to be used for HTTPS

@!attribute #management_certificate

@return [String|File] Azure Service Management certificate (pfx or pem)

@!attribute #subscription_id

@return [String] Azure Subscription ID

@!attribute #http_private_key

@return [String] Private key used for HTTPS certificate based authentication (derived from the management cert)

@!attribute #http_certificate_key

@return [String] Public key used for HTTPS certificate based authentication (derived from the management cert)

@!attribute #sql_database_management_endpoint

@return [String] Azure SQL database management endpoint. default: https://management.core.windows.net:8443/

@!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] Get the host for this service. If you set something using #storage_table_host=,
  then we use that. Else we default to Azure's default hosts, based
  on your account name.

@!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.

@!attribute #management_endpoint

@return [String] Azure Service Management Endpoint. default: https://management.core.windows.net
sb_issuer[RW]

@!attribute [w] #storage_access_key

@return [String] Azure Storage access key.

@!attribute #storage_account_name

@return [String] Azure Storage account name

@!attribute #sb_access_key

@return [String] Azure Service Bus access key

@!attribute #sb_sas_key

@return [String] Azure Service Bus Shared Access Signature key

@!attribute #sb_sas_key_name

@return [String] Azure Service Bus Shared Access Signature key name

@!attribute #sb_namespace

@return [String] Azure Service Bus namespace

@!attribute #sb_issuer

@return [String] Azure Service Bus issuer

@!attribute #ca_file

@return [String] Location of the Certificate Authority bundle to be used for HTTPS

@!attribute #management_certificate

@return [String|File] Azure Service Management certificate (pfx or pem)

@!attribute #subscription_id

@return [String] Azure Subscription ID

@!attribute #http_private_key

@return [String] Private key used for HTTPS certificate based authentication (derived from the management cert)

@!attribute #http_certificate_key

@return [String] Public key used for HTTPS certificate based authentication (derived from the management cert)

@!attribute #sql_database_management_endpoint

@return [String] Azure SQL database management endpoint. default: https://management.core.windows.net:8443/

@!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] Get the host for this service. If you set something using #storage_table_host=,
  then we use that. Else we default to Azure's default hosts, based
  on your account name.

@!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.

@!attribute #management_endpoint

@return [String] Azure Service Management Endpoint. default: https://management.core.windows.net
sb_namespace[RW]

@!attribute [w] #storage_access_key

@return [String] Azure Storage access key.

@!attribute #storage_account_name

@return [String] Azure Storage account name

@!attribute #sb_access_key

@return [String] Azure Service Bus access key

@!attribute #sb_sas_key

@return [String] Azure Service Bus Shared Access Signature key

@!attribute #sb_sas_key_name

@return [String] Azure Service Bus Shared Access Signature key name

@!attribute #sb_namespace

@return [String] Azure Service Bus namespace

@!attribute #sb_issuer

@return [String] Azure Service Bus issuer

@!attribute #ca_file

@return [String] Location of the Certificate Authority bundle to be used for HTTPS

@!attribute #management_certificate

@return [String|File] Azure Service Management certificate (pfx or pem)

@!attribute #subscription_id

@return [String] Azure Subscription ID

@!attribute #http_private_key

@return [String] Private key used for HTTPS certificate based authentication (derived from the management cert)

@!attribute #http_certificate_key

@return [String] Public key used for HTTPS certificate based authentication (derived from the management cert)

@!attribute #sql_database_management_endpoint

@return [String] Azure SQL database management endpoint. default: https://management.core.windows.net:8443/

@!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] Get the host for this service. If you set something using #storage_table_host=,
  then we use that. Else we default to Azure's default hosts, based
  on your account name.

@!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.

@!attribute #management_endpoint

@return [String] Azure Service Management Endpoint. default: https://management.core.windows.net
sb_sas_key[RW]

@!attribute [w] #storage_access_key

@return [String] Azure Storage access key.

@!attribute #storage_account_name

@return [String] Azure Storage account name

@!attribute #sb_access_key

@return [String] Azure Service Bus access key

@!attribute #sb_sas_key

@return [String] Azure Service Bus Shared Access Signature key

@!attribute #sb_sas_key_name

@return [String] Azure Service Bus Shared Access Signature key name

@!attribute #sb_namespace

@return [String] Azure Service Bus namespace

@!attribute #sb_issuer

@return [String] Azure Service Bus issuer

@!attribute #ca_file

@return [String] Location of the Certificate Authority bundle to be used for HTTPS

@!attribute #management_certificate

@return [String|File] Azure Service Management certificate (pfx or pem)

@!attribute #subscription_id

@return [String] Azure Subscription ID

@!attribute #http_private_key

@return [String] Private key used for HTTPS certificate based authentication (derived from the management cert)

@!attribute #http_certificate_key

@return [String] Public key used for HTTPS certificate based authentication (derived from the management cert)

@!attribute #sql_database_management_endpoint

@return [String] Azure SQL database management endpoint. default: https://management.core.windows.net:8443/

@!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] Get the host for this service. If you set something using #storage_table_host=,
  then we use that. Else we default to Azure's default hosts, based
  on your account name.

@!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.

@!attribute #management_endpoint

@return [String] Azure Service Management Endpoint. default: https://management.core.windows.net
sb_sas_key_name[RW]

@!attribute [w] #storage_access_key

@return [String] Azure Storage access key.

@!attribute #storage_account_name

@return [String] Azure Storage account name

@!attribute #sb_access_key

@return [String] Azure Service Bus access key

@!attribute #sb_sas_key

@return [String] Azure Service Bus Shared Access Signature key

@!attribute #sb_sas_key_name

@return [String] Azure Service Bus Shared Access Signature key name

@!attribute #sb_namespace

@return [String] Azure Service Bus namespace

@!attribute #sb_issuer

@return [String] Azure Service Bus issuer

@!attribute #ca_file

@return [String] Location of the Certificate Authority bundle to be used for HTTPS

@!attribute #management_certificate

@return [String|File] Azure Service Management certificate (pfx or pem)

@!attribute #subscription_id

@return [String] Azure Subscription ID

@!attribute #http_private_key

@return [String] Private key used for HTTPS certificate based authentication (derived from the management cert)

@!attribute #http_certificate_key

@return [String] Public key used for HTTPS certificate based authentication (derived from the management cert)

@!attribute #sql_database_management_endpoint

@return [String] Azure SQL database management endpoint. default: https://management.core.windows.net:8443/

@!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] Get the host for this service. If you set something using #storage_table_host=,
  then we use that. Else we default to Azure's default hosts, based
  on your account name.

@!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.

@!attribute #management_endpoint

@return [String] Azure Service Management Endpoint. default: https://management.core.windows.net
service_bus_host[R]
sql_database_management_endpoint[W]
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 #sb_access_key

@return [String] Azure Service Bus access key

@!attribute #sb_sas_key

@return [String] Azure Service Bus Shared Access Signature key

@!attribute #sb_sas_key_name

@return [String] Azure Service Bus Shared Access Signature key name

@!attribute #sb_namespace

@return [String] Azure Service Bus namespace

@!attribute #sb_issuer

@return [String] Azure Service Bus issuer

@!attribute #ca_file

@return [String] Location of the Certificate Authority bundle to be used for HTTPS

@!attribute #management_certificate

@return [String|File] Azure Service Management certificate (pfx or pem)

@!attribute #subscription_id

@return [String] Azure Subscription ID

@!attribute #http_private_key

@return [String] Private key used for HTTPS certificate based authentication (derived from the management cert)

@!attribute #http_certificate_key

@return [String] Public key used for HTTPS certificate based authentication (derived from the management cert)

@!attribute #sql_database_management_endpoint

@return [String] Azure SQL database management endpoint. default: https://management.core.windows.net:8443/

@!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] Get the host for this service. If you set something using #storage_table_host=,
  then we use that. Else we default to Azure's default hosts, based
  on your account name.

@!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.

@!attribute #management_endpoint

@return [String] Azure Service Management Endpoint. default: https://management.core.windows.net
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 #sb_access_key

@return [String] Azure Service Bus access key

@!attribute #sb_sas_key

@return [String] Azure Service Bus Shared Access Signature key

@!attribute #sb_sas_key_name

@return [String] Azure Service Bus Shared Access Signature key name

@!attribute #sb_namespace

@return [String] Azure Service Bus namespace

@!attribute #sb_issuer

@return [String] Azure Service Bus issuer

@!attribute #ca_file

@return [String] Location of the Certificate Authority bundle to be used for HTTPS

@!attribute #management_certificate

@return [String|File] Azure Service Management certificate (pfx or pem)

@!attribute #subscription_id

@return [String] Azure Subscription ID

@!attribute #http_private_key

@return [String] Private key used for HTTPS certificate based authentication (derived from the management cert)

@!attribute #http_certificate_key

@return [String] Public key used for HTTPS certificate based authentication (derived from the management cert)

@!attribute #sql_database_management_endpoint

@return [String] Azure SQL database management endpoint. default: https://management.core.windows.net:8443/

@!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] Get the host for this service. If you set something using #storage_table_host=,
  then we use that. Else we default to Azure's default hosts, based
  on your account name.

@!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.

@!attribute #management_endpoint

@return [String] Azure Service Management Endpoint. default: https://management.core.windows.net
storage_blob_host[W]
storage_queue_host[W]
storage_table_host[W]
subscription_id[RW]

@!attribute [w] #storage_access_key

@return [String] Azure Storage access key.

@!attribute #storage_account_name

@return [String] Azure Storage account name

@!attribute #sb_access_key

@return [String] Azure Service Bus access key

@!attribute #sb_sas_key

@return [String] Azure Service Bus Shared Access Signature key

@!attribute #sb_sas_key_name

@return [String] Azure Service Bus Shared Access Signature key name

@!attribute #sb_namespace

@return [String] Azure Service Bus namespace

@!attribute #sb_issuer

@return [String] Azure Service Bus issuer

@!attribute #ca_file

@return [String] Location of the Certificate Authority bundle to be used for HTTPS

@!attribute #management_certificate

@return [String|File] Azure Service Management certificate (pfx or pem)

@!attribute #subscription_id

@return [String] Azure Subscription ID

@!attribute #http_private_key

@return [String] Private key used for HTTPS certificate based authentication (derived from the management cert)

@!attribute #http_certificate_key

@return [String] Public key used for HTTPS certificate based authentication (derived from the management cert)

@!attribute #sql_database_management_endpoint

@return [String] Azure SQL database management endpoint. default: https://management.core.windows.net:8443/

@!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] Get the host for this service. If you set something using #storage_table_host=,
  then we use that. Else we default to Azure's default hosts, based
  on your account name.

@!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.

@!attribute #management_endpoint

@return [String] Azure Service Management Endpoint. default: https://management.core.windows.net

Public Class Methods

keys() click to toggle source

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

# File lib/azure/configurable.rb, line 90
def keys
  @keys ||= [
      :storage_access_key,
      :storage_account_name,
      :sb_access_key,
      :sb_sas_key,
      :sb_sas_key_name,
      :ca_file,
      :sb_namespace,
      :management_certificate,
      :subscription_id,
      :sql_database_management_endpoint,
      :sb_issuer,
      :storage_table_host,
      :storage_blob_host,
      :storage_queue_host,
      :management_endpoint
  ]
end

Public Instance Methods

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

Set configuration options using a block

# File lib/azure/configurable.rb, line 112
def configure
  yield self
end
management_certificate() click to toggle source
# File lib/azure/configurable.rb, line 139
def management_certificate
  @management_certificate
end
management_certificate=(cert_string_or_file) click to toggle source

Set the management certificate via string or file (populates http_private_key and http_certificate_key) @param [String|File] the string or file representing the .pem or .pfx

# File lib/azure/configurable.rb, line 145
def management_certificate=(cert_string_or_file)
  self.send(:reset_agents!) if self.respond_to?(:reset_agents!)
  if cert_string_or_file.nil?
    @certificate_key = @private_key = @management_certificate = nil
  else

    # the pfx may have null chars which will raise an exception in File.file?
    invalid_file_chars = cert_string_or_file.to_s =~ /\x00/

    # validate only if input is file path
    if !invalid_file_chars && File.file?(cert_string_or_file) && File.extname(cert_string_or_file).downcase =~ /(pem|pfx)$/
      error_message = "Could not read from file '#{cert_string_or_file}'."
      raise ArgumentError.new(error_message) unless test('r', cert_string_or_file)
    end

    # get the string representation of cert
    cert_file = if !invalid_file_chars && File.file?(cert_string_or_file)
                  read_cert_from_file(cert_string_or_file)
                else
                  cert_string_or_file
                end

    begin
      if cert_file =~ /-----BEGIN CERTIFICATE-----/
        # Parse pem content
        @certificate_key = OpenSSL::X509::Certificate.new(cert_file)
        @private_key = OpenSSL::PKey::RSA.new(cert_file)
      else
        # Parse pfx content
        cert_content = OpenSSL::PKCS12.new(cert_file)
        @certificate_key = OpenSSL::X509::Certificate.new(
            cert_content.certificate.to_pem
        )
        @private_key = OpenSSL::PKey::RSA.new(cert_content.key.to_pem)
      end
      @management_certificate = cert_file
    rescue OpenSSL::OpenSSLError => e
      @certificate_key = nil
      @private_key = nil
      raise ArgumentError.new("Management certificate not valid. Error: #{e.message}")
    end
  end
end
management_endpoint() click to toggle source
# File lib/azure/configurable.rb, line 201
def management_endpoint
  normalize_endpoint do
    if URI(@management_endpoint).scheme.nil?
      "https://#{@management_endpoint}"
    else
      @management_endpoint
    end
  end
end
reset!(options = {}) click to toggle source

Reset configuration options to default values

# File lib/azure/configurable.rb, line 117
def reset!(options = {})
  Azure::Configurable.keys.each do |key|
    value = if self == Azure
              Azure::Default.options[key]
            else
              Azure.send(key)
            end

    if key == :management_certificate
      @certificate_key = nil
      @private_key = nil
      send(:"#{key.to_s + '='}", value)
    else
      instance_variable_set(:"@#{key}", options.fetch(key, value))
    end
  end
  self.send(:reset_agents!) if self.respond_to?(:reset_agents!)
  self
end
Also aliased as: setup
setup(options = {})
Alias for: reset!
sql_database_management_endpoint() click to toggle source
# File lib/azure/configurable.rb, line 211
def sql_database_management_endpoint
  normalize_endpoint do
    if URI(@sql_database_management_endpoint).scheme.nil?
      "https://#{@sql_database_management_endpoint}:8443"
    else
      @sql_database_management_endpoint
    end
  end
end
storage_blob_host() click to toggle source

Storage blob host @return [String]

# File lib/azure/configurable.rb, line 229
def storage_blob_host
  @storage_blob_host || default_host(:blob)
end
storage_queue_host() click to toggle source

Storage queue host @return [String]

# File lib/azure/configurable.rb, line 223
def storage_queue_host
  @storage_queue_host || default_host(:queue)
end
storage_table_host() click to toggle source

Storage table host @return [String]

# File lib/azure/configurable.rb, line 235
def storage_table_host
  @storage_table_host || default_host(:table)
end

Private Instance Methods

default_host(service) click to toggle source
# File lib/azure/configurable.rb, line 265
def default_host(service)
  "https://#{storage_account_name}.#{service}.core.windows.net"
end
normalize_endpoint() { || ... } click to toggle source
# File lib/azure/configurable.rb, line 285
def normalize_endpoint
  if block_given?
    File.join(yield, '')
  else
    nil
  end
end
options() click to toggle source
# File lib/azure/configurable.rb, line 293
def options
  Hash[Azure::Configurable.keys.map { |key| [key, instance_variable_get(:"@#{key}")] }]
end
parse_publishsettings(pub_file_path) click to toggle source
# File lib/azure/configurable.rb, line 280
def parse_publishsettings(pub_file_path)
  pub_xml = Nokogiri::XML.parse(File.read(pub_file_path))
  pub_xml.css('PublishData PublishProfile Subscription')[0]
end
read_cert_from_file(cert_file_path) click to toggle source
# File lib/azure/configurable.rb, line 269
def read_cert_from_file(cert_file_path)
  if File.extname(cert_file_path).downcase == '.pem'
    File.read(cert_file_path)
  elsif File.extname(cert_file_path).downcase == '.publishsettings'
    management_cert = parse_publishsettings(cert_file_path)['ManagementCertificate']
    Base64.decode64(management_cert)
  else
    File.binread(cert_file_path)
  end
end