簡體   English   中英

使用 Azure CLI 獲取 Azure 應用程序網關的“principalId”值

[英]Using Azure CLI Get the 'principalId' value of an Azure Application Gateway

PS /home/ian> az network application-gateway identity show --gateway-name "xxx-inf-abc-wag" --resource-group "network-xxx"
{
  "principalId": null,
  "tenantId": null,
  "type": "userAssigned",
  "userAssignedIdentities": {
    "/subscriptions/XXXXXXXXX-80b8-4447-b2a6-XXXXXXXXXX/resourcegroups/network-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/dev-gpp-wag-mi": {
      "clientId": "DDDDDDDDD-eb2e-4836-898a-DDDDDDDDD",
      "principalId": "UUUUUUUUUU-b7c8-43d2-80a2-UUUUUUUUUU"
    }
  }
}

我只想從運行“az.network application-gateway identity show”返回的上述 json 中檢索字段“principalId”的值。

我想我需要添加“--query...something”。 我嘗試了“--query.principalId”,但這不起作用。 我知道我的“--query”語法有問題但不知道如何解決?

通過使用另一個 az 命令解決了它...

$id = $(az ad sp list --display-name "XXX-abc-wag-mi" --query [0].id --output tsv)

az.network application-gateway identity show使用以下查詢表達式

$id=$(az.network application-gateway identity show -g MyResourceGroup --gateway ag1 --query 'userAssignedIdentities."/subscriptions/XXXXXXXXX-80b8-4447-b2a6-XXXXXXXXXX/resourcegroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id1".principalId' -o tsv)

解釋

az.network application-gateway identity show -g MyResourceGroup --gateway-name ag1給出以下 output:

{
  "principalId": null,
  "tenantId": null,
  "type": "userAssigned",
  "userAssignedIdentities": {
    "/subscriptions/XXXXXXXXX-80b8-4447-b2a6-XXXXXXXXXX/resourcegroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id1": {
      "clientId": "DDDDDDDDD-eb2e-4836-898a-DDDDDDDDD",
      "principalId": "UUUUUUUUUU-b7c8-43d2-80a2-UUUUUUUUUU"
    }
  }
}

由於密鑰/subscriptions/XXXXXXXXX-80b8-4447-b2a6-XXXXXXXXXX/resourcegroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id1包含正斜杠和點字符(特殊字符),因此必須對其進行轉義。

因此,密鑰應該用雙引號引起來

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM