Skip to content

Commit

Permalink
Merge pull request #28 from djberg96/usgov
Browse files Browse the repository at this point in the history
Add usgov support, fix rescue scoping
(cherry picked from commit 5879733bc0ef74b2ffd3658d81b1cd7af7e2eb82)

https://bugzilla.redhat.com/show_bug.cgi?id=1404827
  • Loading branch information
simaishi committed Feb 9, 2017
1 parent 0160a60 commit 4f30af5
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions app/models/manageiq/providers/azure/manager_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ def connect(options = {})

client_id = options[:user] || authentication_userid(options[:auth_type])
client_key = options[:pass] || authentication_password(options[:auth_type])
self.class.raw_connect(client_id, client_key, azure_tenant_id, subscription, options[:proxy_uri] || http_proxy_uri)
self.class.raw_connect(client_id, client_key, azure_tenant_id, subscription, options[:proxy_uri] || http_proxy_uri, provider_region)
end

def verify_credentials(_auth_type = nil, options = {})
require 'azure-armrest'
conf = connect(options)
rescue ArgumentError => err
raise MiqException::MiqInvalidCredentialsError, _("Incorrect credentials - #{err.message}")
rescue Azure::Armrest::UnauthorizedException, Azure::Armrest::BadRequestException
rescue ::Azure::Armrest::UnauthorizedException, ::Azure::Armrest::BadRequestException
raise MiqException::MiqInvalidCredentialsError, _("Incorrect credentials - check your Azure Client ID and Client Key")
rescue MiqException::MiqInvalidCredentialsError
raise # Raise before falling into catch-all block below
Expand All @@ -26,7 +26,7 @@ def verify_credentials(_auth_type = nil, options = {})
end

module ClassMethods
def raw_connect(client_id, client_key, azure_tenant_id, subscription, proxy_uri = nil)
def raw_connect(client_id, client_key, azure_tenant_id, subscription, proxy_uri = nil, provider_region = nil)

require 'azure-armrest'

Expand All @@ -39,10 +39,20 @@ def raw_connect(client_id, client_key, azure_tenant_id, subscription, proxy_uri
:client_key => client_key,
:tenant_id => azure_tenant_id,
:subscription_id => subscription,
:proxy => proxy_uri
:proxy => proxy_uri,
:environment => environment_for(provider_region)
)
end

def environment_for(region)
case region
when /usgov/i
::Azure::Armrest::Environment::USGovernment
else
::Azure::Armrest::Environment::Public
end
end

# Discovery

# Create EmsAzure instances for all regions with instances
Expand Down

0 comments on commit 4f30af5

Please sign in to comment.