Skip to content

Commit

Permalink
feat: Return an object with an empty list property when KV does not e…
Browse files Browse the repository at this point in the history
…xist (#167)

* Return an object with an empty list property when KV does not exist

* Retrieve access policies if we're sure that the KeyVault exists

Closes #166
  • Loading branch information
fgheysels authored Apr 27, 2021
1 parent f98cb54 commit 31994af
Showing 1 changed file with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ else
$keyVault = Get-AzKeyVault -VaultName $keyVaultName -ResourceGroupName $resourceGroupName
}

$armAccessPolicies = @()

if($keyVault)
{
$armAccessPolicies = @()
{
Write-Host "Key Vault '$keyVaultName' is found."

$keyVaultAccessPolicies = $keyVault.accessPolicies

if($keyVaultAccessPolicies)
{
Write-Host "Key Vault '$keyVaultName' is found."

{
foreach($keyVaultAccessPolicy in $keyVaultAccessPolicies)
{
$armAccessPolicy = [pscustomobject]@{
Expand All @@ -42,16 +43,16 @@ if($keyVault)

$armAccessPolicies += $armAccessPolicy
}
}

$armAccessPoliciesParameter = [pscustomobject]@{
list = $armAccessPolicies
}

Write-Host "Current access policies: $armAccessPoliciesParameter"
return $armAccessPoliciesParameter
}
}
else
{
Write-Warning "KeyVault '$keyVaultName' could not be found."
}

$armAccessPoliciesParameter = [pscustomobject]@{
list = $armAccessPolicies
}

Write-Host "Current access policies: $armAccessPoliciesParameter"
return $armAccessPoliciesParameter

0 comments on commit 31994af

Please sign in to comment.