Skip to content

Commit

Permalink
update azure_rm_common, upgrade to track2 (#670)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fred-sun authored Nov 1, 2021
1 parent b8dce08 commit fbfe197
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
23 changes: 17 additions & 6 deletions plugins/module_utils/azure_rm_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ def default_api_version(self):
import azure.mgmt.datalake.store.models as DataLakeStoreAccountModel
from azure.mgmt.notificationhubs import NotificationHubsManagementClient
from azure.mgmt.eventhub import EventHubManagementClient
from azure.identity._credentials import client_secret

except ImportError as exc:
Authentication = object
Expand Down Expand Up @@ -724,7 +725,7 @@ def create_default_pip(self, resource_group, location, public_ip_name, allocatio
self.log("Check to see if public IP {0} exists".format(public_ip_name))
try:
pip = self.network_client.public_ip_addresses.get(resource_group, public_ip_name)
except CloudError:
except Exception:
pass

if pip:
Expand Down Expand Up @@ -764,7 +765,7 @@ def create_default_securitygroup(self, resource_group, location, security_group_
self.log("Check to see if security group {0} exists".format(security_group_name))
try:
group = self.network_client.network_security_groups.get(resource_group, security_group_name)
except CloudError:
except Exception:
pass

if group:
Expand Down Expand Up @@ -875,7 +876,7 @@ def get_graphrbac_client(self, tenant_id):

return client

def get_mgmt_svc_client(self, client_type, base_url=None, api_version=None, suppress_subscription_id=False):
def get_mgmt_svc_client(self, client_type, base_url=None, api_version=None, suppress_subscription_id=False, is_track2=False):
self.log('Getting management service client {0}'.format(client_type.__name__))
self.check_client_version(client_type)

Expand All @@ -887,9 +888,15 @@ def get_mgmt_svc_client(self, client_type, base_url=None, api_version=None, supp

# Some management clients do not take a subscription ID as parameters.
if suppress_subscription_id:
client_kwargs = dict(credentials=self.azure_auth.azure_credentials, base_url=base_url)
if is_track2:
client_kwargs = dict(credential=self.azure_auth.azure_credential_track2, base_url=base_url)
else:
client_kwargs = dict(credentials=self.azure_auth.azure_credentials, base_url=base_url)
else:
client_kwargs = dict(credentials=self.azure_auth.azure_credentials, subscription_id=self.azure_auth.subscription_id, base_url=base_url)
if is_track2:
client_kwargs = dict(credential=self.azure_auth.azure_credential_track2, subscription_id=self.azure_auth.subscription_id, base_url=base_url)
else:
client_kwargs = dict(credentials=self.azure_auth.azure_credentials, subscription_id=self.azure_auth.subscription_id, base_url=base_url)

api_profile_dict = {}

Expand Down Expand Up @@ -923,7 +930,8 @@ def _ansible_get_models(self, *arg, **kwarg):
setattr(client, '_ansible_models', importlib.import_module(client_type.__module__).models)
client.models = types.MethodType(_ansible_get_models, client)

client.config = self.add_user_agent(client.config)
if not is_track2:
client.config = self.add_user_agent(client.config)

if self.azure_auth._cert_validation_mode == 'ignore':
client.config.session_configuration_callback = self._validation_ignore_callback
Expand Down Expand Up @@ -1483,6 +1491,9 @@ def __init__(self, auth_source=None, profile=None, subscription_id=None, client_
cloud_environment=self._cloud_environment,
resource=graph_resource if self.is_ad_resource else rm_resource,
verify=self._cert_validation_mode == 'validate')
self.azure_credential_track2 = client_secret.ClientSecretCredential(client_id=self.credentials['client_id'],
client_secret=self.credentials['secret'],
tenant_id=self.credentials['tenant'])

elif self.credentials.get('ad_user') is not None and \
self.credentials.get('password') is not None and \
Expand Down
3 changes: 2 additions & 1 deletion requirements-azure.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
packaging
requests[security]
xmltodict
azure-cli-core==2.11.1
azure-cli-core==2.26.1
azure-common==1.1.11
azure-identity==1.7.0
azure-mgmt-apimanagement==0.2.0
azure-mgmt-authorization==0.51.1
azure-mgmt-batch==5.0.1
Expand Down

0 comments on commit fbfe197

Please sign in to comment.