Azure服务主体创建-使用Azure功能



我正在尝试编写一个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
)

您有两个选项:

  1. 使用Microsoft Graph API创建和管理您的应用程序用户。不幸的是,目前还没有针对Python的SDK,所以您需要通过API调用自己来设置
  2. 更简单,但不推荐使用。使用Azure SDK for Python中的GraphRbacManagementClient类。库中有专门用于执行此操作的方法(CLI当前使用的就是这种方法(。但是,我们不再开发Azure Graph API,而是建议迁移到Microsoft Graph API

最新更新