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