Class: Azure::Armrest::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/azure/armrest/environment.rb

Constant Summary collapse

VALID_KEYS =

A list of valid keys that can be passed to the constructor

%i[
  name
  active_directory_authority
  active_directory_resource_id
  gallery_url
  graph_url
  graph_api_version
  key_vault_dns_suffix
  key_vault_service_resource_id
  publish_settings_file_url
  resource_manager_url
  service_management_url
  sql_database_dns_suffix
  storage_suffix
  traffic_manager_dns_suffix
].freeze
Public =

Pre-generated environments

new(
  :name                          => 'Public',
  :active_directory_authority    => 'https://login.microsoftonline.com/',
  :active_directory_resource_id  => 'https://management.core.windows.net/',
  :gallery_url                   => 'https://gallery.azure.com/',
  :graph_url                     => 'https://graph.windows.net/',
  :graph_api_version             => '1.6',
  :key_vault_dns_suffix          => 'vault.azure.net',
  :key_vault_service_resource_id => 'https://vault.azure.net',
  :publish_settings_file_url     => 'https://manage.windowsazure.com/publishsettings/index',
  :resource_manager_url          => 'https://management.azure.com/',
  :service_management_url        => 'https://management.core.windows.net/',
  :sql_database_dns_suffix       => 'database.windows.net',
  :storage_suffix                => 'core.windows.net',
  :traffic_manager_dns_suffix    => 'trafficmanager.net',
)
USGovernment =
new(
  :name                          => 'US Government',
  :active_directory_authority    => 'https://login.microsoftonline.us/',
  :active_directory_resource_id  => 'https://management.core.usgovcloudapi.net/',
  :gallery_url                   => 'https://gallery.usgovcloudapi.net/',
  :graph_url                     => 'https://graph.windows.net/',
  :graph_api_version             => '1.6',
  :key_vault_dns_suffix          => 'vault.usgovcloudapi.net',
  :key_vault_service_resource_id => 'https://vault.usgovcloudapi.net',
  :publish_settings_file_url     => 'https://manage.windowsazure.us/publishsettings/index',
  :resource_manager_url          => 'https://management.usgovcloudapi.net/',
  :service_management_url        => 'https://management.core.usgovcloudapi.net/',
  :sql_database_dns_suffix       => 'database.usgovcloudapi.net',
  :storage_suffix                => 'core.usgovcloudapi.net',
  :traffic_manager_dns_suffix    => 'usgovtrafficmanager.net',
)
Germany =
new(
  :name                          => 'Germany',
  :active_directory_authority    => 'https://login.microsoftonline.de/',
  :active_directory_resource_id  => 'https://management.core.cloudapi.de/',
  :gallery_url                   => 'https://gallery.cloudapi.de/',
  :graph_url                     => 'https://graph.cloudapi.de/',
  :graph_api_version             => '1.6',
  :key_vault_dns_suffix          => 'vault.microsoftazure.de',
  :key_vault_service_resource_id => 'https://vault.microsoftazure.de',
  :publish_settings_file_url     => 'https://manage.microsoftazure.de/publishsettings/index',
  :resource_manager_url          => 'https://management.microsoftazure.de/',
  :service_management_url        => 'https://management.core.cloudapi.de/',
  :sql_database_dns_suffix       => 'database.cloudapi.de',
  :storage_suffix                => 'core.cloudapi.de',
  :traffic_manager_dns_suffix    => 'azuretrafficmanager.de'
)
China =
new(
  :name                          => 'China',
  :active_directory_authority    => 'https://login.chinacloudapi.cn',
  :active_directory_resource_id  => 'https://management.core.chinacloudapi.cn/',
  :gallery_url                   => 'https://gallery.chinacloudapi.cn/',
  :graph_url                     => 'https://graph.chinacloudapi.cn/',
  :graph_api_version             => '1.6',
  :key_vault_dns_suffix          => 'vault.azure.cn',
  :key_vault_service_resource_id => 'https://vault.azure.cn',
  :publish_settings_file_url     => 'http://go.microsoft.com/fwlink/?LinkID=301776',
  :resource_manager_url          => 'https://management.chinacloudapi.cn/',
  :service_management_url        => 'https://management.core.chinacloudapi.cn/',
  :sql_database_dns_suffix       => 'database.chinacloudapi.cn',
  :storage_suffix                => 'core.chinacloudapi.cn',
  :traffic_manager_dns_suffix    => 'trafficmanager.cn'
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Environment

Creates a new Azure::Armrest::Environment object. At a minimum, the options hash must include the :name, :active_directory_authority and :active_directory_resource_id.

Note that there are pre-generated environments already for Public and US Government environments.



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/azure/armrest/environment.rb', line 71

def initialize(options)
  options.symbolize_keys.each do |key, value|
    raise ArgumentError, "Invalid key '#{key}'" unless VALID_KEYS.include?(key)
    instance_variable_set("@#{key}", value)
  end

  %i[name active_directory_authority resource_manager_url].each do |key|
    unless instance_variable_get("@#{key}")
      raise ArgumentError, "Mandatory argument '#{key}' not set"
    end
  end
end

Instance Attribute Details

#active_directory_authorityObject (readonly) Also known as: authority_url, login_endpoint

The authority used to acquire an AD token



26
27
28
# File 'lib/azure/armrest/environment.rb', line 26

def active_directory_authority
  @active_directory_authority
end

#active_directory_resource_idObject (readonly)

The resource ID used to obtain an AD token



29
30
31
# File 'lib/azure/armrest/environment.rb', line 29

def active_directory_resource_id
  @active_directory_resource_id
end

The template gallery endpoint



32
33
34
# File 'lib/azure/armrest/environment.rb', line 32

def gallery_url
  @gallery_url
end

#graph_api_versionObject (readonly)

The api-version for Active Directory



38
39
40
# File 'lib/azure/armrest/environment.rb', line 38

def graph_api_version
  @graph_api_version
end

#graph_urlObject (readonly) Also known as: graph_endpoint

The Active Directory resource ID



35
36
37
# File 'lib/azure/armrest/environment.rb', line 35

def graph_url
  @graph_url
end

#key_vault_dns_suffixObject (readonly)

The KeyValut service DNS suffix



41
42
43
# File 'lib/azure/armrest/environment.rb', line 41

def key_vault_dns_suffix
  @key_vault_dns_suffix
end

#key_vault_service_resource_idObject (readonly)

The KeyVault service resource ID



44
45
46
# File 'lib/azure/armrest/environment.rb', line 44

def key_vault_service_resource_id
  @key_vault_service_resource_id
end

#nameObject (readonly)

The Environment name



23
24
25
# File 'lib/azure/armrest/environment.rb', line 23

def name
  @name
end

#publish_settings_file_urlObject (readonly)

The publish settings file URL



47
48
49
# File 'lib/azure/armrest/environment.rb', line 47

def publish_settings_file_url
  @publish_settings_file_url
end

#resource_manager_urlObject (readonly) Also known as: resource_url

The resource management endpoint



50
51
52
# File 'lib/azure/armrest/environment.rb', line 50

def resource_manager_url
  @resource_manager_url
end

#service_management_urlObject (readonly)

The service management URL



53
54
55
# File 'lib/azure/armrest/environment.rb', line 53

def service_management_url
  @service_management_url
end

#sql_database_dns_suffixObject (readonly)

The DNS suffix for SQL Server instances



56
57
58
# File 'lib/azure/armrest/environment.rb', line 56

def sql_database_dns_suffix
  @sql_database_dns_suffix
end

#storage_suffixObject (readonly)

The endpoint suffix for storage accounts



59
60
61
# File 'lib/azure/armrest/environment.rb', line 59

def storage_suffix
  @storage_suffix
end

#traffic_manager_dns_suffixObject (readonly)

The DNS suffix for TrafficManager



62
63
64
# File 'lib/azure/armrest/environment.rb', line 62

def traffic_manager_dns_suffix
  @traffic_manager_dns_suffix
end

Class Method Details

.discover(options) ⇒ Object

Automatically discover and create an Environment given a resource manager endpoint. The options hash must include an endpoint :url key. It may also include a :name (recommended), and http proxy options.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/azure/armrest/environment.rb', line 94

def self.discover(options)
  url  = options.fetch(:url)
  name = options[:name] || 'Custom'

  uri = Addressable::URI.join(url, '/metadata/', 'endpoints')
  uri.query = "api-version=1.0"

  response = ArmrestService.send(
    :rest_get,
    :url         => uri.to_s,
    :proxy       => options[:proxy],
    :ssl_version => options[:ssl_version],
    :ssl_verify  => options[:ssl_verify]
  )

  endpoint = Endpoint.new(response.body)

  new(
    :name                         => name,
    :gallery_url                  => endpoint.gallery_endpoint,
    :graph_url                    => endpoint.graph_endpoint,
    :active_directory_authority   => endpoint.authentication.,
    :active_directory_resource_id => endpoint.authentication.audiences.first,
    :resource_manager_url         => url
  )
end