I am trying to write a Python Azure Function to create service principal with custom role. I have the JSON template to pass role definitions and create a custom role. The idea for the function is to using REST API equivalent to 'az ad sp create-for-rbac' cli command and generate client_id, client_secret and tenant_id. Please let me know if you have tried this and any help here is much appreciated, thank you!
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
)