Skip to content

Commit

Permalink
Upgrade azure-mgmt-authorizaiton to 2.0.0 (#955)
Browse files Browse the repository at this point in the history
* Upgrade azure-mgmt-authorizaiton to 2.0.0

* remove blank line
  • Loading branch information
Fred-sun authored Aug 19, 2022
1 parent b70b40a commit 7734d84
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 29 deletions.
7 changes: 4 additions & 3 deletions plugins/module_utils/azure_rm_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def default_api_version(self):
# For now, we have to copy from azure-cli
AZURE_API_PROFILES = {
'latest': {
'AuthorizationManagementClient': '2018-09-01-preview',
'AuthorizationManagementClient': '2020-04-01-preview',
'ContainerInstanceManagementClient': '2018-02-01-preview',
'ComputeManagementClient': dict(
default_api_version='2018-10-01',
Expand Down Expand Up @@ -1012,12 +1012,13 @@ def authorization_client(self):
if not self._authorization_client:
self._authorization_client = self.get_mgmt_svc_client(AuthorizationManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager,
api_version='2018-09-01-preview')
is_track2=True,
api_version='2020-04-01-preview')
return self._authorization_client

@property
def authorization_models(self):
return AuthorizationManagementClient.models('2018-09-01-preview')
return AuthorizationManagementClient.models('2020-04-01-preview')

@property
def subscription_client(self):
Expand Down
16 changes: 7 additions & 9 deletions plugins/modules/azure_rm_roleassignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,9 @@
sample: /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
'''

import uuid
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase

try:
from msrestazure.azure_exceptions import CloudError
import uuid
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase

except ImportError:
# This is handled in azure_rm_common
Expand Down Expand Up @@ -266,7 +264,7 @@ def create_roleassignment(self):
role_assignment_name=self.name,
parameters=parameters)

except CloudError as exc:
except Exception as exc:
self.log('Error attempting to create role assignment.')
self.fail("Error creating role assignment: {0}".format(str(exc)))
return self.roleassignment_to_dict(response)
Expand All @@ -280,7 +278,7 @@ def delete_roleassignment(self, assignment_id):
self.log("Deleting the role assignment {0}".format(self.name))
try:
response = self.authorization_client.role_assignments.delete_by_id(role_id=assignment_id)
except CloudError as e:
except Exception as e:
self.log('Error attempting to delete the role assignment.')
self.fail("Error deleting the role assignment: {0}".format(str(e)))

Expand All @@ -307,7 +305,7 @@ def get_roleassignment(self):
!= self.role_definition_id.split('/')[-1].lower()):
self.fail('State Mismatch Error: The assignment ID exists, but does not match the provided role.')

except CloudError as ex:
except Exception as ex:
self.log("Didn't find role assignments id {0}".format(self.id))

elif self.name and self.scope:
Expand All @@ -321,7 +319,7 @@ def get_roleassignment(self):
!= self.role_definition_id.split('/')[-1].lower()):
self.fail('State Mismatch Error: The assignment name exists, but does not match the provided role.')

except CloudError as ex:
except Exception as ex:
self.log("Didn't find role assignment by name {0} at scope {1}".format(self.name, self.scope))

else:
Expand All @@ -337,7 +335,7 @@ def get_roleassignment(self):
self.fail('If id or name are not supplied, then assignee_object_id and role_definition_id are required.')
if response:
role_assignment = response[0]
except CloudError as ex:
except Exception as ex:
self.log("Didn't find role assignments for subscription {0}".format(self.subscription_id))

return role_assignment
Expand Down
12 changes: 5 additions & 7 deletions plugins/modules/azure_rm_roleassignment_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,11 @@
'''

try:
from msrestazure.azure_exceptions import CloudError
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
except ImportError:
# This is handled in azure_rm_common
pass

from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase


class AzureRMRoleAssignmentInfo(AzureRMModuleBase):

Expand Down Expand Up @@ -216,7 +214,7 @@ def get_by_id(self):
response = [self.roleassignment_to_dict(a) for a in response]
results = response

except CloudError as ex:
except Exception as ex:
self.log("Didn't find role assignments id {0}".format(self.scope))

return results
Expand All @@ -242,7 +240,7 @@ def get_by_name(self):

results = response

except CloudError as ex:
except Exception as ex:
self.log("Didn't find role assignment {0} in scope {1}".format(self.name, self.scope))

return results
Expand Down Expand Up @@ -275,7 +273,7 @@ def list_assignments(self, filter=None):

results = response

except CloudError as ex:
except Exception as ex:
self.log("Didn't find role assignments in subscription {0}.".format(self.subscription_id))

return results
Expand Down Expand Up @@ -310,7 +308,7 @@ def list_by_scope(self):

results = response

except CloudError as ex:
except Exception as ex:
self.log("Didn't find role assignments at scope {0}".format(self.scope))

return results
Expand Down
10 changes: 5 additions & 5 deletions plugins/modules/azure_rm_roledefinition.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@

try:
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
from msrestazure.azure_exceptions import CloudError
from msrestazure.azure_operation import AzureOperationPoller
from msrest.polling import LROPoller
from azure.core.polling import LROPoller
from msrest.serialization import Model
from azure.mgmt.authorization import AuthorizationManagementClient
from azure.mgmt.authorization.model import (RoleDefinition, Permission)
Expand Down Expand Up @@ -228,6 +227,7 @@ def exec_module(self, **kwargs):
# get management client
self._client = self.get_mgmt_svc_client(AuthorizationManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager,
is_track2=True,
api_version="2018-01-01-preview")

self.scope = self.build_scope()
Expand Down Expand Up @@ -344,7 +344,7 @@ def create_update_roledefinition(self):
if isinstance(response, LROPoller) or isinstance(response, AzureOperationPoller):
response = self.get_poller_result(response)

except CloudError as exc:
except Exception as exc:
self.log('Error attempting to create role definition.')
self.fail("Error creating role definition: {0}".format(str(exc)))
return roledefinition_to_dict(response)
Expand All @@ -362,7 +362,7 @@ def delete_roledefinition(self, role_definition_id):
role_definition_id=role_definition_id)
if isinstance(response, LROPoller) or isinstance(response, AzureOperationPoller):
response = self.get_poller_result(response)
except CloudError as e:
except Exception as e:
self.log('Error attempting to delete the role definition.')
self.fail("Error deleting the role definition: {0}".format(str(e)))

Expand Down Expand Up @@ -394,7 +394,7 @@ def get_roledefinition(self):
if len(roles) > 1:
self.fail("Found multiple role definitions: {0}".format(roles))

except CloudError as ex:
except Exception as ex:
self.log("Didn't find role definition {0}".format(self.name))

return False
Expand Down
8 changes: 4 additions & 4 deletions plugins/modules/azure_rm_roledefinition_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@

try:
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
from msrestazure.azure_exceptions import CloudError
from msrest.serialization import Model
from azure.mgmt.authorization import AuthorizationManagementClient

Expand Down Expand Up @@ -198,6 +197,7 @@ def exec_module(self, **kwargs):
# get management client
self._client = self.get_mgmt_svc_client(AuthorizationManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager,
is_track2=True,
api_version="2018-01-01-preview")

if self.id:
Expand Down Expand Up @@ -242,7 +242,7 @@ def list(self):
if len(roles) > 0:
return [roledefinition_to_dict(r) for r in roles]

except CloudError as ex:
except Exception as ex:
self.log("Didn't find role definition in scope {0}".format(self.scope))

return response
Expand All @@ -267,7 +267,7 @@ def get_by_id(self):
else:
return [response]

except CloudError as ex:
except Exception as ex:
self.log("Didn't find role definition by id {0}".format(self.id))

return []
Expand Down Expand Up @@ -297,7 +297,7 @@ def get_by_role_name(self):
if len(roles) > 1:
self.fail("Found multiple Role Definitions with name: {0}".format(self.role_name))

except CloudError as ex:
except Exception as ex:
self.log("Didn't find Role Definition by name {0}".format(self.role_name))

return []
Expand Down
2 changes: 1 addition & 1 deletion requirements-azure.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ azure-cli-core==2.34.0
azure-common==1.1.11
azure-identity==1.7.0
azure-mgmt-apimanagement==0.2.0
azure-mgmt-authorization==0.51.1
azure-mgmt-authorization==2.0.0
azure-mgmt-batch==5.0.1
azure-mgmt-cdn==11.0.0
azure-mgmt-compute==26.1.0
Expand Down

0 comments on commit 7734d84

Please sign in to comment.