从azure查询azure应用程序网关设置或整个ARM模板

问题描述 投票:0回答:1

您好,我想构建后端c#,在其中我将能够查询已经配置的Azure应用程序网关的所有设置。我尝试使用Frontdoor,并使用Frontdoorclient连接到Frontdoor,并能够查询所有负载平衡器设置和其他设置。这对我有所帮助,因为Azure.management.Fluent.Frontdoor.dlll的前门有客户端,而对于azure.mamgement.network.dll,我找不到用于Azure应用程序网关的客户端。

c# asp.net azure azure-api-management
1个回答
0
投票

Azure SDK不提供管理客户端来直接管理Azure应用程序网关。如果要管理它,则应使用NetworkManagementClient.ApplicationGateways对其进行管理。有关更多详细信息,请参阅document

  1. 创建服务主体并为sp分配角色
az login
az account set --subscription "<your subscription id>"
# the sp will have Azure Contributor role
az ad sp create-for-rbac -n "readMetric" 

enter image description here

  1. 代码
# use msal get token
var app = ConfidentialClientApplicationBuilder.Create(<sp app id>)
           .WithAuthority(AzureCloudInstance.AzurePublic, "<sp tenantID>")
           .WithClientSecret(<sp password>)
           .Build();
string[] scopes = new string[] { "https://management.azure.com/.default" };
var  result = await app.AcquireTokenForClient(scopes)
                   .ExecuteAsync();
TokenCredentials tokenCredentials = new TokenCredentials(result.AccessToken,"Bearer");

 NetworkManagementClient networkManagementClient = new NetworkManagementClient(tokenCredentials);
ApplicationGateway appgateway =await networkManagementClient.ApplicationGateways.GetAsync("<groupName>", "<resourceName>");

// get application gateway settings:https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.management.network.models.applicationgateway?view=azure-dotnet


© www.soinside.com 2019 - 2024. All rights reserved.