Specific credentials can now be used

If not specified the first one in the credentials file is used
Fixes #14

Signed-off-by: Russell Seymour <russell.seymour@turtlesystems.co.uk>
This commit is contained in:
Russell Seymour 2017-02-23 14:13:32 +00:00
parent b011b71a27
commit 7699ffb6e2

View file

@ -40,13 +40,17 @@ class AzureConnection
# If a connection already exists then return it # If a connection already exists then return it
return @conn if defined?(@conn) return @conn if defined?(@conn)
# Determine if more than one subscription is specified in the configuration file, if so use the first one # If a subscription to be used has been specified as en environment variable use that
if @credentials.sections.length >= 1 # otherwise use the first one in the credentials file
@subscription_id = @credentials.sections[0] if !ENV['AZURE_SUBSCRIPTION_ID'].nil?
else
@subscription_id = ENV['AZURE_SUBSCRIPTION_ID'] @subscription_id = ENV['AZURE_SUBSCRIPTION_ID']
else
@subscription_id = @credentials.sections[0]
end end
# Check that the credential exists
raise format('The specified Azure Subscription cannot be found in your credentials: %s', @subscription_id) unless @credentials.sections.include?(@subscription_id)
# Determine the client_id, tenant_id and the client_secret # Determine the client_id, tenant_id and the client_secret
tenant_id = ENV['AZURE_TENANT_ID'] || @credentials[@subscription_id]['tenant_id'] tenant_id = ENV['AZURE_TENANT_ID'] || @credentials[@subscription_id]['tenant_id']
client_id = ENV['AZURE_CLIENT_ID'] || @credentials[@subscription_id]['client_id'] client_id = ENV['AZURE_CLIENT_ID'] || @credentials[@subscription_id]['client_id']