From 9f08de7505e7eaa1b5f914024ed8bdbc31a2cc3e Mon Sep 17 00:00:00 2001 From: Beisi Zhou Date: Mon, 23 Nov 2020 15:53:05 +0800 Subject: [PATCH] remove -hashashtable from ConvertFrom-Json to compatible with windows powershell --- .../Az.KeyVault.Extension.psm1 | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/KeyVault/KeyVault/Az.KeyVault.Extension/Az.KeyVault.Extension.psm1 b/src/KeyVault/KeyVault/Az.KeyVault.Extension/Az.KeyVault.Extension.psm1 index 8433eee8dac5..9e22925e86ed 100644 --- a/src/KeyVault/KeyVault/Az.KeyVault.Extension/Az.KeyVault.Extension.psm1 +++ b/src/KeyVault/KeyVault/Az.KeyVault.Extension/Az.KeyVault.Extension.psm1 @@ -37,10 +37,7 @@ function Get-Secret { $SecretValue = Get-String $Secret } - 'SecureString' - { - $SecretValue = Get-SecureString $Secret - } + 'PSCredential' { Get-PSCredential $Secret @@ -51,7 +48,7 @@ function Get-Secret } Default { - throw "Unknown secret type" + $SecretValue = Get-SecureString $Secret } } return $SecretValue @@ -112,8 +109,10 @@ function Get-Hashtable [object] $Secret ) - $secretValueText = Get-String $Secret - return ConvertFrom-Json $secretValueText -AsHashtable + $jsonObject = Get-String $Secret | ConvertFrom-Json + $hashtable = @{} + $jsonObject.psobject.Properties | foreach { $hashtable[$_.Name] = $_.Value } + return $hashtable } function Set-Secret @@ -240,10 +239,10 @@ function Get-SecretInfo [string] $VaultName, [hashtable] $AdditionalParameters ) - - Check-SubscriptionLogIn $AdditionalParameters.SubscriptionId $AdditionalParameters.AZKVaultName - if ([string]::IsNullOrEmpty($Filter)) + Check-SubscriptionLogIn $AdditionalParameters.SubscriptionId $AdditionalParameters.AZKVaultName + + if ([string]::IsNullOrEmpty($Filter)) { $Filter = "*" } @@ -256,10 +255,14 @@ function Get-SecretInfo { if ($pattern.IsMatch($vaultSecretInfo.Name)) { + if($vaultSecretInfo.ContentType -eq $null) + { + $vaultSecretInfo.ContentType = 'Unknown' + } Write-Output ( [Microsoft.PowerShell.SecretManagement.SecretInformation]::new( $vaultSecretInfo.Name, - [Microsoft.PowerShell.SecretManagement.SecretType]::SecureString, + [System.Enum]::Parse([Microsoft.PowerShell.SecretManagement.SecretType], $vaultSecretInfo.ContentType), $VaultName) ) }