azure-armrest 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 172b9e9bbaf79e6ce3b794516c9d03871b1bbefd
4
- data.tar.gz: 22f969732daa71dd7f072485ac5f491cd7649ff7
3
+ metadata.gz: b525251ef80821ff56d3acea755a8861afda77fa
4
+ data.tar.gz: 7b349ae37b233c3c0f120c7dfbbcc7572cab8ec3
5
5
  SHA512:
6
- metadata.gz: 389e975c413a315045b02edc52920f623df4df1fa576d9bc788b8653d342e2cbcab7008ff3a14828248df436f759df3181458c963c0a39b61c19c7ab4a3f7f26
7
- data.tar.gz: a888720f50eefa4ab1ce91b23ae19beecd82cc2e6f670133af0d86d44d4f7f9daa00c7567a6b06458518d683c6551afa5b2ee696e507e88a8da60a53011082df
6
+ metadata.gz: 9ff548c71449012c821ee00355ab71dd2d58b47594d76257c0fe3237da3a8fad55233b1fee8e17769655cb18633af1923c6225083c6f4ef056a30300e6ae5613
7
+ data.tar.gz: 202570079f1463b424937e400352c46f5ad7bf36889e57d261eced1908aee1b9a9a26ae96b230edc0d4b9277f2ebf46aa7dee42ef28fd20aee22436499d83d04
data/CHANGES CHANGED
@@ -1,3 +1,10 @@
1
+ = 0.5.0 - 20-Dec-2016
2
+ * Added the Azure::Armrest::Environment class. The Configuration#environment
3
+ option now takes an Environment instance. There are two predefined instances
4
+ that you can use - Public or USGovernment. The default is Public.
5
+ * Fixed bugs caused by altering the base_url. This affected the tags and
6
+ tenants methods, as well as the VirtualMachineService#series method.
7
+
1
8
  = 0.4.2 - 19-Dec-2016
2
9
  * Added the delete_by_id method, so you can now delete by ID string.
3
10
  * Added the TemplateDeploymentService#delete_associated_resources method.
data/lib/azure/armrest.rb CHANGED
@@ -7,29 +7,15 @@ require 'cache_method'
7
7
 
8
8
  # The Azure module serves as a namespace.
9
9
  module Azure
10
-
11
10
  # The Armrest module mostly serves as a namespace, but also contains any
12
11
  # common constants shared by subclasses.
13
12
  module Armrest
14
- # The default (public) Azure resource
15
- RESOURCE = "https://management.azure.com/"
16
-
17
- # The resource for US Government clients
18
- USGOV_RESOURCE = "https://management.core.usgovcloudapi.net/"
19
-
20
- # The default (public) authority resource
21
- AUTHORITY = "https://login.microsoftonline.com/"
22
-
23
- # The authority for US Government clients
24
- USGOV_AUTHORITY = "https://login-us.microsoftonline.com/"
25
-
26
- # Environment string used to indicate US Government
27
- USGOV_ENVIRONMENT = 'usgov'
28
13
  end
29
14
  end
30
15
 
31
16
  require 'azure/armrest/version'
32
17
  require 'azure/armrest/configuration'
18
+ require 'azure/armrest/environment'
33
19
  require 'azure/armrest/exception'
34
20
  require 'azure/armrest/armrest_collection'
35
21
  require 'azure/armrest/armrest_service'
@@ -46,7 +46,11 @@ module Azure
46
46
  end
47
47
 
48
48
  # Base URL used for REST calls. Modify within method calls as needed.
49
- @base_url = File.join(configuration.resource_url, 'subscriptions', configuration.subscription_id)
49
+ @base_url = File.join(
50
+ configuration.environment.resource_url,
51
+ 'subscriptions',
52
+ configuration.subscription_id
53
+ )
50
54
 
51
55
  set_service_api_version(options, service_name)
52
56
  end
@@ -135,13 +139,7 @@ module Azure
135
139
  # Returns a list of tags for the current subscription.
136
140
  #
137
141
  def tags
138
- url = url_with_api_version(
139
- configuration.api_version,
140
- @base_url,
141
- 'subscriptions',
142
- configuration.subscription_id,
143
- 'tagNames'
144
- )
142
+ url = url_with_api_version(configuration.api_version, base_url, 'tagNames')
145
143
  resp = rest_get(url)
146
144
  JSON.parse(resp.body)["value"].map{ |hash| Azure::Armrest::Tag.new(hash) }
147
145
  end
@@ -149,7 +147,7 @@ module Azure
149
147
  # Returns a list of tenants that can be accessed.
