c# - 从 azure 查询 azure 应用程序网关设置或整个 ARM 模板
问题描述
您好,我想构建后端 c#,我将能够在其中查询我已经配置的 azure 应用程序网关的所有设置。我尝试过使用 Frontdoor 并使用 Frontdoorclient 连接到前门并能够查询所有负载均衡器设置和其他设置。这对我有帮助,因为 Azure.management.Fluent.Frontdoor.dlll 上的前门有客户端,而对于 azure.mamgement.network.dll,我找不到 azure 应用程序网关的客户端。
解决方案
Azure SDK 不提供直接管理 Azure 应用程序网关的管理客户端。如果我们想管理它,我们应该使用NetworkManagementClient.ApplicationGateways
它来管理它。更多详细信息,请参阅文档
- 创建服务主体并将角色分配给 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"
- 代码
# 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
推荐阅读
- java - 在 Parent 和 Child 中类似方法签名的情况下的 Java 行为
- javascript - 为什么添加 console.log 语句会阻止测试超时?
- google-chrome - 在 url 中使用别名时 NTLM 而不是 Kerberos 和 Chrome 版本 69
- html - CSS - 使复选框和长描述内联
- jsf - PrimeFaces 6.1 中rich:extendedDataTable 的替代方案
- c++ - MS Word ShapeNode 坐标无法获取
- javascript - 如何在 React 中创建下拉菜单?
- javascript - React 受控组件与不受控组件的总体定义
- angular - 如何访问在同一个父组件中多次使用的子组件的不同输入的值?
- shell - 在引用另一个时设置环境变量