Class: Chef::Provisioning::AzureRM::Credentials
- Inherits:
-
Object
- Object
- Chef::Provisioning::AzureRM::Credentials
- Defined in:
- lib/chef/provisioning/azurerm/credentials.rb
Constant Summary collapse
- CONFIG_PATH =
"#{ENV['HOME']}/.azure/credentials".freeze
Class Method Summary collapse
Instance Method Summary collapse
- #azure_credentials_for_subscription(subscription_id, azure_environment) ⇒ Object
-
#initialize ⇒ Credentials
constructor
A new instance of Credentials.
-
#settings_for_azure_environment(azure_environment) ⇒ MsRestAzure::ActiveDirectoryServiceSettings
Retrieves a [MsRestAzure::ActiveDirectoryServiceSettings] object representing the settings for the given cloud.
Constructor Details
#initialize ⇒ Credentials
Returns a new instance of Credentials.
9 10 11 12 13 14 15 16 |
# File 'lib/chef/provisioning/azurerm/credentials.rb', line 9 def initialize config_file = ENV['AZURE_CONFIG_FILE'] || File.(CONFIG_PATH) if File.file?(config_file) @credentials = IniFile.load(File.(config_file)) else Chef::Log.warn "#{CONFIG_PATH} was not found or not accessible." unless File.file?(config_file) end end |
Class Method Details
.singleton ⇒ Object
47 48 49 |
# File 'lib/chef/provisioning/azurerm/credentials.rb', line 47 def self.singleton @credentials ||= Credentials.new end |
Instance Method Details
#azure_credentials_for_subscription(subscription_id, azure_environment) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/chef/provisioning/azurerm/credentials.rb', line 18 def azure_credentials_for_subscription(subscription_id, azure_environment) tenant_id = ENV['AZURE_TENANT_ID'] || @credentials[subscription_id]['tenant_id'] client_id = ENV['AZURE_CLIENT_ID'] || @credentials[subscription_id]['client_id'] client_secret = ENV['AZURE_CLIENT_SECRET'] || @credentials[subscription_id]['client_secret'] token_provider = MsRestAzure::ApplicationTokenProvider.new(tenant_id, client_id, client_secret, settings_for_azure_environment(azure_environment)) MsRest::TokenCredentials.new(token_provider) end |
#settings_for_azure_environment(azure_environment) ⇒ MsRestAzure::ActiveDirectoryServiceSettings
Retrieves a [MsRestAzure::ActiveDirectoryServiceSettings] object representing the settings for the given cloud.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/chef/provisioning/azurerm/credentials.rb', line 32 def settings_for_azure_environment(azure_environment) case azure_environment.downcase when 'azureusgovernment' ::MsRestAzure::ActiveDirectoryServiceSettings.get_azure_us_government_settings when 'azurechina' ::MsRestAzure::ActiveDirectoryServiceSettings.get_azure_china_settings when 'azuregermancloud' ::MsRestAzure::ActiveDirectoryServiceSettings.get_azure_germany_settings when 'azurerm' ::MsRestAzure::ActiveDirectoryServiceSettings.get_azure_settings when 'azure' ::MsRestAzure::ActiveDirectoryServiceSettings.get_azure_settings end end |