150
148
  #
151
149
  def tenants
152
- url = url_with_api_version(configuration.api_version, @base_url, 'tenants')
150
+ url = url_with_api_version(configuration.api_version, configuration.resource_url, 'tenants')
153
151
  resp = rest_get(url)
154
152
  JSON.parse(resp.body)['value'].map{ |hash| Azure::Armrest::Tenant.new(hash) }
155
153
  end
@@ -64,14 +64,9 @@ module Azure
64
64
  # Maximum number of threads to use within methods that use Parallel for thread pooling.
65
65
  attr_accessor :max_threads
66
66
 
67
- # The environment in which to acquire your token.
68
- attr_reader :environment
69
-
70
- # The authority URL used to acquire a valid token.
71
- attr_accessor :resource_url
72
-
73
- # The resource URL used to acquire a valid token.
74
- attr_accessor :authority_url
67
+ # The environment object which determines various endpoint URL's. The
68
+ # default is Azure::Armrest::Environment::Public.
69
+ attr_accessor :environment
75
70
 
76
71
  # Yields a new Azure::Armrest::Configuration objects. Note that you must
77
72
  # specify a client_id, client_key, tenant_id. The subscription_id is optional
@@ -106,8 +101,7 @@ module Azure
106
101
  :proxy => ENV['http_proxy'],
107
102
  :ssl_version => 'TLSv1',
108
103
  :max_threads => 10,
109
- :authority_url => Azure::Armrest::AUTHORITY,
110
- :resource_url => Azure::Armrest::RESOURCE
104
+ :environment => Azure::Armrest::Environment::Public
111
105
  }.merge(args.symbolize_keys)
112
106
 
113
107
  # Avoid thread safety issues for VCR testing.
@@ -218,28 +212,6 @@ module Azure
218
212
 
219
213
  private
220
214
 
221
- # Sets the environment to authenticate against. The environment
222
- # must support ActiveDirectory.
223
- #
224
- def environment=(env)
225
- return if env == environment
226
- set_auth_and_resource_urls(env)
227
- @environment = env
228
- end
229
-
230
- # Sets the authority_url and resource_url accessors depending on the
231
- # environment.
232
- #--
233
- # Only two supported at the moment, but more likely to be added.
234
- #
235
- def set_auth_and_resource_urls(env)
236
- case env.to_s.downcase
237
- when Azure::Armrest::USGOV_ENVIRONMENT
238
- @authority_url = Azure::Armrest::USGOV_AUTHORITY
239
- @resource_url = Azure::Armrest::USGOV_RESOURCE
240
- end
241
- end
242
-
243
215
  # Validate the subscription ID for the given credentials. Returns the
244
216
  # subscription ID if valid.
245
217
  #
@@ -307,7 +279,7 @@ module Azure
307
279
  end
308
280
 
309
281
  def fetch_token
310
- token_url = File.join(authority_url, tenant_id, 'oauth2/token')
282
+ token_url = File.join(environment.authority_url, tenant_id, 'oauth2', 'token')
311
283
 
312
284
  response = JSON.parse(
313
285
  ArmrestService.send(
@@ -320,7 +292,7 @@ module Azure
320
292
  :grant_type => grant_type,
321
293
  :client_id => client_id,
322
294
  :client_secret => client_key,
323
- :resource => resource_url
295
+ :resource => environment.resource_url
324
296
  }
325
297
  )
326
298
  )
