Class: Kitchen::Driver::Credentials
- Inherits:
-
Object
- Object
- Kitchen::Driver::Credentials
- Defined in:
- lib/kitchen/driver/credentials.rb
Overview
Credentials
Constant Summary collapse
- CONFIG_PATH =
"#{ENV['HOME']}/.azure/credentials".freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#ad_settings_for_azure_environment(azure_environment) ⇒ MsRestAzure::ActiveDirectoryServiceSettings
Retrieves a [MsRestAzure::ActiveDirectoryServiceSettings] object representing the AD settings for the given cloud.
-
#azure_options_for_subscription(subscription_id, azure_environment = "Azure") ⇒ Object
Retrieves an object containing options and credentials for the given subscription_id and azure_environment.
-
#endpoint_settings_for_azure_environment(azure_environment) ⇒ MsRestAzure::AzureEnvironment
Retrieves a [MsRestAzure::AzureEnvironment] object representing endpoint settings for the given cloud.
-
#initialize ⇒ Credentials
constructor
Creates and initializes a new instance of the Credentials class.
Constructor Details
#initialize ⇒ Credentials
Creates and initializes a new instance of the Credentials class.
14 15 16 17 18 19 20 21 |
# File 'lib/kitchen/driver/credentials.rb', line 14 def initialize config_file = ENV["AZURE_CONFIG_FILE"] || File.(CONFIG_PATH) if File.file?(config_file) @credentials = IniFile.load(File.(config_file)) else warn "#{CONFIG_PATH} was not found or not accessible." end end |
Class Method Details
.singleton ⇒ Object
85 86 87 |
# File 'lib/kitchen/driver/credentials.rb', line 85 def self.singleton @credentials ||= Credentials.new end |
Instance Method Details
#ad_settings_for_azure_environment(azure_environment) ⇒ MsRestAzure::ActiveDirectoryServiceSettings
Retrieves a [MsRestAzure::ActiveDirectoryServiceSettings] object representing the AD settings for the given cloud.
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/kitchen/driver/credentials.rb', line 53 def ad_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_german_settings when "azure" ::MsRestAzure::ActiveDirectoryServiceSettings.get_azure_settings end end |
#azure_options_for_subscription(subscription_id, azure_environment = "Azure") ⇒ Object
Retrieves an object containing options and credentials for the given subscription_id and azure_environment.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/kitchen/driver/credentials.rb', line 32 def (subscription_id, azure_environment = "Azure") 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, ad_settings_for_azure_environment(azure_environment)) = { tenant_id: tenant_id, client_id: client_id, client_secret: client_secret, subscription_id: subscription_id, credentials: ::MsRest::TokenCredentials.new(token_provider), active_directory_settings: ad_settings_for_azure_environment(azure_environment), base_url: endpoint_settings_for_azure_environment(azure_environment).resource_manager_endpoint_url } end |
#endpoint_settings_for_azure_environment(azure_environment) ⇒ MsRestAzure::AzureEnvironment
Retrieves a [MsRestAzure::AzureEnvironment] object representing endpoint settings for the given cloud.
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/kitchen/driver/credentials.rb', line 72 def endpoint_settings_for_azure_environment(azure_environment) case azure_environment.downcase when "azureusgovernment" ::MsRestAzure::AzureEnvironments::AzureUSGovernment when "azurechina" ::MsRestAzure::AzureEnvironments::AzureChinaCloud when "azuregermancloud" ::MsRestAzure::AzureEnvironments::AzureGermanCloud when "azure" ::MsRestAzure::AzureEnvironments::AzureCloud end end |