简体   繁体   English

Azure KeyVault遍历文件库中的所有机密

[英]Azure KeyVault iterate over all secrets in a vault

For the sake of simplicity let assume I want to build a dictionary from all the secrets in specific vault with the Secret Name and the Secret Value, using Azure REST API. 为了简单起见,假设我想使用Azure REST API根据特定库中的所有秘密(具有“秘密名称”和“秘密值”)来构建字典。

The problem I'm facing is that the Get Secrets API call returns SecretListResult which contains a list of SecretItem. 我面临的问题是Get Secrets API调用返回SecretListResult,其中包含SecretItem的列表。 the SecretItem has ID element, but not a Name, nor the Value. SecretItem具有ID元素,但没有Name,也没有Value。 The GetSecret API needs the secret name and not the secret ID, and so far I cant find a way the translate an ID to name. GetSecret API需要密码名而不是密码ID,到目前为止,我找不到将ID转换为名称的方法。

any suggestions would be highly appreciated 任何建议将不胜感激

Thank you. 谢谢。

// Get list of secrets //获取机密列表

GET https://alice.vault.azure.net/secrets?api-version=2015-06-01

Response Body:
{
  "value": [
    {
      "contentType": "text",
      "id": "https://alice.vault.azure.net/secrets/secret1",
      "attributes": {
        "enabled": true,
        "created": 1496749576,
        "updated": 1496749576
      }
    },
    {
      "contentType": "text",
      "id": "https://alice.vault.azure.net/secrets/secret2",
      "attributes": {
        "enabled": true,
        "created": 1496749590,
        "updated": 1496749590
      }
    }
  ],
  "nextLink": null
}

// Get secret properties and value //获取秘密的属性和价值

Parse id , look for last occurrence of / to get secret name. 解析id ,查找/最后一次出现以获取秘密名称。 One call per item. 每个项目一个通话。

GET https://alice.vault.azure.net/secrets/secret1/?api-version=2015-06-01

Response Body:
{
  "value": "5up3r1ee7s3cr3t",
  "contentType": "text",
  "id": "https://alice.vault.azure.net/secrets/secret1/6ac15a48877148e094276504d73e95a1",
  "attributes": {
    "enabled": true,
    "created": 1496749576,
    "updated": 1496749576
  }
}


GET https://alice.vault.azure.net/secrets/secret2/?api-version=2015-06-01

Response Body:
{
  "value": "@n0th3r5up3r1ee7s3cr3t",
  "contentType": "text",
  "id": "https://alice.vault.azure.net/secrets/secret2/2b34de363d6445ba83bb23bafaea6658",
  "attributes": {
    "enabled": true,
    "created": 1496749590,
    "updated": 1496749590
  }
}

Source: I just looked at what Azure PowerShell calls on the wire with -Debug , eg: 来源:我只是使用-Debug查看了Azure PowerShell在网络上的调用,例如:

Get-AzureKeyVaultSecret -VaultName Alice -Debug
Get-AzureKeyVaultSecret -VaultName Alice -Name secret1 -Debug

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM