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
return @conn if defined?(@conn)
# Determine if more than one subscription is specified in the configuration file, if so use the first one
if @credentials.sections.length >= 1
@subscription_id = @credentials.sections[0]
else
# If a subscription to be used has been specified as en environment variable use that
# otherwise use the first one in the credentials file
if !ENV['AZURE_SUBSCRIPTION_ID'].nil?
@subscription_id = ENV['AZURE_SUBSCRIPTION_ID']
else
@subscription_id = @credentials.sections[0]
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
tenant_id = ENV['AZURE_TENANT_ID'] || @credentials[@subscription_id]['tenant_id']
client_id = ENV['AZURE_CLIENT_ID'] || @credentials[@subscription_id]['client_id']