0

我正在尝试使用以下代码从 azure 订阅中枚举 Azure AD 用户:WORKING_DIRECTORY = os.getcwd() TENANT_ID = "REDACTED_AZURE_ID_OF_MY_AZURE_AD_USER" AZURE_AUTH_LOCATION = os.path.join(WORKING_DIRECTORY, "mycredentials.json") # from: az ad sp create-for-rbac --sdk-auth > mycredentials.json

# I've tried with get_client_from_cli_profile() while logged in azure CLI
# I've tried with and without parameters auth_path and tenant_id
rbac_client = get_client_from_auth_file(GraphRbacManagementClient,auth_path=AZURE_AUTH_LOCATION, tenant_id=TENANT_ID)

# Try to list users
for user in rbac_client.users.list():
    pprint(user.__dict__)

正如我在评论中详述的那样,我试图通过几次不成功的尝试来解决这个问题,这里是堆栈跟踪

/home/guillaumedsde/.virtualenvs/champollion/bin/python /home/guillaumedsde/PycharmProjects/champollion/champollion/champollion.py
Traceback (most recent call last):
  File "/home/guillaumedsde/PycharmProjects/champollion/champollion/champollion.py", line 582, in <module>
    gitlab_project_member.access_level)
  File "/home/guillaumedsde/PycharmProjects/champollion/champollion/champollion.py", line 306, in create_role_assignment
    "principal_id": get_user_azure_id(user)}  # get_user_azure_id(user)}  # TODO
  File "/home/guillaumedsde/PycharmProjects/champollion/champollion/champollion.py", line 329, in get_user_azure_id
    for user in rbac_client.users.list():
  File "/home/guillaumedsde/.virtualenvs/champollion/lib/python3.6/site-packages/msrest/paging.py", line 131, in __next__
    self.advance_page()
  File "/home/guillaumedsde/.virtualenvs/champollion/lib/python3.6/site-packages/msrest/paging.py", line 117, in advance_page
    self._response = self._get_next(self.next_link)
  File "/home/guillaumedsde/.virtualenvs/champollion/lib/python3.6/site-packages/azure/graphrbac/operations/users_operations.py", line 158, in internal_paging
    raise models.GraphErrorException(self._deserialize, response)
azure.graphrbac.models.graph_error.GraphErrorException: Operation returned an invalid status code 'Not Found'

Process finished with exit code 1
4

1 回答 1

1

是 azure-common 1.1.13 https://pypi.org/project/azure-common/1.1.13/中修复的错误

您现在可以简单地执行此操作(没有租户 ID)

rbac_client = get_client_from_auth_file(GraphRbacManagementClient,auth_path=AZURE_AUTH_LOCATION)

我也借此机会修复了此方法的 CLI 版本。

(我在 MS 拥有此代码)

于 2018-07-03T20:07:19.700 回答