我正在尝试编写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
)
答案 0 :(得分:0)
您有两个选择:
GraphRbacManagementClient
类。库中有专门用于执行此操作的方法(这就是the CLI currently uses)。但是,我们不再开发Azure Graph API,建议迁移到Microsoft Graph API。