【问题标题】:What permissions are needed to run the adf pipeline api运行 adf 管道 api 需要什么权限
【发布时间】:2022-01-09 11:25:49
【问题描述】:

运行 Azure 数据工厂管理 API 需要哪些权限。例如,我正在尝试在网络活动中执行 Pipeline runsQuery by factory api。

错误:

User configuration issue
{"error":{"code":"AuthorizationFailed","message":"The client with object id does not have authorization to perform action 'Microsoft.DataFactory/factories/pipelineruns/read' over scope '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/pipelineruns/{runId}' or the scope is invalid. If access was recently granted, please refresh your credentials."}}

能否请您指导我如何传递凭据并获取 GET 和 POST 方法的令牌。

【问题讨论】:

    标签: azure azure-data-factory-2


    【解决方案1】:

    您需要创建一个可以访问您的数据工厂的 Azure Active Directory 应用程序。

    1. Create an Azure Active Directory application,对于登录 URL,您可以提供一个虚拟 URL (https://contoso.org/exampleapp)。
    2. Get values for signing in,获取应用 ID 和租户 ID,并记下这些值以备后用。
    3. Certificates and secrets,获取身份验证密钥,并记下您在本教程后面使用的此值。
    4. Assign the application to a role,将应用程序分配给订阅级别的贡献者角色,以便应用程序可以在订阅中创建数据工厂。

    完成上述步骤后,您需要创建 DataFactoryManagementClient 并使用以下代码 sn-p 验证您的应用程序:

    var context = new AuthenticationContext("https://login.microsoftonline.com/" + tenantID);
    ClientCredential cc = new ClientCredential(applicationId, authenticationKey);
    AuthenticationResult result = context.AcquireTokenAsync("https://management.azure.com/", cc).Result;
    ServiceClientCredentials cred = new TokenCredentials(result.AccessToken);
    var client = new DataFactoryManagementClient(cred) {
        SubscriptionId = subscriptionId };
    

    一旦您验证了您的应用程序,您就可以使用以下代码 sn-p 启动管道运行:

    // Create a pipeline run
    Console.WriteLine("Creating pipeline run...");
    
    CreateRunResponse runResponse = client.Pipelines.CreateRunWithHttpMessagesAsync(
        resourceGroup, dataFactoryName, pipelineName, parameters: parameters
    ).Result.Body;
    Console.WriteLine("Pipeline run ID: " + runResponse.RunId);
    

    以下是运行 Azure 数据工厂管道的控制台应用程序的完整代码:

    using Microsoft.Azure.Management.DataFactory;
    using Microsoft.Azure.Management.DataFactory.Models;
    using Microsoft.IdentityModel.Clients.ActiveDirectory;
    using Microsoft.Rest;
    using System;
    
    namespace ADF
    {
        class Program
        {
            static void Main(string[] args)
            {
                // Set variables
                string tenantID = "<your tenant ID>";
                string applicationId = "<your application ID>";
                string authenticationKey = "<your authentication key for the application>";
                string subscriptionId = "<your subscription ID where the data factory resides>";
                string resourceGroup = "<your resource group where the data factory resides>";
                string dataFactoryName ="<specify the name of data factory to create. It must be globally unique.>";
                string pipelineName = "<specify the name of pipeline to run. It must be globally unique.>";
    
                // Authenticate and create a data factory management client
                var context = new AuthenticationContext("https://login.microsoftonline.com/" + tenantID);
                ClientCredential cc = new ClientCredential(applicationId, authenticationKey);
                AuthenticationResult result = context.AcquireTokenAsync("https://management.azure.com/", cc).Result;
                ServiceClientCredentials cred = new TokenCredentials(result.AccessToken);
                
                var client = new DataFactoryManagementClient(cred)
                {
                    SubscriptionId = subscriptionId
                };
    
                // Create a pipeline run
                Console.WriteLine("Creating pipeline run...");
    
                CreateRunResponse runResponse = client.Pipelines.CreateRunWithHttpMessagesAsync(
                    resourceGroup, dataFactoryName, pipelineName
                ).Result.Body;
    
                Console.WriteLine("Pipeline run ID: " + runResponse.RunId);
            }
        }
    }
    

    不要忘记添加 Nuget 包:

    Install-Package Microsoft.Azure.Management.DataFactory
    Install-Package Microsoft.Azure.Management.ResourceManager -IncludePrerelease
    Install-Package Microsoft.IdentityModel.Clients.ActiveDirectory
    

    【讨论】:

    • 嗨@Prami Gawande,谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-03
    • 2016-10-14
    • 1970-01-01
    • 2020-05-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多