From a724fa21f1ee9350dc0644c9a0d346f806b4494d Mon Sep 17 00:00:00 2001 From: Beisi Zhou Date: Sun, 25 Apr 2021 16:47:18 +0800 Subject: [PATCH] bug fix for Get-AzKeyVaultSecret -IncludeVersions when current version is disabled --- src/KeyVault/KeyVault/ChangeLog.md | 1 + .../KeyVault/Commands/GetAzureKeyVaultSecret.cs | 11 +++-------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/KeyVault/KeyVault/ChangeLog.md b/src/KeyVault/KeyVault/ChangeLog.md index bb0bbfc16e6b..c6be958e73ef 100644 --- a/src/KeyVault/KeyVault/ChangeLog.md +++ b/src/KeyVault/KeyVault/ChangeLog.md @@ -18,6 +18,7 @@ - Additional information about change #1 --> ## Upcoming Release +* Fixed a bug for `Get-AzKeyVaultSecret -IncludeVersions` when current version is disabled [#14740] ## Version 3.4.2 * Fixed a bug for `Get-AzKeyVaultSecret -AsPlainText` if the secret is not found [#14645] diff --git a/src/KeyVault/KeyVault/Commands/GetAzureKeyVaultSecret.cs b/src/KeyVault/KeyVault/Commands/GetAzureKeyVaultSecret.cs index 7b00e5d5e653..df03cb72d57f 100644 --- a/src/KeyVault/KeyVault/Commands/GetAzureKeyVaultSecret.cs +++ b/src/KeyVault/KeyVault/Commands/GetAzureKeyVaultSecret.cs @@ -222,12 +222,7 @@ public override void ExecuteCmdlet() } else if (IncludeVersions) { - secret = DataServiceClient.GetSecret(VaultName, Name, string.Empty); - if (secret != null) - { - WriteObject(new PSKeyVaultSecretIdentityItem(secret)); - GetAndWriteSecretVersions(VaultName, Name, secret.Version); - } + GetAndWriteSecretVersions(VaultName, Name); } else if (InRemovedState) { @@ -271,14 +266,14 @@ private void GetAndWriteSecrets(string vaultName, string name) => }, (options) => KVSubResourceWildcardFilter(name, DataServiceClient.GetSecrets(options))); - private void GetAndWriteSecretVersions(string vaultName, string name, string currentSecretVersion) => + private void GetAndWriteSecretVersions(string vaultName, string name) => GetAndWriteObjects(new KeyVaultObjectFilterOptions { VaultName = vaultName, Name = name, NextLink = null }, - (options) => DataServiceClient.GetSecretVersions(options).Where(s => s.Version != currentSecretVersion)); + (options) => DataServiceClient.GetSecretVersions(options)); private void WriteSecret(PSKeyVaultSecret secret) {