def get_principal_dictionary(graph_client, object_ids, raise_on_graph_call_error=False): """Retrieves Azure AD Objects for corresponding object ids passed. :param graph_client: A client for Microsoft Graph. :param object_ids: The object ids to retrieve Azure AD objects for. :param raise_on_graph_call_error: A boolean indicate whether an error should be raised if the underlying Microsoft Graph call fails. :return: A dictionary keyed by object id with the Azure AD object as the value. Note: empty Azure AD objects could be returned if not found in the graph. """ if not object_ids: return {} object_params = GetObjectsParameters( include_directory_object_references=True, object_ids=object_ids) principal_dics = { object_id: DirectoryObject() for object_id in object_ids } aad_objects = graph_client.objects.get_objects_by_object_ids( object_params) try: for aad_object in aad_objects: principal_dics[aad_object.object_id] = aad_object except CloudError as e: if e.status_code in [403, 401]: GraphHelper.log.warning( 'Credentials not authorized for access to read from Microsoft Graph. \n ' 'Can not query on principalName, displayName, or aadType. \n' ) else: GraphHelper.log.error( 'Exception in call to Microsoft Graph. \n ' 'Can not query on principalName, displayName, or aadType. \n' 'Error: {0}'.format(e)) if raise_on_graph_call_error: raise return principal_dics
def get_principal_dictionary(graph_client, object_ids): object_params = GetObjectsParameters( include_directory_object_references=True, object_ids=object_ids) principal_dics = { object_id: DirectoryObject() for object_id in object_ids } aad_objects = graph_client.objects.get_objects_by_object_ids( object_params) try: for aad_object in aad_objects: principal_dics[aad_object.object_id] = aad_object except CloudError: GraphHelper.log.warning( 'Credentials not authorized for access to read from Microsoft Graph. \n ' 'Can not query on principalName, displayName, or aadType. \n') return principal_dics