0

我正在尝试编写一个 Python Azure 函数来创建具有自定义角色的服务主体。我有 JSON 模板来传递角色定义并创建自定义角色。该函数的想法是使用等效于“az ad sp create-for-rbac”cli 命令的 REST API 并生成 client_id、client_secret 和tenant_id。如果您尝试过,请告诉我,非常感谢您提供任何帮助,谢谢!

import logging
  
import azure.functions as func


def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    name = req.params.get('name')
    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            name = req_body.get('name')

    if name:
        return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
    else:
        return func.HttpResponse(
             "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
             status_code=200
        )
4

1 回答 1

0

你有两个选择:

  1. 利用Microsoft Graph API创建和管理您的应用用户。不幸的是,目前没有适用于 Python 的 SDK,因此您需要自己通过 API 调用进行设置。
  2. 更简单但不推荐。使用Azure SDK for PythonGraphRbacManagementClient中的类。库中有专门用于执行此操作的方法(这是CLI 当前使用的方法)。但是,我们不再开发 Azure Graph API,而是建议迁移到 Microsoft Graph API。
于 2020-09-24T20:50:21.567 回答