Azure 数据工厂管道:使用 Python 创建管道:身份验证(通过 az cli)

欢迎特拉亚诺

我正在尝试使用 Microsoft 此处提供的示例通过 python 创建 azure 数据工厂管道:

https://docs.microsoft.com/en-us/azure/data-factory/quickstart-create-data-factory-python

def main():

    # Azure subscription ID
    subscription_id = '<Specify your Azure Subscription ID>'

    # This program creates this resource group. If it's an existing resource group, comment out the code that creates the resource group
    rg_name = 'ADFTutorialResourceGroup'

    # The data factory name. It must be globally unique.
    df_name = '<Specify a name for the data factory. It must be globally unique>'

    # Specify your Active Directory client ID, client secret, and tenant ID
    credentials = ServicePrincipalCredentials(client_id='<Active Directory application/client ID>', secret='<client secret>', tenant='<Active Directory tenant ID>')
    resource_client = ResourceManagementClient(credentials, subscription_id)
    adf_client = DataFactoryManagementClient(credentials, subscription_id)

    rg_params = {'location':'eastus'}
    df_params = {'location':'eastus'}

但是,我无法传递如上所示的凭据,因为 azure 登录是作为管道中较早的一个单独步骤执行的,这给我留下了一个经过身份验证的 azure 会话(不能将其他凭据传递到此脚本中)。

在我运行 python 代码来创建管道之前,我通过 Jenkins 部署管道执行“az login”,这为我提供了一个经过身份验证的 azurerm 会话。我应该能够在 python 脚本中重新使用这个会话来获取数据工厂客户端,而无需再次进行身份验证。

但是,我不确定如何修改代码的客户端创建部分,因为似乎没有任何使用已经建立的 azurerm 会话的示例:

    adf_client = DataFactoryManagementClient(credentials, subscription_id)

    rg_params = {'location':'eastus'}
    df_params = {'location':'eastus'}

 #Create a data factory
    df_resource = Factory(location='eastus')
    df = adf_client.factories.create_or_update(rg_name, df_name, df_resource)
    print_item(df)
    while df.provisioning_state != 'Succeeded':
        df = adf_client.factories.get(rg_name, df_name)
        time.sleep(1)

Microsoft 的身份验证文档建议我可以使用先前建立的会话进行身份验证,如下所示:

from azure.common.client_factory import get_client_from_cli_profile
from azure.mgmt.compute import ComputeManagementClient

client = get_client_from_cli_profile(ComputeManagementClient)

(参考:https : //docs.microsoft.com/en-us/python/azure/python-sdk-azure-authenticate? view = azure- python

这有效,但是 azure 数据工厂对象实例化失败:

Traceback (most recent call last):
  File "post-scripts/check-data-factory.py", line 72, in <module>
    main()
  File "post-scripts/check-data-factory.py", line 65, in main
    df = adf_client.factories.create_or_update(rg_name, data_factory_name, df_resource)

AttributeError: 'ComputeManagementClient' object has no attribute 'factories'

因此,在此与获取 df 对象之间可能需要一些额外的步骤?

任何线索表示赞赏!

洛朗·马祖尔

只需用正确的类型替换类:

from azure.common.client_factory import get_client_from_cli_profile
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.datafactory import DataFactoryManagementClient

resource_client = get_client_from_cli_profile(ResourceManagementClient)
adf_client = get_client_from_cli_profile(DataFactoryManagementClient)

您得到的错误是因为您创建了一个 Compute 客户端(用于处理 VM),而不是 ADF 客户端。但是,是的,您找到了适合您需求的文档 :)

(披露:我在 Python SDK 团队的 MS 工作)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用 Azure 进行身份验证以使用 python 运行数据工厂管道测试?

如何在 Yaml 的 Azure 管道中指定 AZ CLI 的版本?

无法在 Azure DevOps 管道中运行嵌套的 az cli 命令

Python Azure数据工厂更新管道

使用 PowerShell 部署 Azure 数据工厂管道

无法弄清楚如何从 Az Devops CLI 创建一个空的构建管道

如何从DevOps管道安全登录Az CLI

在Azure DevOps管道中,如何使用从addSpnToEnvironment参数返回的服务原理详细信息登录到AZ CLI?

如何使用Azure Az CLI以编程方式创建配置了Autopilot的Azure CosmosDB

如何在 Azure DevOps 的构建管道中启用 Ouath 身份验证

Azure 数据工厂管道成本

使用AZ CLI创建Azure应用注册时出现问题

如何使用Azure CLI(Az广告应用程序)创建范围

如何使用Azure数据工厂管道调用REST API?

使用 az cli 创建 EventGrid 订阅

使用 Azure az repos CLI 分叉存储库

使用AZ CLI提取App Service Plan Azure资源列表

使用 az-cli 命令禁用 azure devops repos

Azure CLI:克隆管道

删除多个Azure数据工厂管道

Azure 数据工厂管道基于参数运行

依赖于私有AZ回购的Azure构建管道

Azure CLI使用什么身份验证流?

使用或不使用触发器为 Azure 数据工厂创建 CI 和 CD 管道

无法使用 Azure 数据工厂通过 Azure SQL DB 的托管标识进行身份验证

Azure devops 構建管道:安裝 npm 或 angular cli

Azure CLI在“ az组件更新”时失败

使用 MSI 身份验证的 Azure 数据工厂 Web 活动

从Azure DevOps管道YAML文件运行`az artificats`命令