微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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类。库中有专门用于执行此操作的方法(这就是the CLI currently uses)。但是,我们不再开发Azure Graph API,建议迁移到Microsoft Graph API。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。