@@ -0,0 +1,124 @@
1
+ module Azure
2
+ module Armrest
3
+ class Environment
4
+ # A list of valid keys that can be passed to the constructor
5
+ VALID_KEYS = [
6
+ :name,
7
+ :active_directory_authority,
8
+ :active_directory_resource_id,
9
+ :gallery_url,
10
+ :graph_url,
11
+ :graph_api_version,
12
+ :key_vault_dns_suffix,
13
+ :key_vault_service_resource_id,
14
+ :publish_settings_file_url,
15
+ :resource_manager_url,
16
+ :service_management_url,
17
+ :sql_database_dns_suffix,
18
+ :storage_suffix,
19
+ :traffic_manager_dns_suffix
20
+ ]
21
+
22
+ # The Environment name
23
+ attr_reader :name
24
+
25
+ # The authority used to acquire an AD token
26
+ attr_reader :active_directory_authority
27
+
28
+ # The resource ID used to obtain an AD token
29
+ attr_reader :active_directory_resource_id
30
+
31
+ # The template gallery endpoint
32
+ attr_reader :gallery_url
33
+
34
+ # The Active Directory resource ID
35
+ attr_reader :graph_url
36
+
37
+ # The api-version for Active Directory
38
+ attr_reader :graph_api_version
39
+
40
+ # The KeyValut service DNS suffix
41
+ attr_reader :key_vault_dns_suffix
42
+
43
+ # The KeyVault service resource ID
44
+ attr_reader :key_vault_service_resource_id
45
+
46
+ # The publish settings file URL
47
+ attr_reader :publish_settings_file_url
48
+
49
+ # The resource management endpoint
50
+ attr_reader :resource_manager_url
51
+
52
+ # The service management URL
53
+ attr_reader :service_management_url
54
+
55
+ # The DNS suffix for SQL Server instances
56
+ attr_reader :sql_database_dns_suffix
57
+
58
+ # The endpoint suffix for storage accounts
59
+ attr_reader :storage_suffix
60
+
61
+ # The DNS suffix for TrafficManager
62
+ attr_reader :traffic_manager_dns_suffix
63
+
64
+ # Creates a new Azure::Armrest::Environment object. At a minimum, the
65
+ # options hash must include the :name, :active_directory_authority and
66
+ # :active_directory_resource_id.
67
+ #
68
+ # Note that there are pre-generated environments already for Public
69
+ # and US Government environments.
70
+ #
71
+ def initialize(options)
72
+ options.symbolize_keys.each do |key, value|
73
+ raise ArgumentError, "Invalid key '#{key}'" unless VALID_KEYS.include?(key)
74
+ instance_variable_set("@#{key}", value)
75
+ end
76
+
77
+ [:name, :active_directory_authority, :resource_manager_url].each do |key|
78
+ unless instance_variable_get("@#{key}")
79
+ raise ArgumentError, "Mandatory argument '#{key}' not set"
80
+ end
81
+ end
82
+ end
83
+
84
+ alias authority_url active_directory_authority
85
+ alias resource_url resource_manager_url
86
+
87
+ # Pre-generated environments
88
+
89
+ Public = self.new(
90
+ :name => 'Public',
91
+ :active_directory_authority => 'https://login.microsoftonline.com/',
92
+ :active_directory_resource_id => 'https://management.core.windows.net/',
93
+ :gallery_url => 'https://gallery.azure.com/',
94
+ :graph_url => 'https://graph.windows.net/',
95
+ :graph_api_version => '1.6',
96
+ :key_vault_dns_suffix => 'vault.azure.net',
97
+ :key_vault_service_resource_id => 'https://vault.azure.net',
98
+ :publish_settings_file_url => 'https://manage.windowsazure.com/publishsettings/index',
99
+ :resource_manager_url => 'https://management.azure.com/',
100
+ :service_management_url => 'https://management.core.windows.net/',
101
+ :sql_database_dns_suffix => 'database.windows.net',
102
+ :storage_suffix => 'core.windows.net',
103
+ :traffic_manager_dns_suffix => 'trafficmanager.net',
104
+ )
105
+
106
+ USGovernment = self.new(
107
+ :name => 'US Government',
108
+ :active_directory_authority => 'https://login-us.microsoftonline.com/',
109
+ :active_directory_resource_id => 'https://management.core.usgovcloudapi.net/',
110
+ :gallery_url => 'https://gallery.usgovcloudapi.net/',
111
+ :graph_url => 'https://graph.windows.net/',
112
+ :graph_api_version => '1.6',
113
+ :key_vault_dns_suffix => 'vault.usgovcloudapi.net',
114
+ :key_vault_service_resource_id => 'https://vault.usgovcloudapi.net',
115
+ :publish_settings_file_url => 'https://manage.windowsazure.us/publishsettings/index',
116
+ :resource_manager_url => 'https://management.usgovcloudapi.net/',
117
+ :service_management_url => 'https://management.core.usgovcloudapi.net/',
118
+ :sql_database_dns_suffix => 'database.usgovcloudapi.net',
119
+ :storage_suffix => 'core.usgovcloudapi.net',
120
+ :traffic_manager_dns_suffix => 'usgovtrafficmanager.net',
121
+ )
122
+ end
123
+ end
124
+ end
@@ -80,7 +80,7 @@ module Azure
80
80
 
81
81
  def build_url(resource_id)
82
82
  url = File.join(
83
- configuration.resource_url,
83
+ configuration.environment.resource_url,
84
84
  resource_id,
85
85
  'providers',
86
86
  provider,
@@ -107,7 +107,7 @@ module Azure
107
107
  info['subservice_name'])
108
108
  service_name = info['subservice_name'] || info['service_name'] || 'resourceGroups'
109
109
 
110
- url = File.join(configuration.resource_url, id_string) + "?api-version=#{api_version}"
110
+ url = File.join(configuration.environment.resource_url, id_string) + "?api-version=#{api_version}"
111
111
 
112
112
  model_class = SERVICE_NAME_MAP.fetch(service_name.downcase) do
113
113
  raise ArgumentError, "unable to map service name #{service_name} to model"
@@ -120,10 +120,8 @@ module Azure
120
120
 
121
121
  def delete_by_id(id_string)
122
122
  info = parse_id_string(id_string)
123
- api_version = api_version_lookup(info['provider'],
124
- info['service_name'],
125
- info['subservice_name'])
126
- url = File.join(configuration.resource_url, id_string) + "?api-version=#{api_version}"
123
+ api_version = api_version_lookup(info['provider'], info['service_name'], info['subservice_name'])
124
+ url = File.join(configuration.environment.resource_url, id_string) + "?api-version=#{api_version}"
127
125
 
128
126
  delete_by_url(url, id_string)
129
127
  end
@@ -217,7 +215,7 @@ module Azure
217
215
  # arguments provided, and appends it with the api_version.
218
216
  #
219
217
  def build_url(resource_group = nil, *args)
220
- url = File.join(configuration.resource_url, build_id_string(resource_group, *args))
218
+ url = File.join(configuration.environment.resource_url, build_id_string(resource_group, *args))
221
219
  url << "?api-version=#{@api_version}"
222
220
  end
223
221
 
@@ -61,7 +61,7 @@ module Azure
61
61
  end
62
62
 
63
63
  def _list_all
64
- url = File.join(configuration.resource_url, 'providers')
64
+ url = File.join(configuration.environment.resource_url, 'providers')
65
65
  url << "?api-version=#{@api_version}"
66
66
  response = rest_get(url)
67
67
  JSON.parse(response)['value']
@@ -56,7 +56,7 @@ module Azure
56
56
  #
57
57
  def move(source_group, source_subscription = configuration.subscription_id)
58
58
  url = File.join(
59
- configuration.resource_url,
59
+ configuration.environment.resource_url,
60
60
  'subscriptions',
61
61
  source_subscription,
62
62
  'resourcegroups',
@@ -78,7 +78,7 @@ module Azure
78
78
  #
79
79
  def check_resource(resource_name, resource_type)
80
80
  body = JSON.dump(:Name => resource_name, :Type => resource_type)
81
- url = File.join(Azure::Armrest::RESOURCE, 'providers', provider, 'checkresourcename')
81
+ url = File.join(configuration.environment.resource_url, 'providers', provider, 'checkresourcename')
82
82
  url << "?api-version=#{@api_version}"
83
83
 
84
84
  response = rest_post(url, body)
@@ -28,7 +28,7 @@ module Azure
28
28
  private
29
29
 
30
30
  def subscriptions_url
31
- File.join(configuration.resource_url, 'subscriptions')
31
+ File.join(configuration.environment.resource_url, 'subscriptions')
32
32
  end
33
33
  end
34
34
  end
@@ -1,6 +1,6 @@
1
1
  module Azure
2
2
  module Armrest
3
3
  # The version of the azure-armrest library.
4
- VERSION = '0.4.2'.freeze
4
+ VERSION = '0.5.0'.freeze
5
5
  end
6
6
  end
@@ -28,8 +28,7 @@ module Azure
28
28
  end
29
29
 
30
30
  url = url_with_api_version(
31
- version, @base_url, 'subscriptions', configuration.subscription_id,
32
- 'providers', provider, 'locations', location, 'vmSizes'
31
+ version, base_url, 'providers', provider, 'locations', location, 'vmSizes'
33
32
  )
34
33
 
35
34
  JSON.parse(rest_get(url))['value'].map{ |hash| VirtualMachineSize.new(hash) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: azure-armrest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-12-19 00:00:00.000000000 Z
14
+ date: 2016-12-20 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: json
@@ -238,6 +238,7 @@ files:
238
238
  - lib/azure/armrest/availability_set_service.rb
239
239
  - lib/azure/armrest/billing/usage_service.rb
240
240
  - lib/azure/armrest/configuration.rb
241
+ - lib/azure/armrest/environment.rb
241
242
  - lib/azure/armrest/exception.rb
242
243
  - lib/azure/armrest/insights/alert_service.rb
243
244
  - lib/azure/armrest/insights/diagnostic_service.rb