diff --git a/README.md b/README.md index 3edb2f3090..e65cde0fd9 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,6 @@ Additional info on Azure deployment models [https://azure.microsoft.com/en-us/do Note: x64 Ruby for Windows is known to have some compatibility issues. # Getting Started with Azure Resource Manager Usage (Preview) - ## Install the rubygem packages You can install the azure rubygem packages directly. @@ -97,6 +96,72 @@ see [Developer’s guide to auth with Azure Resource Manager API](http://aka.ms/ After creating the service principal, you should have three pieces of information, a client id (GUID), client secret (string) and tenant id (GUID) or domain name (string). +## Prerequisite + +In order to use the Azure SDK, you must supply the following values to the Azure SDK: + +* Tenant Id +* Client Id +* Subscription Id +* Client Secret + +You could pass the above values in the following ways: + +### Option 1 - Environment Variables +You can set the (above) values using the following environment variables: + +* AZURE_TENANT_ID +* AZURE_CLIENT_ID +* AZURE_SUBSCRIPTION_ID +* AZURE_CLIENT_SECRET + +To set the environment variables, in Windows, you could use the command such as: + +``` +set AZURE_TENANT_ID= +``` + +In Unix based systems, you could use the command such as: + +``` +export AZURE_TENANT_ID= +``` + +### Option 2 - Options Hash +The initialization of profile clients take an options hash as a parameter. This options hash consists of tenant_id, client_id, client_secret, subscription_id, active_directory_settings and credentials. Among these, the active_directory_settings and credentials are optional. + +You can set the (above) values using the options hash: + +```ruby +options = { + tenant_id: 'YOUR TENANT ID', + client_id: 'YOUR CLIENT ID', + client_secret: 'YOUR CLIENT SECRET', + subscription_id: 'YOUR SUBSCRIPTION ID' +} +``` + +If you would like to pass in the credentials object, you could use the the following code: + +```ruby +provider = MsRestAzure::ApplicationTokenProvider.new( + 'YOUR TENANT ID', + 'YOUR CLIENT ID', + 'YOUR CLIENT SECRET') +credentials = MsRest::TokenCredentials.new(provider) + +options = { + tenant_id: 'YOUR TENANT ID', + client_id: 'YOUR CLIENT ID', + client_secret: 'YOUR CLIENT SECRET', + subscription_id: 'YOUR SUBSCRIPTION ID', + credentials: credentials +} +``` + +### Option 3 - Combination of Environment Variables & Options Hash +You can set the (above) values using a combination of environment variables and options hash. The values mentioned in the options hash will take precedence over the environment variables. + # Azure Multiple API versions & Profiles With 0.15.0 of Azure SDK, multiple API versions and profiles are introduced. With these changes, each individual gem @@ -150,14 +215,10 @@ The following lines should be used to instantiate a profile client: ```ruby # Provide credentials -provider = MsRestAzure::ApplicationTokenProvider.new( - ENV['AZURE_TENANT_ID'], - ENV['AZURE_CLIENT_ID'], - ENV['AZURE_CLIENT_SECRET']) -credentials = MsRest::TokenCredentials.new(provider) - options = { - credentials: credentials, + tenant_id: ENV['AZURE_TENANT_ID'], + client_id: ENV['AZURE_CLIENT_ID'], + client_secret: ENV['AZURE_CLIENT_SECRET'], subscription_id: ENV['AZURE_SUBSCRIPTION_ID'] } @@ -195,14 +256,10 @@ The following lines should be used to instantiate a profile client: ```ruby # Provide credentials -provider = MsRestAzure::ApplicationTokenProvider.new( - ENV['AZURE_TENANT_ID'], - ENV['AZURE_CLIENT_ID'], - ENV['AZURE_CLIENT_SECRET']) -credentials = MsRest::TokenCredentials.new(provider) - options = { - credentials: credentials, + tenant_id: ENV['AZURE_TENANT_ID'], + client_id: ENV['AZURE_CLIENT_ID'], + client_secret: ENV['AZURE_CLIENT_SECRET'], subscription_id: ENV['AZURE_SUBSCRIPTION_ID'] } @@ -226,8 +283,7 @@ purchase_plan_obj = Azure::Compute::Profiles::Latest::Mgmt::Models::PurchasePlan ## Usage of Individual gem using using specific api-version -In the previous section, we used the profile associated with individual gem. In the current section, we could use the -version directly. +In the previous section, we used the profile associated with individual gem. In the current section, we could use the version directly. ### Install @@ -241,6 +297,8 @@ gem install 'azure_mgmt_compute' The following lines should be used to instantiate a profile client: ```ruby +# To use this scenario, you must specify the tenant id, client id, subscription id +# and client secret using the environment variables. # Provide credentials provider = MsRestAzure::ApplicationTokenProvider.new( ENV['AZURE_TENANT_ID'], @@ -248,14 +306,9 @@ provider = MsRestAzure::ApplicationTokenProvider.new( ENV['AZURE_CLIENT_SECRET']) credentials = MsRest::TokenCredentials.new(provider) -options = { - credentials: credentials, - subscription_id: ENV['AZURE_SUBSCRIPTION_ID'] -} - # Target client for 2016_03_30 version of Compute compute_client = Azure::Compute::Mgmt::V2016_03_30::ComputeManagementClient.new(credentials) -compute_client.subscription_id = subscription_id +compute_client.subscription_id = ENV['AZURE_SUBSCRIPTION_ID'] ``` The compute client could be used to access operations and models: diff --git a/Rakefile b/Rakefile index d02bc72bf4..13ad7616c3 100644 --- a/Rakefile +++ b/Rakefile @@ -172,6 +172,9 @@ namespace :arm do # bundle exec ruby profile_generator_client.rb --dir_metadata=dir_metadata.json --profile=profiles.json command = "#{get_base_profile_generation_cmd}#{get_profile_spec_files_folder}/#{PROFILE_METADATA[:azure_sdk]}" execute_and_stream(command) + + FileUtils.cp("#{__dir__}/generators/profilegen/src/resources/common/configurable.rb", "#{__dir__}/azure_sdk/lib/common/configurable.rb") + FileUtils.cp("#{__dir__}/generators/profilegen/src/resources/common/default.rb", "#{__dir__}/azure_sdk/lib/common/default.rb") end desc 'Regen individual profiles' @@ -183,6 +186,9 @@ namespace :arm do # bundle exec ruby profile_generator_client.rb --dir_metadata=dir_metadata.json --profile=authorization_profiles.json command = "#{get_base_profile_generation_cmd}#{get_profile_spec_files_folder}/#{profile_spec_file}" execute_and_stream(command) + + FileUtils.cp("#{__dir__}/generators/profilegen/src/resources/common/configurable.rb", "#{__dir__}/management/#{sdk}/lib/profiles/common/configurable.rb") + FileUtils.cp("#{__dir__}/generators/profilegen/src/resources/common/default.rb", "#{__dir__}/management/#{sdk}/lib/profiles/common/default.rb") end end end diff --git a/azure_sdk/lib/common/configurable.rb b/azure_sdk/lib/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/azure_sdk/lib/common/configurable.rb +++ b/azure_sdk/lib/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/azure_sdk/lib/common/default.rb b/azure_sdk/lib/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/azure_sdk/lib/common/default.rb +++ b/azure_sdk/lib/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/azure_sdk/lib/latest/latest_profile_client.rb b/azure_sdk/lib/latest/latest_profile_client.rb index 6faf3987d7..8c30c5f827 100644 --- a/azure_sdk/lib/latest/latest_profile_client.rb +++ b/azure_sdk/lib/latest/latest_profile_client.rb @@ -68,13 +68,13 @@ module Azure::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client - include Azure::ARM::Configurable + include Azure::Common::Configurable attr_reader :analysis_services, :authorization, :automation, :batch, :billing, :cdn, :cognitive_services, :commerce, :compute, :consumption, :container_instance, :container_registry, :container_service, :customer_insights, :data_lake_analytics, :data_lake_store, :dev_test_labs, :dns, :event_grid, :event_hub, :features, :graph, :iot_hub, :key_vault, :links, :locks, :logic, :machine_learning, :managed_applications, :marketplace_ordering, :media_services, :mobile_engagement, :monitor, :network, :notification_hubs, :operational_insights, :policy, :power_bi_embedded, :recovery_services, :recovery_services_backup, :recovery_services_site_recovery, :redis, :relay, :resources, :resources_management, :scheduler, :search, :server_management, :service_bus, :service_fabric, :sql, :stor_simple8000_series, :storage, :stream_analytics, :subscriptions, :traffic_manager, :web def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end @@ -140,15 +140,5 @@ def initialize(options = {}) @web = Azure::Profiles::Latest::Web::Mgmt::WebClass.new(self) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/azure_sdk/lib/v2017_03_09/v2017_03_09_profile_client.rb b/azure_sdk/lib/v2017_03_09/v2017_03_09_profile_client.rb index ef6d48ff13..fc348c2c3f 100644 --- a/azure_sdk/lib/v2017_03_09/v2017_03_09_profile_client.rb +++ b/azure_sdk/lib/v2017_03_09/v2017_03_09_profile_client.rb @@ -20,13 +20,13 @@ module Azure::Profiles::V2017_03_09::Mgmt # Client class for the V2017_03_09 profile SDK. # class Client - include Azure::ARM::Configurable + include Azure::Common::Configurable attr_reader :storage, :network, :compute, :features, :links, :locks, :policy, :resources, :subscriptions def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end @@ -44,15 +44,5 @@ def initialize(options = {}) @subscriptions = Azure::Profiles::V2017_03_09::Subscriptions::Mgmt::SubscriptionsClass.new(self) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/generators/profilegen/src/resources/common/configurable.rb b/generators/profilegen/src/resources/common/configurable.rb new file mode 100644 index 0000000000..0e4922239a --- /dev/null +++ b/generators/profilegen/src/resources/common/configurable.rb @@ -0,0 +1,86 @@ +# encoding: utf-8 +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. + +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. + module Configurable + # @return [String] Azure tenant id (also known as domain). + attr_accessor :tenant_id + + # @return [String] Azure client id. + attr_accessor :client_id + + # @return [String] Azure secret key. + attr_accessor :client_secret + + # @return [String] Azure subscription id. + attr_accessor :subscription_id + + # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure active directory service settings. + attr_accessor :active_directory_settings + + # @return [MsRest::ServiceClientCredentials] credentials to authorize HTTP requests made by the service client. + attr_accessor :credentials + + class << self + # + # List of configurable keys for {Azure::Common::Client}. + # @return [Array] of option keys. + # + def keys + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] + end + end + + # + # Set configuration options using a block. + # + def configure + yield self + end + + # + # Resets the configurable options to provided options or defaults. + # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. + # + def reset!(options = {}) + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] + instance_variable_set(:"@#{key}", options.fetch(key, default_value)) + end + + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + + self + end + + def config + self + end + + private + + # + # configures configurable options to default values + # + def setup_default_options + opts = {} + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] + end + + opts + end + end +end diff --git a/generators/profilegen/src/resources/common/default.rb b/generators/profilegen/src/resources/common/default.rb new file mode 100644 index 0000000000..aa6d7c577b --- /dev/null +++ b/generators/profilegen/src/resources/common/default.rb @@ -0,0 +1,57 @@ +# encoding: utf-8 +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. + +module Azure::Common + module Default + class << self + # + # Default Azure Tenant Id. + # @return [String] Azure Tenant Id. + # + def tenant_id + ENV['AZURE_TENANT_ID'] + end + + # + # Default Azure Client Id. + # @return [String] Azure Client Id. + # + def client_id + ENV['AZURE_CLIENT_ID'] + end + + # + # Default Azure Client Secret. + # @return [String] Azure Client Secret. + # + def client_secret + ENV['AZURE_CLIENT_SECRET'] + end + + # + # Default Azure Subscription Id. + # @return [String] Azure Subscription Id. + # + def subscription_id + ENV['AZURE_SUBSCRIPTION_ID'] + end + + # + # Default Azure Active Directory Service Settings. + # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. + # + def active_directory_settings + MsRestAzure::ActiveDirectoryServiceSettings.get_azure_settings + end + + # + # Configuration options. + # @return [Hash] Configuration options. + # + def options + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] + end + end + end +end diff --git a/generators/profilegen/src/resources/templates/client_template.template b/generators/profilegen/src/resources/templates/client_template.template index 67f85ce46e..aa1e1c64bb 100644 --- a/generators/profilegen/src/resources/templates/client_template.template +++ b/generators/profilegen/src/resources/templates/client_template.template @@ -31,7 +31,7 @@ module Azure::Profiles::<%= @profile_name %>::Mgmt <%- else -%> class Client <%- end -%> - include Azure::ARM::Configurable + include Azure::Common::Configurable <%- if !@individual_gem_profile -%> attr_reader <% @class_names.each_with_index do |class_name, index| %> :<%= class_name.gsub(/([a-z\d])([A-Z])/,'\1_\2').downcase %><% if index != @class_names.length - 1 %>,<% end %><% end %> @@ -42,7 +42,7 @@ module Azure::Profiles::<%= @profile_name %>::Mgmt super(options) <%- else -%> if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end @@ -55,15 +55,5 @@ module Azure::Profiles::<%= @profile_name %>::Mgmt <%- end -%> end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/generators/profilegen/src/resources/templates/module_template.template b/generators/profilegen/src/resources/templates/module_template.template index 38441d7f78..83b273125a 100644 --- a/generators/profilegen/src/resources/templates/module_template.template +++ b/generators/profilegen/src/resources/templates/module_template.template @@ -35,7 +35,7 @@ module Azure::Profiles::<%= @profile_name %> <%- if @individual_gem_profile -%> def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_analysis_services/lib/profiles/common/configurable.rb b/management/azure_mgmt_analysis_services/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_analysis_services/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_analysis_services/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_analysis_services/lib/profiles/common/default.rb b/management/azure_mgmt_analysis_services/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_analysis_services/lib/profiles/common/default.rb +++ b/management/azure_mgmt_analysis_services/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_analysis_services/lib/profiles/latest/analysisservices_latest_profile_client.rb b/management/azure_mgmt_analysis_services/lib/profiles/latest/analysisservices_latest_profile_client.rb index d62f771dad..073ce57845 100644 --- a/management/azure_mgmt_analysis_services/lib/profiles/latest/analysisservices_latest_profile_client.rb +++ b/management/azure_mgmt_analysis_services/lib/profiles/latest/analysisservices_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::AnalysisServices::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < AnalysisServicesClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_analysis_services/lib/profiles/latest/modules/analysisservices_profile_module.rb b/management/azure_mgmt_analysis_services/lib/profiles/latest/modules/analysisservices_profile_module.rb index 654a23a564..242959ab2d 100644 --- a/management/azure_mgmt_analysis_services/lib/profiles/latest/modules/analysisservices_profile_module.rb +++ b/management/azure_mgmt_analysis_services/lib/profiles/latest/modules/analysisservices_profile_module.rb @@ -35,7 +35,7 @@ class AnalysisServicesClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_authorization/lib/profiles/common/configurable.rb b/management/azure_mgmt_authorization/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_authorization/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_authorization/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_authorization/lib/profiles/common/default.rb b/management/azure_mgmt_authorization/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_authorization/lib/profiles/common/default.rb +++ b/management/azure_mgmt_authorization/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_authorization/lib/profiles/latest/authorization_latest_profile_client.rb b/management/azure_mgmt_authorization/lib/profiles/latest/authorization_latest_profile_client.rb index 85073c9f4f..e5bc872a3c 100644 --- a/management/azure_mgmt_authorization/lib/profiles/latest/authorization_latest_profile_client.rb +++ b/management/azure_mgmt_authorization/lib/profiles/latest/authorization_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Authorization::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < AuthorizationClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_authorization/lib/profiles/latest/modules/authorization_profile_module.rb b/management/azure_mgmt_authorization/lib/profiles/latest/modules/authorization_profile_module.rb index c47bc2be7b..9024fb4173 100644 --- a/management/azure_mgmt_authorization/lib/profiles/latest/modules/authorization_profile_module.rb +++ b/management/azure_mgmt_authorization/lib/profiles/latest/modules/authorization_profile_module.rb @@ -41,7 +41,7 @@ class AuthorizationClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_automation/lib/profiles/common/configurable.rb b/management/azure_mgmt_automation/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_automation/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_automation/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_automation/lib/profiles/common/default.rb b/management/azure_mgmt_automation/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_automation/lib/profiles/common/default.rb +++ b/management/azure_mgmt_automation/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_automation/lib/profiles/latest/automation_latest_profile_client.rb b/management/azure_mgmt_automation/lib/profiles/latest/automation_latest_profile_client.rb index 7cb8572ab2..fa9ebea461 100644 --- a/management/azure_mgmt_automation/lib/profiles/latest/automation_latest_profile_client.rb +++ b/management/azure_mgmt_automation/lib/profiles/latest/automation_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Automation::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < AutomationClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_automation/lib/profiles/latest/modules/automation_profile_module.rb b/management/azure_mgmt_automation/lib/profiles/latest/modules/automation_profile_module.rb index 57d25445a5..369b88e084 100644 --- a/management/azure_mgmt_automation/lib/profiles/latest/modules/automation_profile_module.rb +++ b/management/azure_mgmt_automation/lib/profiles/latest/modules/automation_profile_module.rb @@ -173,7 +173,7 @@ class AutomationClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_batch/lib/profiles/common/configurable.rb b/management/azure_mgmt_batch/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_batch/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_batch/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_batch/lib/profiles/common/default.rb b/management/azure_mgmt_batch/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_batch/lib/profiles/common/default.rb +++ b/management/azure_mgmt_batch/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_batch/lib/profiles/latest/batch_latest_profile_client.rb b/management/azure_mgmt_batch/lib/profiles/latest/batch_latest_profile_client.rb index 493fb46220..dcea9ecdc9 100644 --- a/management/azure_mgmt_batch/lib/profiles/latest/batch_latest_profile_client.rb +++ b/management/azure_mgmt_batch/lib/profiles/latest/batch_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Batch::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < BatchClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_batch/lib/profiles/latest/modules/batch_profile_module.rb b/management/azure_mgmt_batch/lib/profiles/latest/modules/batch_profile_module.rb index 2de2ac1008..662da2bb5a 100644 --- a/management/azure_mgmt_batch/lib/profiles/latest/modules/batch_profile_module.rb +++ b/management/azure_mgmt_batch/lib/profiles/latest/modules/batch_profile_module.rb @@ -49,7 +49,7 @@ class BatchClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_billing/lib/profiles/common/configurable.rb b/management/azure_mgmt_billing/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_billing/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_billing/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_billing/lib/profiles/common/default.rb b/management/azure_mgmt_billing/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_billing/lib/profiles/common/default.rb +++ b/management/azure_mgmt_billing/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_billing/lib/profiles/latest/billing_latest_profile_client.rb b/management/azure_mgmt_billing/lib/profiles/latest/billing_latest_profile_client.rb index bc8b263273..f4e2149890 100644 --- a/management/azure_mgmt_billing/lib/profiles/latest/billing_latest_profile_client.rb +++ b/management/azure_mgmt_billing/lib/profiles/latest/billing_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Billing::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < BillingClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_billing/lib/profiles/latest/modules/billing_profile_module.rb b/management/azure_mgmt_billing/lib/profiles/latest/modules/billing_profile_module.rb index b658ba02db..86acd56d30 100644 --- a/management/azure_mgmt_billing/lib/profiles/latest/modules/billing_profile_module.rb +++ b/management/azure_mgmt_billing/lib/profiles/latest/modules/billing_profile_module.rb @@ -31,7 +31,7 @@ class BillingClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_cdn/lib/profiles/common/configurable.rb b/management/azure_mgmt_cdn/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_cdn/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_cdn/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_cdn/lib/profiles/common/default.rb b/management/azure_mgmt_cdn/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_cdn/lib/profiles/common/default.rb +++ b/management/azure_mgmt_cdn/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_cdn/lib/profiles/latest/cdn_latest_profile_client.rb b/management/azure_mgmt_cdn/lib/profiles/latest/cdn_latest_profile_client.rb index c933eb1705..f605b4e016 100644 --- a/management/azure_mgmt_cdn/lib/profiles/latest/cdn_latest_profile_client.rb +++ b/management/azure_mgmt_cdn/lib/profiles/latest/cdn_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::CDN::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < CDNClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_cdn/lib/profiles/latest/modules/cdn_profile_module.rb b/management/azure_mgmt_cdn/lib/profiles/latest/modules/cdn_profile_module.rb index f90b50067d..de174207c7 100644 --- a/management/azure_mgmt_cdn/lib/profiles/latest/modules/cdn_profile_module.rb +++ b/management/azure_mgmt_cdn/lib/profiles/latest/modules/cdn_profile_module.rb @@ -71,7 +71,7 @@ class CDNClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_cognitive_services/lib/profiles/common/configurable.rb b/management/azure_mgmt_cognitive_services/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_cognitive_services/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_cognitive_services/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_cognitive_services/lib/profiles/common/default.rb b/management/azure_mgmt_cognitive_services/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_cognitive_services/lib/profiles/common/default.rb +++ b/management/azure_mgmt_cognitive_services/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_cognitive_services/lib/profiles/latest/cognitiveservices_latest_profile_client.rb b/management/azure_mgmt_cognitive_services/lib/profiles/latest/cognitiveservices_latest_profile_client.rb index 38dd8db55f..b07146594e 100644 --- a/management/azure_mgmt_cognitive_services/lib/profiles/latest/cognitiveservices_latest_profile_client.rb +++ b/management/azure_mgmt_cognitive_services/lib/profiles/latest/cognitiveservices_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::CognitiveServices::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < CognitiveServicesClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_cognitive_services/lib/profiles/latest/modules/cognitiveservices_profile_module.rb b/management/azure_mgmt_cognitive_services/lib/profiles/latest/modules/cognitiveservices_profile_module.rb index 6f035269f7..87dad0f6e6 100644 --- a/management/azure_mgmt_cognitive_services/lib/profiles/latest/modules/cognitiveservices_profile_module.rb +++ b/management/azure_mgmt_cognitive_services/lib/profiles/latest/modules/cognitiveservices_profile_module.rb @@ -42,7 +42,7 @@ class CognitiveServicesClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_commerce/lib/profiles/common/configurable.rb b/management/azure_mgmt_commerce/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_commerce/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_commerce/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_commerce/lib/profiles/common/default.rb b/management/azure_mgmt_commerce/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_commerce/lib/profiles/common/default.rb +++ b/management/azure_mgmt_commerce/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_commerce/lib/profiles/latest/commerce_latest_profile_client.rb b/management/azure_mgmt_commerce/lib/profiles/latest/commerce_latest_profile_client.rb index e8641b7d29..8168009c79 100644 --- a/management/azure_mgmt_commerce/lib/profiles/latest/commerce_latest_profile_client.rb +++ b/management/azure_mgmt_commerce/lib/profiles/latest/commerce_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Commerce::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < CommerceClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_commerce/lib/profiles/latest/modules/commerce_profile_module.rb b/management/azure_mgmt_commerce/lib/profiles/latest/modules/commerce_profile_module.rb index 0cae9c46ec..ea1f5f8ae0 100644 --- a/management/azure_mgmt_commerce/lib/profiles/latest/modules/commerce_profile_module.rb +++ b/management/azure_mgmt_commerce/lib/profiles/latest/modules/commerce_profile_module.rb @@ -31,7 +31,7 @@ class CommerceClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_compute/lib/profiles/common/configurable.rb b/management/azure_mgmt_compute/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_compute/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_compute/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_compute/lib/profiles/common/default.rb b/management/azure_mgmt_compute/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_compute/lib/profiles/common/default.rb +++ b/management/azure_mgmt_compute/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_compute/lib/profiles/latest/compute_latest_profile_client.rb b/management/azure_mgmt_compute/lib/profiles/latest/compute_latest_profile_client.rb index 140adf3a23..d399917cf3 100644 --- a/management/azure_mgmt_compute/lib/profiles/latest/compute_latest_profile_client.rb +++ b/management/azure_mgmt_compute/lib/profiles/latest/compute_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Compute::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < ComputeClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_compute/lib/profiles/latest/modules/compute_profile_module.rb b/management/azure_mgmt_compute/lib/profiles/latest/modules/compute_profile_module.rb index eebb0ca119..f4cc103d29 100644 --- a/management/azure_mgmt_compute/lib/profiles/latest/modules/compute_profile_module.rb +++ b/management/azure_mgmt_compute/lib/profiles/latest/modules/compute_profile_module.rb @@ -200,7 +200,7 @@ class ComputeClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_compute/lib/profiles/v2017_03_09/compute_v2017_03_09_profile_client.rb b/management/azure_mgmt_compute/lib/profiles/v2017_03_09/compute_v2017_03_09_profile_client.rb index 31d178f352..3f96ed99eb 100644 --- a/management/azure_mgmt_compute/lib/profiles/v2017_03_09/compute_v2017_03_09_profile_client.rb +++ b/management/azure_mgmt_compute/lib/profiles/v2017_03_09/compute_v2017_03_09_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Compute::Profiles::V2017_03_09::Mgmt # Client class for the V2017_03_09 profile SDK. # class Client < ComputeClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_compute/lib/profiles/v2017_03_09/modules/compute_profile_module.rb b/management/azure_mgmt_compute/lib/profiles/v2017_03_09/modules/compute_profile_module.rb index 1fc92ece89..15a1923695 100644 --- a/management/azure_mgmt_compute/lib/profiles/v2017_03_09/modules/compute_profile_module.rb +++ b/management/azure_mgmt_compute/lib/profiles/v2017_03_09/modules/compute_profile_module.rb @@ -124,7 +124,7 @@ class ComputeClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_consumption/lib/profiles/common/configurable.rb b/management/azure_mgmt_consumption/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_consumption/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_consumption/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_consumption/lib/profiles/common/default.rb b/management/azure_mgmt_consumption/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_consumption/lib/profiles/common/default.rb +++ b/management/azure_mgmt_consumption/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_consumption/lib/profiles/latest/consumption_latest_profile_client.rb b/management/azure_mgmt_consumption/lib/profiles/latest/consumption_latest_profile_client.rb index 34563e02b2..a0ee788786 100644 --- a/management/azure_mgmt_consumption/lib/profiles/latest/consumption_latest_profile_client.rb +++ b/management/azure_mgmt_consumption/lib/profiles/latest/consumption_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Consumption::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < ConsumptionClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_consumption/lib/profiles/latest/modules/consumption_profile_module.rb b/management/azure_mgmt_consumption/lib/profiles/latest/modules/consumption_profile_module.rb index ac08e6f6ca..e5f8180ef2 100644 --- a/management/azure_mgmt_consumption/lib/profiles/latest/modules/consumption_profile_module.rb +++ b/management/azure_mgmt_consumption/lib/profiles/latest/modules/consumption_profile_module.rb @@ -28,7 +28,7 @@ class ConsumptionClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_container_instance/lib/profiles/common/configurable.rb b/management/azure_mgmt_container_instance/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_container_instance/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_container_instance/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_container_instance/lib/profiles/common/default.rb b/management/azure_mgmt_container_instance/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_container_instance/lib/profiles/common/default.rb +++ b/management/azure_mgmt_container_instance/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_container_instance/lib/profiles/latest/containerinstance_latest_profile_client.rb b/management/azure_mgmt_container_instance/lib/profiles/latest/containerinstance_latest_profile_client.rb index 6aa9ff6633..e4ca82fe79 100644 --- a/management/azure_mgmt_container_instance/lib/profiles/latest/containerinstance_latest_profile_client.rb +++ b/management/azure_mgmt_container_instance/lib/profiles/latest/containerinstance_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::ContainerInstance::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < ContainerInstanceClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_container_instance/lib/profiles/latest/modules/containerinstance_profile_module.rb b/management/azure_mgmt_container_instance/lib/profiles/latest/modules/containerinstance_profile_module.rb index 382940c985..0d5c922164 100644 --- a/management/azure_mgmt_container_instance/lib/profiles/latest/modules/containerinstance_profile_module.rb +++ b/management/azure_mgmt_container_instance/lib/profiles/latest/modules/containerinstance_profile_module.rb @@ -41,7 +41,7 @@ class ContainerInstanceClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_container_registry/lib/profiles/common/configurable.rb b/management/azure_mgmt_container_registry/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_container_registry/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_container_registry/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_container_registry/lib/profiles/common/default.rb b/management/azure_mgmt_container_registry/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_container_registry/lib/profiles/common/default.rb +++ b/management/azure_mgmt_container_registry/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_container_registry/lib/profiles/latest/containerregistry_latest_profile_client.rb b/management/azure_mgmt_container_registry/lib/profiles/latest/containerregistry_latest_profile_client.rb index d8a8406dfd..2195400305 100644 --- a/management/azure_mgmt_container_registry/lib/profiles/latest/containerregistry_latest_profile_client.rb +++ b/management/azure_mgmt_container_registry/lib/profiles/latest/containerregistry_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::ContainerRegistry::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < ContainerRegistryClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_container_registry/lib/profiles/latest/modules/containerregistry_profile_module.rb b/management/azure_mgmt_container_registry/lib/profiles/latest/modules/containerregistry_profile_module.rb index 8d1769babf..e178b2d311 100644 --- a/management/azure_mgmt_container_registry/lib/profiles/latest/modules/containerregistry_profile_module.rb +++ b/management/azure_mgmt_container_registry/lib/profiles/latest/modules/containerregistry_profile_module.rb @@ -63,7 +63,7 @@ class ContainerRegistryClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_container_service/lib/profiles/common/configurable.rb b/management/azure_mgmt_container_service/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_container_service/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_container_service/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_container_service/lib/profiles/common/default.rb b/management/azure_mgmt_container_service/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_container_service/lib/profiles/common/default.rb +++ b/management/azure_mgmt_container_service/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_container_service/lib/profiles/latest/containerservice_latest_profile_client.rb b/management/azure_mgmt_container_service/lib/profiles/latest/containerservice_latest_profile_client.rb index 03cb6c304d..cbcadd6b92 100644 --- a/management/azure_mgmt_container_service/lib/profiles/latest/containerservice_latest_profile_client.rb +++ b/management/azure_mgmt_container_service/lib/profiles/latest/containerservice_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::ContainerService::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < ContainerServiceClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_container_service/lib/profiles/latest/modules/containerservice_profile_module.rb b/management/azure_mgmt_container_service/lib/profiles/latest/modules/containerservice_profile_module.rb index 7c34d6a264..cdc8b0fedb 100644 --- a/management/azure_mgmt_container_service/lib/profiles/latest/modules/containerservice_profile_module.rb +++ b/management/azure_mgmt_container_service/lib/profiles/latest/modules/containerservice_profile_module.rb @@ -34,7 +34,7 @@ class ContainerServiceClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_customer_insights/lib/profiles/common/configurable.rb b/management/azure_mgmt_customer_insights/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_customer_insights/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_customer_insights/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_customer_insights/lib/profiles/common/default.rb b/management/azure_mgmt_customer_insights/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_customer_insights/lib/profiles/common/default.rb +++ b/management/azure_mgmt_customer_insights/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_customer_insights/lib/profiles/latest/customerinsights_latest_profile_client.rb b/management/azure_mgmt_customer_insights/lib/profiles/latest/customerinsights_latest_profile_client.rb index f0d203b55a..092c12ea18 100644 --- a/management/azure_mgmt_customer_insights/lib/profiles/latest/customerinsights_latest_profile_client.rb +++ b/management/azure_mgmt_customer_insights/lib/profiles/latest/customerinsights_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::CustomerInsights::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < CustomerInsightsClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_customer_insights/lib/profiles/latest/modules/customerinsights_profile_module.rb b/management/azure_mgmt_customer_insights/lib/profiles/latest/modules/customerinsights_profile_module.rb index e953e880cb..ad61f9fd0c 100644 --- a/management/azure_mgmt_customer_insights/lib/profiles/latest/modules/customerinsights_profile_module.rb +++ b/management/azure_mgmt_customer_insights/lib/profiles/latest/modules/customerinsights_profile_module.rb @@ -138,7 +138,7 @@ class CustomerInsightsClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_datalake_analytics/lib/profiles/common/configurable.rb b/management/azure_mgmt_datalake_analytics/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_datalake_analytics/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_datalake_analytics/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_datalake_analytics/lib/profiles/common/default.rb b/management/azure_mgmt_datalake_analytics/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_datalake_analytics/lib/profiles/common/default.rb +++ b/management/azure_mgmt_datalake_analytics/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_datalake_analytics/lib/profiles/latest/datalakeanalytics_latest_profile_client.rb b/management/azure_mgmt_datalake_analytics/lib/profiles/latest/datalakeanalytics_latest_profile_client.rb index 2486298c02..04081ffc86 100644 --- a/management/azure_mgmt_datalake_analytics/lib/profiles/latest/datalakeanalytics_latest_profile_client.rb +++ b/management/azure_mgmt_datalake_analytics/lib/profiles/latest/datalakeanalytics_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::DataLakeAnalytics::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < DataLakeAnalyticsClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_datalake_analytics/lib/profiles/latest/modules/datalakeanalytics_profile_module.rb b/management/azure_mgmt_datalake_analytics/lib/profiles/latest/modules/datalakeanalytics_profile_module.rb index 7c2f34d90b..c6b1dc39a5 100644 --- a/management/azure_mgmt_datalake_analytics/lib/profiles/latest/modules/datalakeanalytics_profile_module.rb +++ b/management/azure_mgmt_datalake_analytics/lib/profiles/latest/modules/datalakeanalytics_profile_module.rb @@ -54,7 +54,7 @@ class DataLakeAnalyticsClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_datalake_store/lib/profiles/common/configurable.rb b/management/azure_mgmt_datalake_store/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_datalake_store/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_datalake_store/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_datalake_store/lib/profiles/common/default.rb b/management/azure_mgmt_datalake_store/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_datalake_store/lib/profiles/common/default.rb +++ b/management/azure_mgmt_datalake_store/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_datalake_store/lib/profiles/latest/datalakestore_latest_profile_client.rb b/management/azure_mgmt_datalake_store/lib/profiles/latest/datalakestore_latest_profile_client.rb index f9821007b2..9a0e9a52e9 100644 --- a/management/azure_mgmt_datalake_store/lib/profiles/latest/datalakestore_latest_profile_client.rb +++ b/management/azure_mgmt_datalake_store/lib/profiles/latest/datalakestore_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::DataLakeStore::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < DataLakeStoreClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_datalake_store/lib/profiles/latest/modules/datalakestore_profile_module.rb b/management/azure_mgmt_datalake_store/lib/profiles/latest/modules/datalakestore_profile_module.rb index 8fff546bf8..5ea35394cf 100644 --- a/management/azure_mgmt_datalake_store/lib/profiles/latest/modules/datalakestore_profile_module.rb +++ b/management/azure_mgmt_datalake_store/lib/profiles/latest/modules/datalakestore_profile_module.rb @@ -47,7 +47,7 @@ class DataLakeStoreClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_devtestlabs/lib/profiles/common/configurable.rb b/management/azure_mgmt_devtestlabs/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_devtestlabs/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_devtestlabs/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_devtestlabs/lib/profiles/common/default.rb b/management/azure_mgmt_devtestlabs/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_devtestlabs/lib/profiles/common/default.rb +++ b/management/azure_mgmt_devtestlabs/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_devtestlabs/lib/profiles/latest/devtestlabs_latest_profile_client.rb b/management/azure_mgmt_devtestlabs/lib/profiles/latest/devtestlabs_latest_profile_client.rb index b08bedc8bb..b45cf1dc3f 100644 --- a/management/azure_mgmt_devtestlabs/lib/profiles/latest/devtestlabs_latest_profile_client.rb +++ b/management/azure_mgmt_devtestlabs/lib/profiles/latest/devtestlabs_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::DevTestLabs::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < DevTestLabsClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_devtestlabs/lib/profiles/latest/modules/devtestlabs_profile_module.rb b/management/azure_mgmt_devtestlabs/lib/profiles/latest/modules/devtestlabs_profile_module.rb index 9e8ec681aa..18219dd018 100644 --- a/management/azure_mgmt_devtestlabs/lib/profiles/latest/modules/devtestlabs_profile_module.rb +++ b/management/azure_mgmt_devtestlabs/lib/profiles/latest/modules/devtestlabs_profile_module.rb @@ -188,7 +188,7 @@ class DevTestLabsClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_dns/lib/profiles/common/configurable.rb b/management/azure_mgmt_dns/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_dns/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_dns/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_dns/lib/profiles/common/default.rb b/management/azure_mgmt_dns/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_dns/lib/profiles/common/default.rb +++ b/management/azure_mgmt_dns/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_dns/lib/profiles/latest/dns_latest_profile_client.rb b/management/azure_mgmt_dns/lib/profiles/latest/dns_latest_profile_client.rb index fda838123a..f654247145 100644 --- a/management/azure_mgmt_dns/lib/profiles/latest/dns_latest_profile_client.rb +++ b/management/azure_mgmt_dns/lib/profiles/latest/dns_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Dns::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < DnsClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_dns/lib/profiles/latest/modules/dns_profile_module.rb b/management/azure_mgmt_dns/lib/profiles/latest/modules/dns_profile_module.rb index b0c44264e7..1bea62421c 100644 --- a/management/azure_mgmt_dns/lib/profiles/latest/modules/dns_profile_module.rb +++ b/management/azure_mgmt_dns/lib/profiles/latest/modules/dns_profile_module.rb @@ -38,7 +38,7 @@ class DnsClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_event_grid/lib/profiles/common/configurable.rb b/management/azure_mgmt_event_grid/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_event_grid/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_event_grid/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_event_grid/lib/profiles/common/default.rb b/management/azure_mgmt_event_grid/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_event_grid/lib/profiles/common/default.rb +++ b/management/azure_mgmt_event_grid/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_event_grid/lib/profiles/latest/eventgrid_latest_profile_client.rb b/management/azure_mgmt_event_grid/lib/profiles/latest/eventgrid_latest_profile_client.rb index e674fd6f72..25d836188b 100644 --- a/management/azure_mgmt_event_grid/lib/profiles/latest/eventgrid_latest_profile_client.rb +++ b/management/azure_mgmt_event_grid/lib/profiles/latest/eventgrid_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::EventGrid::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < EventGridClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_event_grid/lib/profiles/latest/modules/eventgrid_profile_module.rb b/management/azure_mgmt_event_grid/lib/profiles/latest/modules/eventgrid_profile_module.rb index 15272bfe8c..4720c5ab15 100644 --- a/management/azure_mgmt_event_grid/lib/profiles/latest/modules/eventgrid_profile_module.rb +++ b/management/azure_mgmt_event_grid/lib/profiles/latest/modules/eventgrid_profile_module.rb @@ -47,7 +47,7 @@ class EventGridClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_event_hub/lib/profiles/common/configurable.rb b/management/azure_mgmt_event_hub/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_event_hub/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_event_hub/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_event_hub/lib/profiles/common/default.rb b/management/azure_mgmt_event_hub/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_event_hub/lib/profiles/common/default.rb +++ b/management/azure_mgmt_event_hub/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_event_hub/lib/profiles/latest/eventhub_latest_profile_client.rb b/management/azure_mgmt_event_hub/lib/profiles/latest/eventhub_latest_profile_client.rb index 8042f4ac6f..40dd77bc50 100644 --- a/management/azure_mgmt_event_hub/lib/profiles/latest/eventhub_latest_profile_client.rb +++ b/management/azure_mgmt_event_hub/lib/profiles/latest/eventhub_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::EventHub::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < EventHubClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_event_hub/lib/profiles/latest/modules/eventhub_profile_module.rb b/management/azure_mgmt_event_hub/lib/profiles/latest/modules/eventhub_profile_module.rb index 4085fed65a..88366e4161 100644 --- a/management/azure_mgmt_event_hub/lib/profiles/latest/modules/eventhub_profile_module.rb +++ b/management/azure_mgmt_event_hub/lib/profiles/latest/modules/eventhub_profile_module.rb @@ -54,7 +54,7 @@ class EventHubClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_features/lib/profiles/common/configurable.rb b/management/azure_mgmt_features/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_features/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_features/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_features/lib/profiles/common/default.rb b/management/azure_mgmt_features/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_features/lib/profiles/common/default.rb +++ b/management/azure_mgmt_features/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_features/lib/profiles/latest/features_latest_profile_client.rb b/management/azure_mgmt_features/lib/profiles/latest/features_latest_profile_client.rb index 11e17d51b9..ee6fb1ecd1 100644 --- a/management/azure_mgmt_features/lib/profiles/latest/features_latest_profile_client.rb +++ b/management/azure_mgmt_features/lib/profiles/latest/features_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Features::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < FeaturesClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_features/lib/profiles/latest/modules/features_profile_module.rb b/management/azure_mgmt_features/lib/profiles/latest/modules/features_profile_module.rb index bcdbeb5910..e12603bc44 100644 --- a/management/azure_mgmt_features/lib/profiles/latest/modules/features_profile_module.rb +++ b/management/azure_mgmt_features/lib/profiles/latest/modules/features_profile_module.rb @@ -21,7 +21,7 @@ class FeaturesClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_features/lib/profiles/v2017_03_09/features_v2017_03_09_profile_client.rb b/management/azure_mgmt_features/lib/profiles/v2017_03_09/features_v2017_03_09_profile_client.rb index 6ce0044fa2..1c73533308 100644 --- a/management/azure_mgmt_features/lib/profiles/v2017_03_09/features_v2017_03_09_profile_client.rb +++ b/management/azure_mgmt_features/lib/profiles/v2017_03_09/features_v2017_03_09_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Features::Profiles::V2017_03_09::Mgmt # Client class for the V2017_03_09 profile SDK. # class Client < FeaturesClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_features/lib/profiles/v2017_03_09/modules/features_profile_module.rb b/management/azure_mgmt_features/lib/profiles/v2017_03_09/modules/features_profile_module.rb index b95ef9f20a..a86315adde 100644 --- a/management/azure_mgmt_features/lib/profiles/v2017_03_09/modules/features_profile_module.rb +++ b/management/azure_mgmt_features/lib/profiles/v2017_03_09/modules/features_profile_module.rb @@ -21,7 +21,7 @@ class FeaturesClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_graph/lib/profiles/common/configurable.rb b/management/azure_mgmt_graph/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_graph/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_graph/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_graph/lib/profiles/common/default.rb b/management/azure_mgmt_graph/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_graph/lib/profiles/common/default.rb +++ b/management/azure_mgmt_graph/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_graph/lib/profiles/latest/graph_latest_profile_client.rb b/management/azure_mgmt_graph/lib/profiles/latest/graph_latest_profile_client.rb index fbbe59e921..029c06419e 100644 --- a/management/azure_mgmt_graph/lib/profiles/latest/graph_latest_profile_client.rb +++ b/management/azure_mgmt_graph/lib/profiles/latest/graph_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Graph::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < GraphClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_graph/lib/profiles/latest/modules/graph_profile_module.rb b/management/azure_mgmt_graph/lib/profiles/latest/modules/graph_profile_module.rb index 338819bf9d..68c2da5bb3 100644 --- a/management/azure_mgmt_graph/lib/profiles/latest/modules/graph_profile_module.rb +++ b/management/azure_mgmt_graph/lib/profiles/latest/modules/graph_profile_module.rb @@ -62,7 +62,7 @@ class GraphClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_iot_hub/lib/profiles/common/configurable.rb b/management/azure_mgmt_iot_hub/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_iot_hub/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_iot_hub/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_iot_hub/lib/profiles/common/default.rb b/management/azure_mgmt_iot_hub/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_iot_hub/lib/profiles/common/default.rb +++ b/management/azure_mgmt_iot_hub/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_iot_hub/lib/profiles/latest/iothub_latest_profile_client.rb b/management/azure_mgmt_iot_hub/lib/profiles/latest/iothub_latest_profile_client.rb index 35f69793f8..2d81df4d94 100644 --- a/management/azure_mgmt_iot_hub/lib/profiles/latest/iothub_latest_profile_client.rb +++ b/management/azure_mgmt_iot_hub/lib/profiles/latest/iothub_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::IotHub::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < IotHubClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_iot_hub/lib/profiles/latest/modules/iothub_profile_module.rb b/management/azure_mgmt_iot_hub/lib/profiles/latest/modules/iothub_profile_module.rb index 2239f3678b..30ad6e959f 100644 --- a/management/azure_mgmt_iot_hub/lib/profiles/latest/modules/iothub_profile_module.rb +++ b/management/azure_mgmt_iot_hub/lib/profiles/latest/modules/iothub_profile_module.rb @@ -78,7 +78,7 @@ class IotHubClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_key_vault/lib/profiles/common/configurable.rb b/management/azure_mgmt_key_vault/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_key_vault/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_key_vault/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_key_vault/lib/profiles/common/default.rb b/management/azure_mgmt_key_vault/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_key_vault/lib/profiles/common/default.rb +++ b/management/azure_mgmt_key_vault/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_key_vault/lib/profiles/latest/keyvault_latest_profile_client.rb b/management/azure_mgmt_key_vault/lib/profiles/latest/keyvault_latest_profile_client.rb index ceb1788c7f..ceae4d7c8b 100644 --- a/management/azure_mgmt_key_vault/lib/profiles/latest/keyvault_latest_profile_client.rb +++ b/management/azure_mgmt_key_vault/lib/profiles/latest/keyvault_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::KeyVault::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < KeyVaultClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_key_vault/lib/profiles/latest/modules/keyvault_profile_module.rb b/management/azure_mgmt_key_vault/lib/profiles/latest/modules/keyvault_profile_module.rb index e85cbc1e5f..0f3f52b8da 100644 --- a/management/azure_mgmt_key_vault/lib/profiles/latest/modules/keyvault_profile_module.rb +++ b/management/azure_mgmt_key_vault/lib/profiles/latest/modules/keyvault_profile_module.rb @@ -36,7 +36,7 @@ class KeyVaultClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_links/lib/profiles/common/configurable.rb b/management/azure_mgmt_links/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_links/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_links/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_links/lib/profiles/common/default.rb b/management/azure_mgmt_links/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_links/lib/profiles/common/default.rb +++ b/management/azure_mgmt_links/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_links/lib/profiles/latest/links_latest_profile_client.rb b/management/azure_mgmt_links/lib/profiles/latest/links_latest_profile_client.rb index e296bbda9c..b458b355c8 100644 --- a/management/azure_mgmt_links/lib/profiles/latest/links_latest_profile_client.rb +++ b/management/azure_mgmt_links/lib/profiles/latest/links_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Links::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < LinksClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_links/lib/profiles/latest/modules/links_profile_module.rb b/management/azure_mgmt_links/lib/profiles/latest/modules/links_profile_module.rb index edb33276fa..abbf25588b 100644 --- a/management/azure_mgmt_links/lib/profiles/latest/modules/links_profile_module.rb +++ b/management/azure_mgmt_links/lib/profiles/latest/modules/links_profile_module.rb @@ -23,7 +23,7 @@ class LinksClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_links/lib/profiles/v2017_03_09/links_v2017_03_09_profile_client.rb b/management/azure_mgmt_links/lib/profiles/v2017_03_09/links_v2017_03_09_profile_client.rb index a942a3ef86..d228d47480 100644 --- a/management/azure_mgmt_links/lib/profiles/v2017_03_09/links_v2017_03_09_profile_client.rb +++ b/management/azure_mgmt_links/lib/profiles/v2017_03_09/links_v2017_03_09_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Links::Profiles::V2017_03_09::Mgmt # Client class for the V2017_03_09 profile SDK. # class Client < LinksClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_links/lib/profiles/v2017_03_09/modules/links_profile_module.rb b/management/azure_mgmt_links/lib/profiles/v2017_03_09/modules/links_profile_module.rb index 5990ce3969..44f8b7a6c8 100644 --- a/management/azure_mgmt_links/lib/profiles/v2017_03_09/modules/links_profile_module.rb +++ b/management/azure_mgmt_links/lib/profiles/v2017_03_09/modules/links_profile_module.rb @@ -23,7 +23,7 @@ class LinksClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_locks/lib/profiles/common/configurable.rb b/management/azure_mgmt_locks/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_locks/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_locks/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_locks/lib/profiles/common/default.rb b/management/azure_mgmt_locks/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_locks/lib/profiles/common/default.rb +++ b/management/azure_mgmt_locks/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_locks/lib/profiles/latest/locks_latest_profile_client.rb b/management/azure_mgmt_locks/lib/profiles/latest/locks_latest_profile_client.rb index 9e87ebbb76..a243054c98 100644 --- a/management/azure_mgmt_locks/lib/profiles/latest/locks_latest_profile_client.rb +++ b/management/azure_mgmt_locks/lib/profiles/latest/locks_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Locks::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < LocksClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_locks/lib/profiles/latest/modules/locks_profile_module.rb b/management/azure_mgmt_locks/lib/profiles/latest/modules/locks_profile_module.rb index 3353b8e6ed..9804c0656c 100644 --- a/management/azure_mgmt_locks/lib/profiles/latest/modules/locks_profile_module.rb +++ b/management/azure_mgmt_locks/lib/profiles/latest/modules/locks_profile_module.rb @@ -22,7 +22,7 @@ class LocksClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_locks/lib/profiles/v2017_03_09/locks_v2017_03_09_profile_client.rb b/management/azure_mgmt_locks/lib/profiles/v2017_03_09/locks_v2017_03_09_profile_client.rb index 4e712eadea..5ae21acbe2 100644 --- a/management/azure_mgmt_locks/lib/profiles/v2017_03_09/locks_v2017_03_09_profile_client.rb +++ b/management/azure_mgmt_locks/lib/profiles/v2017_03_09/locks_v2017_03_09_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Locks::Profiles::V2017_03_09::Mgmt # Client class for the V2017_03_09 profile SDK. # class Client < LocksClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_locks/lib/profiles/v2017_03_09/modules/locks_profile_module.rb b/management/azure_mgmt_locks/lib/profiles/v2017_03_09/modules/locks_profile_module.rb index 1e07ca5d8a..8c25f06fba 100644 --- a/management/azure_mgmt_locks/lib/profiles/v2017_03_09/modules/locks_profile_module.rb +++ b/management/azure_mgmt_locks/lib/profiles/v2017_03_09/modules/locks_profile_module.rb @@ -21,7 +21,7 @@ class LocksClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_logic/lib/profiles/common/configurable.rb b/management/azure_mgmt_logic/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_logic/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_logic/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_logic/lib/profiles/common/default.rb b/management/azure_mgmt_logic/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_logic/lib/profiles/common/default.rb +++ b/management/azure_mgmt_logic/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_logic/lib/profiles/latest/logic_latest_profile_client.rb b/management/azure_mgmt_logic/lib/profiles/latest/logic_latest_profile_client.rb index 013036aabf..a334e06e96 100644 --- a/management/azure_mgmt_logic/lib/profiles/latest/logic_latest_profile_client.rb +++ b/management/azure_mgmt_logic/lib/profiles/latest/logic_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Logic::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < LogicClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_logic/lib/profiles/latest/modules/logic_profile_module.rb b/management/azure_mgmt_logic/lib/profiles/latest/modules/logic_profile_module.rb index 3e6bfc1454..f183c5197c 100644 --- a/management/azure_mgmt_logic/lib/profiles/latest/modules/logic_profile_module.rb +++ b/management/azure_mgmt_logic/lib/profiles/latest/modules/logic_profile_module.rb @@ -165,7 +165,7 @@ class LogicClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_machine_learning/lib/profiles/common/configurable.rb b/management/azure_mgmt_machine_learning/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_machine_learning/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_machine_learning/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_machine_learning/lib/profiles/common/default.rb b/management/azure_mgmt_machine_learning/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_machine_learning/lib/profiles/common/default.rb +++ b/management/azure_mgmt_machine_learning/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_machine_learning/lib/profiles/latest/machinelearning_latest_profile_client.rb b/management/azure_mgmt_machine_learning/lib/profiles/latest/machinelearning_latest_profile_client.rb index 8ca5e24997..2cfe004adc 100644 --- a/management/azure_mgmt_machine_learning/lib/profiles/latest/machinelearning_latest_profile_client.rb +++ b/management/azure_mgmt_machine_learning/lib/profiles/latest/machinelearning_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::MachineLearning::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < MachineLearningClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_machine_learning/lib/profiles/latest/modules/machinelearning_profile_module.rb b/management/azure_mgmt_machine_learning/lib/profiles/latest/modules/machinelearning_profile_module.rb index 141f2b5d5a..a347e430ef 100644 --- a/management/azure_mgmt_machine_learning/lib/profiles/latest/modules/machinelearning_profile_module.rb +++ b/management/azure_mgmt_machine_learning/lib/profiles/latest/modules/machinelearning_profile_module.rb @@ -55,7 +55,7 @@ class MachineLearningClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_managed_applications/lib/profiles/common/configurable.rb b/management/azure_mgmt_managed_applications/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_managed_applications/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_managed_applications/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_managed_applications/lib/profiles/common/default.rb b/management/azure_mgmt_managed_applications/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_managed_applications/lib/profiles/common/default.rb +++ b/management/azure_mgmt_managed_applications/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_managed_applications/lib/profiles/latest/managedapplications_latest_profile_client.rb b/management/azure_mgmt_managed_applications/lib/profiles/latest/managedapplications_latest_profile_client.rb index cffaf734fa..e1f378d29c 100644 --- a/management/azure_mgmt_managed_applications/lib/profiles/latest/managedapplications_latest_profile_client.rb +++ b/management/azure_mgmt_managed_applications/lib/profiles/latest/managedapplications_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::ManagedApplications::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < ManagedApplicationsClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_managed_applications/lib/profiles/latest/modules/managedapplications_profile_module.rb b/management/azure_mgmt_managed_applications/lib/profiles/latest/modules/managedapplications_profile_module.rb index d5e80a657c..64b096fbeb 100644 --- a/management/azure_mgmt_managed_applications/lib/profiles/latest/modules/managedapplications_profile_module.rb +++ b/management/azure_mgmt_managed_applications/lib/profiles/latest/modules/managedapplications_profile_module.rb @@ -37,7 +37,7 @@ class ManagedApplicationsClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_marketplace_ordering/lib/profiles/common/configurable.rb b/management/azure_mgmt_marketplace_ordering/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_marketplace_ordering/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_marketplace_ordering/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_marketplace_ordering/lib/profiles/common/default.rb b/management/azure_mgmt_marketplace_ordering/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_marketplace_ordering/lib/profiles/common/default.rb +++ b/management/azure_mgmt_marketplace_ordering/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_marketplace_ordering/lib/profiles/latest/marketplaceordering_latest_profile_client.rb b/management/azure_mgmt_marketplace_ordering/lib/profiles/latest/marketplaceordering_latest_profile_client.rb index 66416ba0b9..315f51cd2b 100644 --- a/management/azure_mgmt_marketplace_ordering/lib/profiles/latest/marketplaceordering_latest_profile_client.rb +++ b/management/azure_mgmt_marketplace_ordering/lib/profiles/latest/marketplaceordering_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::MarketplaceOrdering::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < MarketplaceOrderingClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_marketplace_ordering/lib/profiles/latest/modules/marketplaceordering_profile_module.rb b/management/azure_mgmt_marketplace_ordering/lib/profiles/latest/modules/marketplaceordering_profile_module.rb index d4535ff2ed..fe1045a9a6 100644 --- a/management/azure_mgmt_marketplace_ordering/lib/profiles/latest/modules/marketplaceordering_profile_module.rb +++ b/management/azure_mgmt_marketplace_ordering/lib/profiles/latest/modules/marketplaceordering_profile_module.rb @@ -26,7 +26,7 @@ class MarketplaceOrderingClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_media_services/lib/profiles/common/configurable.rb b/management/azure_mgmt_media_services/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_media_services/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_media_services/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_media_services/lib/profiles/common/default.rb b/management/azure_mgmt_media_services/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_media_services/lib/profiles/common/default.rb +++ b/management/azure_mgmt_media_services/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_media_services/lib/profiles/latest/mediaservices_latest_profile_client.rb b/management/azure_mgmt_media_services/lib/profiles/latest/mediaservices_latest_profile_client.rb index f2a5952bf7..ad3e465d93 100644 --- a/management/azure_mgmt_media_services/lib/profiles/latest/mediaservices_latest_profile_client.rb +++ b/management/azure_mgmt_media_services/lib/profiles/latest/mediaservices_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::MediaServices::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < MediaServicesClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_media_services/lib/profiles/latest/modules/mediaservices_profile_module.rb b/management/azure_mgmt_media_services/lib/profiles/latest/modules/mediaservices_profile_module.rb index 61d07d44d1..a74b49be3a 100644 --- a/management/azure_mgmt_media_services/lib/profiles/latest/modules/mediaservices_profile_module.rb +++ b/management/azure_mgmt_media_services/lib/profiles/latest/modules/mediaservices_profile_module.rb @@ -37,7 +37,7 @@ class MediaServicesClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_mobile_engagement/lib/profiles/common/configurable.rb b/management/azure_mgmt_mobile_engagement/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_mobile_engagement/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_mobile_engagement/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_mobile_engagement/lib/profiles/common/default.rb b/management/azure_mgmt_mobile_engagement/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_mobile_engagement/lib/profiles/common/default.rb +++ b/management/azure_mgmt_mobile_engagement/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_mobile_engagement/lib/profiles/latest/mobileengagement_latest_profile_client.rb b/management/azure_mgmt_mobile_engagement/lib/profiles/latest/mobileengagement_latest_profile_client.rb index 19737e628e..03e3b9cc3b 100644 --- a/management/azure_mgmt_mobile_engagement/lib/profiles/latest/mobileengagement_latest_profile_client.rb +++ b/management/azure_mgmt_mobile_engagement/lib/profiles/latest/mobileengagement_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::MobileEngagement::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < MobileEngagementClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_mobile_engagement/lib/profiles/latest/modules/mobileengagement_profile_module.rb b/management/azure_mgmt_mobile_engagement/lib/profiles/latest/modules/mobileengagement_profile_module.rb index 8ba27d33aa..8ad26213f1 100644 --- a/management/azure_mgmt_mobile_engagement/lib/profiles/latest/modules/mobileengagement_profile_module.rb +++ b/management/azure_mgmt_mobile_engagement/lib/profiles/latest/modules/mobileengagement_profile_module.rb @@ -113,7 +113,7 @@ class MobileEngagementClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_monitor/lib/profiles/common/configurable.rb b/management/azure_mgmt_monitor/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_monitor/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_monitor/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_monitor/lib/profiles/common/default.rb b/management/azure_mgmt_monitor/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_monitor/lib/profiles/common/default.rb +++ b/management/azure_mgmt_monitor/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_monitor/lib/profiles/latest/modules/monitor_profile_module.rb b/management/azure_mgmt_monitor/lib/profiles/latest/modules/monitor_profile_module.rb index 07310e5fd4..1cb7c7a061 100644 --- a/management/azure_mgmt_monitor/lib/profiles/latest/modules/monitor_profile_module.rb +++ b/management/azure_mgmt_monitor/lib/profiles/latest/modules/monitor_profile_module.rb @@ -96,7 +96,7 @@ class MonitorClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_monitor/lib/profiles/latest/monitor_latest_profile_client.rb b/management/azure_mgmt_monitor/lib/profiles/latest/monitor_latest_profile_client.rb index 2b16aee2ff..152b046f78 100644 --- a/management/azure_mgmt_monitor/lib/profiles/latest/monitor_latest_profile_client.rb +++ b/management/azure_mgmt_monitor/lib/profiles/latest/monitor_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Monitor::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < MonitorClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_network/lib/profiles/common/configurable.rb b/management/azure_mgmt_network/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_network/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_network/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_network/lib/profiles/common/default.rb b/management/azure_mgmt_network/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_network/lib/profiles/common/default.rb +++ b/management/azure_mgmt_network/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_network/lib/profiles/latest/modules/network_profile_module.rb b/management/azure_mgmt_network/lib/profiles/latest/modules/network_profile_module.rb index 3428142cb8..1ad6c68154 100644 --- a/management/azure_mgmt_network/lib/profiles/latest/modules/network_profile_module.rb +++ b/management/azure_mgmt_network/lib/profiles/latest/modules/network_profile_module.rb @@ -318,7 +318,7 @@ class NetworkClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_network/lib/profiles/latest/network_latest_profile_client.rb b/management/azure_mgmt_network/lib/profiles/latest/network_latest_profile_client.rb index 3835ebc4a2..98b5794c8c 100644 --- a/management/azure_mgmt_network/lib/profiles/latest/network_latest_profile_client.rb +++ b/management/azure_mgmt_network/lib/profiles/latest/network_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Network::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < NetworkClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_network/lib/profiles/v2017_03_09/modules/network_profile_module.rb b/management/azure_mgmt_network/lib/profiles/v2017_03_09/modules/network_profile_module.rb index 80cc3d0078..854056a670 100644 --- a/management/azure_mgmt_network/lib/profiles/v2017_03_09/modules/network_profile_module.rb +++ b/management/azure_mgmt_network/lib/profiles/v2017_03_09/modules/network_profile_module.rb @@ -153,7 +153,7 @@ class NetworkClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_network/lib/profiles/v2017_03_09/network_v2017_03_09_profile_client.rb b/management/azure_mgmt_network/lib/profiles/v2017_03_09/network_v2017_03_09_profile_client.rb index 842aaf0961..c988715303 100644 --- a/management/azure_mgmt_network/lib/profiles/v2017_03_09/network_v2017_03_09_profile_client.rb +++ b/management/azure_mgmt_network/lib/profiles/v2017_03_09/network_v2017_03_09_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Network::Profiles::V2017_03_09::Mgmt # Client class for the V2017_03_09 profile SDK. # class Client < NetworkClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_notification_hubs/lib/profiles/common/configurable.rb b/management/azure_mgmt_notification_hubs/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_notification_hubs/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_notification_hubs/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_notification_hubs/lib/profiles/common/default.rb b/management/azure_mgmt_notification_hubs/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_notification_hubs/lib/profiles/common/default.rb +++ b/management/azure_mgmt_notification_hubs/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_notification_hubs/lib/profiles/latest/modules/notificationhubs_profile_module.rb b/management/azure_mgmt_notification_hubs/lib/profiles/latest/modules/notificationhubs_profile_module.rb index f529a84afa..0080500f37 100644 --- a/management/azure_mgmt_notification_hubs/lib/profiles/latest/modules/notificationhubs_profile_module.rb +++ b/management/azure_mgmt_notification_hubs/lib/profiles/latest/modules/notificationhubs_profile_module.rb @@ -51,7 +51,7 @@ class NotificationHubsClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_notification_hubs/lib/profiles/latest/notificationhubs_latest_profile_client.rb b/management/azure_mgmt_notification_hubs/lib/profiles/latest/notificationhubs_latest_profile_client.rb index d7c05aad19..e8e54dd9bd 100644 --- a/management/azure_mgmt_notification_hubs/lib/profiles/latest/notificationhubs_latest_profile_client.rb +++ b/management/azure_mgmt_notification_hubs/lib/profiles/latest/notificationhubs_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::NotificationHubs::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < NotificationHubsClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_operational_insights/lib/profiles/common/configurable.rb b/management/azure_mgmt_operational_insights/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_operational_insights/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_operational_insights/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_operational_insights/lib/profiles/common/default.rb b/management/azure_mgmt_operational_insights/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_operational_insights/lib/profiles/common/default.rb +++ b/management/azure_mgmt_operational_insights/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_operational_insights/lib/profiles/latest/modules/operationalinsights_profile_module.rb b/management/azure_mgmt_operational_insights/lib/profiles/latest/modules/operationalinsights_profile_module.rb index e193fb2fca..aa925ad201 100644 --- a/management/azure_mgmt_operational_insights/lib/profiles/latest/modules/operationalinsights_profile_module.rb +++ b/management/azure_mgmt_operational_insights/lib/profiles/latest/modules/operationalinsights_profile_module.rb @@ -62,7 +62,7 @@ class OperationalInsightsClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_operational_insights/lib/profiles/latest/operationalinsights_latest_profile_client.rb b/management/azure_mgmt_operational_insights/lib/profiles/latest/operationalinsights_latest_profile_client.rb index bf019e3d31..c66d0ec71a 100644 --- a/management/azure_mgmt_operational_insights/lib/profiles/latest/operationalinsights_latest_profile_client.rb +++ b/management/azure_mgmt_operational_insights/lib/profiles/latest/operationalinsights_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::OperationalInsights::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < OperationalInsightsClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_policy/lib/profiles/common/configurable.rb b/management/azure_mgmt_policy/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_policy/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_policy/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_policy/lib/profiles/common/default.rb b/management/azure_mgmt_policy/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_policy/lib/profiles/common/default.rb +++ b/management/azure_mgmt_policy/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_policy/lib/profiles/latest/modules/policy_profile_module.rb b/management/azure_mgmt_policy/lib/profiles/latest/modules/policy_profile_module.rb index fd845bfbe0..3b20605994 100644 --- a/management/azure_mgmt_policy/lib/profiles/latest/modules/policy_profile_module.rb +++ b/management/azure_mgmt_policy/lib/profiles/latest/modules/policy_profile_module.rb @@ -31,7 +31,7 @@ class PolicyClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_policy/lib/profiles/latest/policy_latest_profile_client.rb b/management/azure_mgmt_policy/lib/profiles/latest/policy_latest_profile_client.rb index 5a7d852070..91f29da47d 100644 --- a/management/azure_mgmt_policy/lib/profiles/latest/policy_latest_profile_client.rb +++ b/management/azure_mgmt_policy/lib/profiles/latest/policy_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Policy::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < PolicyClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_policy/lib/profiles/v2017_03_09/modules/policy_profile_module.rb b/management/azure_mgmt_policy/lib/profiles/v2017_03_09/modules/policy_profile_module.rb index 41d25999b4..5d0c2d3c53 100644 --- a/management/azure_mgmt_policy/lib/profiles/v2017_03_09/modules/policy_profile_module.rb +++ b/management/azure_mgmt_policy/lib/profiles/v2017_03_09/modules/policy_profile_module.rb @@ -24,7 +24,7 @@ class PolicyClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_policy/lib/profiles/v2017_03_09/policy_v2017_03_09_profile_client.rb b/management/azure_mgmt_policy/lib/profiles/v2017_03_09/policy_v2017_03_09_profile_client.rb index c87251682f..4b07059b50 100644 --- a/management/azure_mgmt_policy/lib/profiles/v2017_03_09/policy_v2017_03_09_profile_client.rb +++ b/management/azure_mgmt_policy/lib/profiles/v2017_03_09/policy_v2017_03_09_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Policy::Profiles::V2017_03_09::Mgmt # Client class for the V2017_03_09 profile SDK. # class Client < PolicyClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_powerbi_embedded/lib/profiles/common/configurable.rb b/management/azure_mgmt_powerbi_embedded/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_powerbi_embedded/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_powerbi_embedded/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_powerbi_embedded/lib/profiles/common/default.rb b/management/azure_mgmt_powerbi_embedded/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_powerbi_embedded/lib/profiles/common/default.rb +++ b/management/azure_mgmt_powerbi_embedded/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_powerbi_embedded/lib/profiles/latest/modules/powerbiembedded_profile_module.rb b/management/azure_mgmt_powerbi_embedded/lib/profiles/latest/modules/powerbiembedded_profile_module.rb index 9d213a281e..2c1570fb4d 100644 --- a/management/azure_mgmt_powerbi_embedded/lib/profiles/latest/modules/powerbiembedded_profile_module.rb +++ b/management/azure_mgmt_powerbi_embedded/lib/profiles/latest/modules/powerbiembedded_profile_module.rb @@ -38,7 +38,7 @@ class PowerBiEmbeddedClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_powerbi_embedded/lib/profiles/latest/powerbiembedded_latest_profile_client.rb b/management/azure_mgmt_powerbi_embedded/lib/profiles/latest/powerbiembedded_latest_profile_client.rb index 5f83ac5b84..f0a1da7fe9 100644 --- a/management/azure_mgmt_powerbi_embedded/lib/profiles/latest/powerbiembedded_latest_profile_client.rb +++ b/management/azure_mgmt_powerbi_embedded/lib/profiles/latest/powerbiembedded_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::PowerBiEmbedded::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < PowerBiEmbeddedClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_recovery_services/lib/profiles/common/configurable.rb b/management/azure_mgmt_recovery_services/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_recovery_services/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_recovery_services/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_recovery_services/lib/profiles/common/default.rb b/management/azure_mgmt_recovery_services/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_recovery_services/lib/profiles/common/default.rb +++ b/management/azure_mgmt_recovery_services/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_recovery_services/lib/profiles/latest/modules/recoveryservices_profile_module.rb b/management/azure_mgmt_recovery_services/lib/profiles/latest/modules/recoveryservices_profile_module.rb index 243e9948cd..a6f404f830 100644 --- a/management/azure_mgmt_recovery_services/lib/profiles/latest/modules/recoveryservices_profile_module.rb +++ b/management/azure_mgmt_recovery_services/lib/profiles/latest/modules/recoveryservices_profile_module.rb @@ -64,7 +64,7 @@ class RecoveryServicesClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_recovery_services/lib/profiles/latest/recoveryservices_latest_profile_client.rb b/management/azure_mgmt_recovery_services/lib/profiles/latest/recoveryservices_latest_profile_client.rb index d1d6f57364..0f3301b697 100644 --- a/management/azure_mgmt_recovery_services/lib/profiles/latest/recoveryservices_latest_profile_client.rb +++ b/management/azure_mgmt_recovery_services/lib/profiles/latest/recoveryservices_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::RecoveryServices::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < RecoveryServicesClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_recovery_services_backup/lib/profiles/common/configurable.rb b/management/azure_mgmt_recovery_services_backup/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_recovery_services_backup/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_recovery_services_backup/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_recovery_services_backup/lib/profiles/common/default.rb b/management/azure_mgmt_recovery_services_backup/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_recovery_services_backup/lib/profiles/common/default.rb +++ b/management/azure_mgmt_recovery_services_backup/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_recovery_services_backup/lib/profiles/latest/modules/recoveryservicesbackup_profile_module.rb b/management/azure_mgmt_recovery_services_backup/lib/profiles/latest/modules/recoveryservicesbackup_profile_module.rb index 7ee0ecceb8..baceb10e6a 100644 --- a/management/azure_mgmt_recovery_services_backup/lib/profiles/latest/modules/recoveryservicesbackup_profile_module.rb +++ b/management/azure_mgmt_recovery_services_backup/lib/profiles/latest/modules/recoveryservicesbackup_profile_module.rb @@ -209,7 +209,7 @@ class RecoveryServicesBackupClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_recovery_services_backup/lib/profiles/latest/recoveryservicesbackup_latest_profile_client.rb b/management/azure_mgmt_recovery_services_backup/lib/profiles/latest/recoveryservicesbackup_latest_profile_client.rb index 3039dbfee7..967a70b73f 100644 --- a/management/azure_mgmt_recovery_services_backup/lib/profiles/latest/recoveryservicesbackup_latest_profile_client.rb +++ b/management/azure_mgmt_recovery_services_backup/lib/profiles/latest/recoveryservicesbackup_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::RecoveryServicesBackup::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < RecoveryServicesBackupClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_recovery_services_site_recovery/lib/profiles/common/configurable.rb b/management/azure_mgmt_recovery_services_site_recovery/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_recovery_services_site_recovery/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_recovery_services_site_recovery/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_recovery_services_site_recovery/lib/profiles/common/default.rb b/management/azure_mgmt_recovery_services_site_recovery/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_recovery_services_site_recovery/lib/profiles/common/default.rb +++ b/management/azure_mgmt_recovery_services_site_recovery/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_recovery_services_site_recovery/lib/profiles/latest/modules/recoveryservicessiterecovery_profile_module.rb b/management/azure_mgmt_recovery_services_site_recovery/lib/profiles/latest/modules/recoveryservicessiterecovery_profile_module.rb index d26b4e6f06..c0060b88fb 100644 --- a/management/azure_mgmt_recovery_services_site_recovery/lib/profiles/latest/modules/recoveryservicessiterecovery_profile_module.rb +++ b/management/azure_mgmt_recovery_services_site_recovery/lib/profiles/latest/modules/recoveryservicessiterecovery_profile_module.rb @@ -362,7 +362,7 @@ class RecoveryServicesSiteRecoveryClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_recovery_services_site_recovery/lib/profiles/latest/recoveryservicessiterecovery_latest_profile_client.rb b/management/azure_mgmt_recovery_services_site_recovery/lib/profiles/latest/recoveryservicessiterecovery_latest_profile_client.rb index e69d56a2d2..6613020a93 100644 --- a/management/azure_mgmt_recovery_services_site_recovery/lib/profiles/latest/recoveryservicessiterecovery_latest_profile_client.rb +++ b/management/azure_mgmt_recovery_services_site_recovery/lib/profiles/latest/recoveryservicessiterecovery_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::RecoveryServicesSiteRecovery::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < RecoveryServicesSiteRecoveryClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_redis/lib/profiles/common/configurable.rb b/management/azure_mgmt_redis/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_redis/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_redis/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_redis/lib/profiles/common/default.rb b/management/azure_mgmt_redis/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_redis/lib/profiles/common/default.rb +++ b/management/azure_mgmt_redis/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_redis/lib/profiles/latest/modules/redis_profile_module.rb b/management/azure_mgmt_redis/lib/profiles/latest/modules/redis_profile_module.rb index 253f893022..59de1b4291 100644 --- a/management/azure_mgmt_redis/lib/profiles/latest/modules/redis_profile_module.rb +++ b/management/azure_mgmt_redis/lib/profiles/latest/modules/redis_profile_module.rb @@ -54,7 +54,7 @@ class RedisClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_redis/lib/profiles/latest/redis_latest_profile_client.rb b/management/azure_mgmt_redis/lib/profiles/latest/redis_latest_profile_client.rb index f820fcdc65..d3d8eaecf9 100644 --- a/management/azure_mgmt_redis/lib/profiles/latest/redis_latest_profile_client.rb +++ b/management/azure_mgmt_redis/lib/profiles/latest/redis_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Redis::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < RedisClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_relay/lib/profiles/common/configurable.rb b/management/azure_mgmt_relay/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_relay/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_relay/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_relay/lib/profiles/common/default.rb b/management/azure_mgmt_relay/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_relay/lib/profiles/common/default.rb +++ b/management/azure_mgmt_relay/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_relay/lib/profiles/latest/modules/relay_profile_module.rb b/management/azure_mgmt_relay/lib/profiles/latest/modules/relay_profile_module.rb index 959642454b..8d21ebe670 100644 --- a/management/azure_mgmt_relay/lib/profiles/latest/modules/relay_profile_module.rb +++ b/management/azure_mgmt_relay/lib/profiles/latest/modules/relay_profile_module.rb @@ -48,7 +48,7 @@ class RelayClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_relay/lib/profiles/latest/relay_latest_profile_client.rb b/management/azure_mgmt_relay/lib/profiles/latest/relay_latest_profile_client.rb index d55a8f61dc..751b905219 100644 --- a/management/azure_mgmt_relay/lib/profiles/latest/relay_latest_profile_client.rb +++ b/management/azure_mgmt_relay/lib/profiles/latest/relay_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Relay::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < RelayClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_resources/lib/profiles/common/configurable.rb b/management/azure_mgmt_resources/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_resources/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_resources/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_resources/lib/profiles/common/default.rb b/management/azure_mgmt_resources/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_resources/lib/profiles/common/default.rb +++ b/management/azure_mgmt_resources/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_resources/lib/profiles/latest/modules/resources_profile_module.rb b/management/azure_mgmt_resources/lib/profiles/latest/modules/resources_profile_module.rb index 586e8d6a8e..a6395fe7a1 100644 --- a/management/azure_mgmt_resources/lib/profiles/latest/modules/resources_profile_module.rb +++ b/management/azure_mgmt_resources/lib/profiles/latest/modules/resources_profile_module.rb @@ -70,7 +70,7 @@ class ResourcesClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_resources/lib/profiles/latest/resources_latest_profile_client.rb b/management/azure_mgmt_resources/lib/profiles/latest/resources_latest_profile_client.rb index f951c8fcfb..4a0103f9d3 100644 --- a/management/azure_mgmt_resources/lib/profiles/latest/resources_latest_profile_client.rb +++ b/management/azure_mgmt_resources/lib/profiles/latest/resources_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Resources::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < ResourcesClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_resources/lib/profiles/v2017_03_09/modules/resources_profile_module.rb b/management/azure_mgmt_resources/lib/profiles/v2017_03_09/modules/resources_profile_module.rb index 521cb0340d..2b85721178 100644 --- a/management/azure_mgmt_resources/lib/profiles/v2017_03_09/modules/resources_profile_module.rb +++ b/management/azure_mgmt_resources/lib/profiles/v2017_03_09/modules/resources_profile_module.rb @@ -69,7 +69,7 @@ class ResourcesClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_resources/lib/profiles/v2017_03_09/resources_v2017_03_09_profile_client.rb b/management/azure_mgmt_resources/lib/profiles/v2017_03_09/resources_v2017_03_09_profile_client.rb index fec31aaab0..23a65c9faa 100644 --- a/management/azure_mgmt_resources/lib/profiles/v2017_03_09/resources_v2017_03_09_profile_client.rb +++ b/management/azure_mgmt_resources/lib/profiles/v2017_03_09/resources_v2017_03_09_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Resources::Profiles::V2017_03_09::Mgmt # Client class for the V2017_03_09 profile SDK. # class Client < ResourcesClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_resources_management/lib/profiles/common/configurable.rb b/management/azure_mgmt_resources_management/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_resources_management/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_resources_management/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_resources_management/lib/profiles/common/default.rb b/management/azure_mgmt_resources_management/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_resources_management/lib/profiles/common/default.rb +++ b/management/azure_mgmt_resources_management/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_resources_management/lib/profiles/latest/modules/resourcesmanagement_profile_module.rb b/management/azure_mgmt_resources_management/lib/profiles/latest/modules/resourcesmanagement_profile_module.rb index 6d43397b6a..9ef276599b 100644 --- a/management/azure_mgmt_resources_management/lib/profiles/latest/modules/resourcesmanagement_profile_module.rb +++ b/management/azure_mgmt_resources_management/lib/profiles/latest/modules/resourcesmanagement_profile_module.rb @@ -33,7 +33,7 @@ class ResourcesManagementClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_resources_management/lib/profiles/latest/resourcesmanagement_latest_profile_client.rb b/management/azure_mgmt_resources_management/lib/profiles/latest/resourcesmanagement_latest_profile_client.rb index 3d0a964ea7..b19806a5e0 100644 --- a/management/azure_mgmt_resources_management/lib/profiles/latest/resourcesmanagement_latest_profile_client.rb +++ b/management/azure_mgmt_resources_management/lib/profiles/latest/resourcesmanagement_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::ResourcesManagement::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < ResourcesManagementClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_scheduler/lib/profiles/common/configurable.rb b/management/azure_mgmt_scheduler/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_scheduler/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_scheduler/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_scheduler/lib/profiles/common/default.rb b/management/azure_mgmt_scheduler/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_scheduler/lib/profiles/common/default.rb +++ b/management/azure_mgmt_scheduler/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_scheduler/lib/profiles/latest/modules/scheduler_profile_module.rb b/management/azure_mgmt_scheduler/lib/profiles/latest/modules/scheduler_profile_module.rb index 901d879aa6..827bc71195 100644 --- a/management/azure_mgmt_scheduler/lib/profiles/latest/modules/scheduler_profile_module.rb +++ b/management/azure_mgmt_scheduler/lib/profiles/latest/modules/scheduler_profile_module.rb @@ -64,7 +64,7 @@ class SchedulerClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_scheduler/lib/profiles/latest/scheduler_latest_profile_client.rb b/management/azure_mgmt_scheduler/lib/profiles/latest/scheduler_latest_profile_client.rb index 63d0252ea7..ac755048f2 100644 --- a/management/azure_mgmt_scheduler/lib/profiles/latest/scheduler_latest_profile_client.rb +++ b/management/azure_mgmt_scheduler/lib/profiles/latest/scheduler_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Scheduler::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < SchedulerClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_search/lib/profiles/common/configurable.rb b/management/azure_mgmt_search/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_search/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_search/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_search/lib/profiles/common/default.rb b/management/azure_mgmt_search/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_search/lib/profiles/common/default.rb +++ b/management/azure_mgmt_search/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_search/lib/profiles/latest/modules/search_profile_module.rb b/management/azure_mgmt_search/lib/profiles/latest/modules/search_profile_module.rb index baca733ad4..ba1095f374 100644 --- a/management/azure_mgmt_search/lib/profiles/latest/modules/search_profile_module.rb +++ b/management/azure_mgmt_search/lib/profiles/latest/modules/search_profile_module.rb @@ -34,7 +34,7 @@ class SearchClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_search/lib/profiles/latest/search_latest_profile_client.rb b/management/azure_mgmt_search/lib/profiles/latest/search_latest_profile_client.rb index b7552bbe63..66d91ee06c 100644 --- a/management/azure_mgmt_search/lib/profiles/latest/search_latest_profile_client.rb +++ b/management/azure_mgmt_search/lib/profiles/latest/search_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Search::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < SearchClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_server_management/lib/profiles/common/configurable.rb b/management/azure_mgmt_server_management/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_server_management/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_server_management/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_server_management/lib/profiles/common/default.rb b/management/azure_mgmt_server_management/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_server_management/lib/profiles/common/default.rb +++ b/management/azure_mgmt_server_management/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_server_management/lib/profiles/latest/modules/servermanagement_profile_module.rb b/management/azure_mgmt_server_management/lib/profiles/latest/modules/servermanagement_profile_module.rb index 162292f14d..6baa117273 100644 --- a/management/azure_mgmt_server_management/lib/profiles/latest/modules/servermanagement_profile_module.rb +++ b/management/azure_mgmt_server_management/lib/profiles/latest/modules/servermanagement_profile_module.rb @@ -51,7 +51,7 @@ class ServerManagementClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_server_management/lib/profiles/latest/servermanagement_latest_profile_client.rb b/management/azure_mgmt_server_management/lib/profiles/latest/servermanagement_latest_profile_client.rb index 7331101cfe..c73a7143d8 100644 --- a/management/azure_mgmt_server_management/lib/profiles/latest/servermanagement_latest_profile_client.rb +++ b/management/azure_mgmt_server_management/lib/profiles/latest/servermanagement_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::ServerManagement::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < ServerManagementClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_service_bus/lib/profiles/common/configurable.rb b/management/azure_mgmt_service_bus/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_service_bus/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_service_bus/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_service_bus/lib/profiles/common/default.rb b/management/azure_mgmt_service_bus/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_service_bus/lib/profiles/common/default.rb +++ b/management/azure_mgmt_service_bus/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_service_bus/lib/profiles/latest/modules/servicebus_profile_module.rb b/management/azure_mgmt_service_bus/lib/profiles/latest/modules/servicebus_profile_module.rb index 84cac87b1f..84d93ad05d 100644 --- a/management/azure_mgmt_service_bus/lib/profiles/latest/modules/servicebus_profile_module.rb +++ b/management/azure_mgmt_service_bus/lib/profiles/latest/modules/servicebus_profile_module.rb @@ -77,7 +77,7 @@ class ServiceBusClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_service_bus/lib/profiles/latest/servicebus_latest_profile_client.rb b/management/azure_mgmt_service_bus/lib/profiles/latest/servicebus_latest_profile_client.rb index cd19825188..5ca5f6e58f 100644 --- a/management/azure_mgmt_service_bus/lib/profiles/latest/servicebus_latest_profile_client.rb +++ b/management/azure_mgmt_service_bus/lib/profiles/latest/servicebus_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::ServiceBus::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < ServiceBusClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_service_fabric/lib/profiles/common/configurable.rb b/management/azure_mgmt_service_fabric/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_service_fabric/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_service_fabric/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_service_fabric/lib/profiles/common/default.rb b/management/azure_mgmt_service_fabric/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_service_fabric/lib/profiles/common/default.rb +++ b/management/azure_mgmt_service_fabric/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_service_fabric/lib/profiles/latest/modules/servicefabric_profile_module.rb b/management/azure_mgmt_service_fabric/lib/profiles/latest/modules/servicefabric_profile_module.rb index e8f8388e3f..c261e8b447 100644 --- a/management/azure_mgmt_service_fabric/lib/profiles/latest/modules/servicefabric_profile_module.rb +++ b/management/azure_mgmt_service_fabric/lib/profiles/latest/modules/servicefabric_profile_module.rb @@ -45,7 +45,7 @@ class ServiceFabricClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_service_fabric/lib/profiles/latest/servicefabric_latest_profile_client.rb b/management/azure_mgmt_service_fabric/lib/profiles/latest/servicefabric_latest_profile_client.rb index 6722f25e96..07a62b69f5 100644 --- a/management/azure_mgmt_service_fabric/lib/profiles/latest/servicefabric_latest_profile_client.rb +++ b/management/azure_mgmt_service_fabric/lib/profiles/latest/servicefabric_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::ServiceFabric::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < ServiceFabricClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_sql/lib/profiles/common/configurable.rb b/management/azure_mgmt_sql/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_sql/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_sql/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_sql/lib/profiles/common/default.rb b/management/azure_mgmt_sql/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_sql/lib/profiles/common/default.rb +++ b/management/azure_mgmt_sql/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_sql/lib/profiles/latest/modules/sql_profile_module.rb b/management/azure_mgmt_sql/lib/profiles/latest/modules/sql_profile_module.rb index 6857d94484..bb664d887a 100644 --- a/management/azure_mgmt_sql/lib/profiles/latest/modules/sql_profile_module.rb +++ b/management/azure_mgmt_sql/lib/profiles/latest/modules/sql_profile_module.rb @@ -264,7 +264,7 @@ class SQLClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_sql/lib/profiles/latest/sql_latest_profile_client.rb b/management/azure_mgmt_sql/lib/profiles/latest/sql_latest_profile_client.rb index 1c6bd6e087..5cec06e8a4 100644 --- a/management/azure_mgmt_sql/lib/profiles/latest/sql_latest_profile_client.rb +++ b/management/azure_mgmt_sql/lib/profiles/latest/sql_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::SQL::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < SQLClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_stor_simple8000_series/lib/profiles/common/configurable.rb b/management/azure_mgmt_stor_simple8000_series/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_stor_simple8000_series/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_stor_simple8000_series/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_stor_simple8000_series/lib/profiles/common/default.rb b/management/azure_mgmt_stor_simple8000_series/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_stor_simple8000_series/lib/profiles/common/default.rb +++ b/management/azure_mgmt_stor_simple8000_series/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_stor_simple8000_series/lib/profiles/latest/modules/storsimple8000series_profile_module.rb b/management/azure_mgmt_stor_simple8000_series/lib/profiles/latest/modules/storsimple8000series_profile_module.rb index b5d43a3f70..cbf2bcd02b 100644 --- a/management/azure_mgmt_stor_simple8000_series/lib/profiles/latest/modules/storsimple8000series_profile_module.rb +++ b/management/azure_mgmt_stor_simple8000_series/lib/profiles/latest/modules/storsimple8000series_profile_module.rb @@ -192,7 +192,7 @@ class StorSimple8000SeriesClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_stor_simple8000_series/lib/profiles/latest/storsimple8000series_latest_profile_client.rb b/management/azure_mgmt_stor_simple8000_series/lib/profiles/latest/storsimple8000series_latest_profile_client.rb index 547c30d3e1..09a9dbc3cc 100644 --- a/management/azure_mgmt_stor_simple8000_series/lib/profiles/latest/storsimple8000series_latest_profile_client.rb +++ b/management/azure_mgmt_stor_simple8000_series/lib/profiles/latest/storsimple8000series_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::StorSimple8000Series::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < StorSimple8000SeriesClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_storage/lib/profiles/common/configurable.rb b/management/azure_mgmt_storage/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_storage/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_storage/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_storage/lib/profiles/common/default.rb b/management/azure_mgmt_storage/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_storage/lib/profiles/common/default.rb +++ b/management/azure_mgmt_storage/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_storage/lib/profiles/latest/modules/storage_profile_module.rb b/management/azure_mgmt_storage/lib/profiles/latest/modules/storage_profile_module.rb index e8cb1a05d4..ca37a0e40c 100644 --- a/management/azure_mgmt_storage/lib/profiles/latest/modules/storage_profile_module.rb +++ b/management/azure_mgmt_storage/lib/profiles/latest/modules/storage_profile_module.rb @@ -78,7 +78,7 @@ class StorageClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_storage/lib/profiles/latest/storage_latest_profile_client.rb b/management/azure_mgmt_storage/lib/profiles/latest/storage_latest_profile_client.rb index 642d9799cb..76b677fe27 100644 --- a/management/azure_mgmt_storage/lib/profiles/latest/storage_latest_profile_client.rb +++ b/management/azure_mgmt_storage/lib/profiles/latest/storage_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Storage::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < StorageClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_storage/lib/profiles/v2017_03_09/modules/storage_profile_module.rb b/management/azure_mgmt_storage/lib/profiles/v2017_03_09/modules/storage_profile_module.rb index e274140394..8adad55eb3 100644 --- a/management/azure_mgmt_storage/lib/profiles/v2017_03_09/modules/storage_profile_module.rb +++ b/management/azure_mgmt_storage/lib/profiles/v2017_03_09/modules/storage_profile_module.rb @@ -38,7 +38,7 @@ class StorageClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_storage/lib/profiles/v2017_03_09/storage_v2017_03_09_profile_client.rb b/management/azure_mgmt_storage/lib/profiles/v2017_03_09/storage_v2017_03_09_profile_client.rb index 662ec20c64..98babe6bed 100644 --- a/management/azure_mgmt_storage/lib/profiles/v2017_03_09/storage_v2017_03_09_profile_client.rb +++ b/management/azure_mgmt_storage/lib/profiles/v2017_03_09/storage_v2017_03_09_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Storage::Profiles::V2017_03_09::Mgmt # Client class for the V2017_03_09 profile SDK. # class Client < StorageClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_stream_analytics/lib/profiles/common/configurable.rb b/management/azure_mgmt_stream_analytics/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_stream_analytics/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_stream_analytics/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_stream_analytics/lib/profiles/common/default.rb b/management/azure_mgmt_stream_analytics/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_stream_analytics/lib/profiles/common/default.rb +++ b/management/azure_mgmt_stream_analytics/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_stream_analytics/lib/profiles/latest/modules/streamanalytics_profile_module.rb b/management/azure_mgmt_stream_analytics/lib/profiles/latest/modules/streamanalytics_profile_module.rb index 7dab6660ee..66802b08c5 100644 --- a/management/azure_mgmt_stream_analytics/lib/profiles/latest/modules/streamanalytics_profile_module.rb +++ b/management/azure_mgmt_stream_analytics/lib/profiles/latest/modules/streamanalytics_profile_module.rb @@ -96,7 +96,7 @@ class StreamAnalyticsClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_stream_analytics/lib/profiles/latest/streamanalytics_latest_profile_client.rb b/management/azure_mgmt_stream_analytics/lib/profiles/latest/streamanalytics_latest_profile_client.rb index 74aa83b1b5..f1a8014328 100644 --- a/management/azure_mgmt_stream_analytics/lib/profiles/latest/streamanalytics_latest_profile_client.rb +++ b/management/azure_mgmt_stream_analytics/lib/profiles/latest/streamanalytics_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::StreamAnalytics::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < StreamAnalyticsClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_subscriptions/lib/profiles/common/configurable.rb b/management/azure_mgmt_subscriptions/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_subscriptions/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_subscriptions/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_subscriptions/lib/profiles/common/default.rb b/management/azure_mgmt_subscriptions/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_subscriptions/lib/profiles/common/default.rb +++ b/management/azure_mgmt_subscriptions/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_subscriptions/lib/profiles/latest/modules/subscriptions_profile_module.rb b/management/azure_mgmt_subscriptions/lib/profiles/latest/modules/subscriptions_profile_module.rb index 7caaf86d18..7cf622383f 100644 --- a/management/azure_mgmt_subscriptions/lib/profiles/latest/modules/subscriptions_profile_module.rb +++ b/management/azure_mgmt_subscriptions/lib/profiles/latest/modules/subscriptions_profile_module.rb @@ -28,7 +28,7 @@ class SubscriptionsClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_subscriptions/lib/profiles/latest/subscriptions_latest_profile_client.rb b/management/azure_mgmt_subscriptions/lib/profiles/latest/subscriptions_latest_profile_client.rb index b77e48a2ba..af585e2608 100644 --- a/management/azure_mgmt_subscriptions/lib/profiles/latest/subscriptions_latest_profile_client.rb +++ b/management/azure_mgmt_subscriptions/lib/profiles/latest/subscriptions_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Subscriptions::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < SubscriptionsClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_subscriptions/lib/profiles/v2017_03_09/modules/subscriptions_profile_module.rb b/management/azure_mgmt_subscriptions/lib/profiles/v2017_03_09/modules/subscriptions_profile_module.rb index 10ee87a97e..50a2343350 100644 --- a/management/azure_mgmt_subscriptions/lib/profiles/v2017_03_09/modules/subscriptions_profile_module.rb +++ b/management/azure_mgmt_subscriptions/lib/profiles/v2017_03_09/modules/subscriptions_profile_module.rb @@ -28,7 +28,7 @@ class SubscriptionsClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_subscriptions/lib/profiles/v2017_03_09/subscriptions_v2017_03_09_profile_client.rb b/management/azure_mgmt_subscriptions/lib/profiles/v2017_03_09/subscriptions_v2017_03_09_profile_client.rb index ad908527ab..a02e7a4f91 100644 --- a/management/azure_mgmt_subscriptions/lib/profiles/v2017_03_09/subscriptions_v2017_03_09_profile_client.rb +++ b/management/azure_mgmt_subscriptions/lib/profiles/v2017_03_09/subscriptions_v2017_03_09_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Subscriptions::Profiles::V2017_03_09::Mgmt # Client class for the V2017_03_09 profile SDK. # class Client < SubscriptionsClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_traffic_manager/lib/profiles/common/configurable.rb b/management/azure_mgmt_traffic_manager/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_traffic_manager/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_traffic_manager/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_traffic_manager/lib/profiles/common/default.rb b/management/azure_mgmt_traffic_manager/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_traffic_manager/lib/profiles/common/default.rb +++ b/management/azure_mgmt_traffic_manager/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_traffic_manager/lib/profiles/latest/modules/trafficmanager_profile_module.rb b/management/azure_mgmt_traffic_manager/lib/profiles/latest/modules/trafficmanager_profile_module.rb index 3fb4ba15be..8f746791a3 100644 --- a/management/azure_mgmt_traffic_manager/lib/profiles/latest/modules/trafficmanager_profile_module.rb +++ b/management/azure_mgmt_traffic_manager/lib/profiles/latest/modules/trafficmanager_profile_module.rb @@ -46,7 +46,7 @@ class TrafficManagerClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_traffic_manager/lib/profiles/latest/trafficmanager_latest_profile_client.rb b/management/azure_mgmt_traffic_manager/lib/profiles/latest/trafficmanager_latest_profile_client.rb index bae6081d07..dad010c71b 100644 --- a/management/azure_mgmt_traffic_manager/lib/profiles/latest/trafficmanager_latest_profile_client.rb +++ b/management/azure_mgmt_traffic_manager/lib/profiles/latest/trafficmanager_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::TrafficManager::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < TrafficManagerClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end diff --git a/management/azure_mgmt_web/lib/profiles/common/configurable.rb b/management/azure_mgmt_web/lib/profiles/common/configurable.rb index 231c6dccfb..0e4922239a 100644 --- a/management/azure_mgmt_web/lib/profiles/common/configurable.rb +++ b/management/azure_mgmt_web/lib/profiles/common/configurable.rb @@ -2,8 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # The Azure::ARM::Configurable module provides basic configuration for Azure ARM activities. +module Azure::Common + # The Azure::Common::Configurable module provides basic configuration for Azure activities. module Configurable # @return [String] Azure tenant id (also known as domain). attr_accessor :tenant_id @@ -25,11 +25,11 @@ module Configurable class << self # - # List of configurable keys for {Azure::ARM::Client}. + # List of configurable keys for {Azure::Common::Client}. # @return [Array] of option keys. # def keys - @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings, :credentials] + @keys ||= [:tenant_id, :client_id, :client_secret, :subscription_id, :active_directory_settings] end end @@ -45,11 +45,23 @@ def configure # This will also creates MsRest::TokenCredentials to be used for subsequent Azure Resource Manager clients. # def reset!(options = {}) - Azure::ARM::Configurable.keys.each do |key| - default_value = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.each do |key| + default_value = Azure::Common::Default.options[key] instance_variable_set(:"@#{key}", options.fetch(key, default_value)) end + fail ArgumentError, 'tenant_id is nil' if self.tenant_id.nil? + fail ArgumentError, 'client_id is nil' if self.client_id.nil? + fail ArgumentError, 'client_secret is nil' if self.client_secret.nil? + fail ArgumentError, 'subscription_id is nil' if self.subscription_id.nil? + fail ArgumentError, 'active_directory_settings is nil' if self.active_directory_settings.nil? + + default_value = MsRest::TokenCredentials.new( + MsRestAzure::ApplicationTokenProvider.new( + self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) + + instance_variable_set(:"@credentials", options.fetch(:credentials, default_value)) + self end @@ -62,11 +74,12 @@ def config # # configures configurable options to default values # - def setup_options + def setup_default_options opts = {} - Azure::ARM::Configurable.keys.map do |key| - opts[key] = Azure::ARM::Default.options[key] + Azure::Common::Configurable.keys.map do |key| + opts[key] = Azure::Common::Default.options[key] end + opts end end diff --git a/management/azure_mgmt_web/lib/profiles/common/default.rb b/management/azure_mgmt_web/lib/profiles/common/default.rb index b8f5638006..aa6d7c577b 100644 --- a/management/azure_mgmt_web/lib/profiles/common/default.rb +++ b/management/azure_mgmt_web/lib/profiles/common/default.rb @@ -2,8 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. -module Azure::ARM - # Default configuration options for {Azure::ARM.Client} +module Azure::Common module Default class << self # @@ -38,16 +37,6 @@ def subscription_id ENV['AZURE_SUBSCRIPTION_ID'] end - # - # Default Azure credentials to authorize HTTP requests made by the service client. - # @return [MsRest::ServiceClientCredentials] Azure credentials to authorize HTTP requests made by the service client. - # - def credentials - MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - # # Default Azure Active Directory Service Settings. # @return [MsRestAzure::ActiveDirectoryServiceSettings] Azure Active Directory Service Settings. @@ -61,7 +50,7 @@ def active_directory_settings # @return [Hash] Configuration options. # def options - Hash[Azure::ARM::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Azure::Common::Configurable.keys.map { |key| [key, send(key)]}] end end end diff --git a/management/azure_mgmt_web/lib/profiles/latest/modules/web_profile_module.rb b/management/azure_mgmt_web/lib/profiles/latest/modules/web_profile_module.rb index ec62091185..de2c9520d2 100644 --- a/management/azure_mgmt_web/lib/profiles/latest/modules/web_profile_module.rb +++ b/management/azure_mgmt_web/lib/profiles/latest/modules/web_profile_module.rb @@ -299,7 +299,7 @@ class WebClass def initialize(options = {}) if options.is_a?(Hash) && options.length == 0 - @options = setup_options + @options = setup_default_options else @options = options end diff --git a/management/azure_mgmt_web/lib/profiles/latest/web_latest_profile_client.rb b/management/azure_mgmt_web/lib/profiles/latest/web_latest_profile_client.rb index 168db91317..a5fc57cdbf 100644 --- a/management/azure_mgmt_web/lib/profiles/latest/web_latest_profile_client.rb +++ b/management/azure_mgmt_web/lib/profiles/latest/web_latest_profile_client.rb @@ -12,22 +12,12 @@ module Azure::Web::Profiles::Latest::Mgmt # Client class for the Latest profile SDK. # class Client < WebClass - include Azure::ARM::Configurable + include Azure::Common::Configurable def initialize(options = {}) super(options) end - def credentials - if @credentials.nil? - self.active_directory_settings ||= Azure::ARM::Default.active_directory_settings - - @credentials = MsRest::TokenCredentials.new( - MsRestAzure::ApplicationTokenProvider.new( - self.tenant_id, self.client_id, self.client_secret, self.active_directory_settings)) - end - @credentials - end end end