gpt4 book ai didi

azure - 如何在rest api收集Azure Key Vault中的所有 secret 后获取所有 key

转载 作者:行者123 更新时间:2023-12-03 02:11:28 25 4
gpt4 key购买 nike

祝大家有美好的一天!我有一个 VMware Windows,它在 key 保管库中有权限,我想收集所有 key ,但完成后的下面的代码只有 ID + 属性,不包含 key 值。任何人都可以帮我完成下面的代码以获取所有关键 secret 。

非常感谢您的帮助!

$RresourceUrl = 'dddd.vault.azure.net'

# Compose REST request.
$response = Invoke-WebRequest -Uri 'http://169.254.111.211/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https%3A%2F%2Fvault.azure.net' -Method GET -Headers @{Metadata="true"}

$OAuth = $response.Content | ConvertFrom-Json


# Check if authentication was successfull.
if ($OAuth.access_token) {
#Format headers.
$HeaderParams = @{
'Content-Type' = "application\json"

'Authorization' = "Bearer $($OAuth.access_token)"
}

# Create an empty array to store the result.
$QueryResults = @()

$Uri = "https://$RresourceUrl/secrets?api-version=2016-10-01"
# Invoke REST method and fetch data until there are no pages left.
do {

$Results = Invoke-WebRequest -Uri $Uri -Method GET -Headers $HeaderParams | ConvertFrom-Json
$Results.nextLink
if ($Results.value) {
$QueryResults += $Results.value
}
else {
$QueryResults += $Results
}
$Uri = $Results.nextLink
} until (!($Uri))

# Return the result.
$QueryResults | Export-Csv -NoTypeInformatio *\Documents\Tesst.csv
}
else {
Write-Error "No Access Token"
}


最佳答案

这是我的最终代码,可能尚未优化,但它有效。

$RresourceUrl = 'devakv01.vault.azure.net'

# Compose REST request.
$response = Invoke-WebRequest -Uri 'http://169.254.111.211/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https%3A%2F%2Fvault.azure.net' -Method GET -Headers @{Metadata="true"}

$OAuth = $response.Content | ConvertFrom-Json


# Check if authentication was successfull.
if ($OAuth.access_token) {
#Format headers.
$HeaderParams = @{
'Content-Type' = "application\json"

'Authorization' = "Bearer $($OAuth.access_token)"
}

# Create an empty array to store the result.
$QueryResults = @()

$Uri = "https://$RresourceUrl/secrets?api-version=2016-10-01"
# Invoke REST method and fetch data until there are no pages left.
do {

$Results = Invoke-WebRequest -Uri $Uri -Method GET -Headers $HeaderParams | ConvertFrom-Json
$Results.nextLink
if ($Results.value) {
$QueryResults += $Results.value
}
else {
$QueryResults += $Results
}
$Uri = $Results.nextLink
} until (!($Uri))

# Return the result.
$QueryResults
}
else {
Write-Error "No Access Token"
}

# get Key after to have secrets name

$output = ForEach ($nameSecret in $QueryResults.id)
{
$Resultskey = Invoke-WebRequest -Uri $($nameSecret+'?api-version=2016-10-01') -Method GET -Headers $HeaderParams | ConvertFrom-Json
$Resultskey
}
$output | Export-Csv -NoTypeInformatio *\$RresourceUrl.csv

关于azure - 如何在rest api收集Azure Key Vault中的所有 secret 后获取所有 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73273892/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com