Skip to content

Commit c98279e

Browse files
committed
Fixing purging of managed storage accounts
1 parent 9ec840e commit c98279e

File tree

5 files changed

+78
-3
lines changed

5 files changed

+78
-3
lines changed

src/ResourceManager/KeyVault/Commands.KeyVault/Commands/ManagedStorageAccounts/RemoveAzureKeyVaultManagedStorageAccount.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System.Management.Automation;
1818
using KeyVaultProperties = Microsoft.Azure.Commands.KeyVault.Properties;
1919
using Microsoft.Azure.Commands.KeyVault.Models.ManagedStorageAccounts;
20+
using Microsoft.Azure.Commands.KeyVault.Properties;
2021

2122
namespace Microsoft.Azure.Commands.KeyVault
2223
{
@@ -43,6 +44,13 @@ public class RemoveAzureKeyVaultManagedStorageAccount : KeyVaultCmdletBase
4344
[Alias( Constants.StorageAccountName, Constants.Name )]
4445
public string AccountName { get; set; }
4546

47+
/// <summary>
48+
/// If present, operate on the deleted entity.
49+
/// </summary>
50+
[Parameter(Mandatory = false,
51+
HelpMessage = "Permanently remove the previously deleted managed storage account.")]
52+
public SwitchParameter InRemovedState { get; set; }
53+
4654
/// <summary>
4755
/// If present, do not ask for confirmation
4856
/// </summary>
@@ -58,6 +66,24 @@ public class RemoveAzureKeyVaultManagedStorageAccount : KeyVaultCmdletBase
5866

5967
public override void ExecuteCmdlet()
6068
{
69+
if (InRemovedState.IsPresent)
70+
{
71+
ConfirmAction(
72+
Force.IsPresent,
73+
string.Format(
74+
CultureInfo.InvariantCulture,
75+
Resources.RemoveDeletedManagedStorageAccountWarning,
76+
AccountName),
77+
string.Format(
78+
CultureInfo.InvariantCulture,
79+
Resources.RemoveDeletedManagedStorageAccountWhatIfMessage,
80+
AccountName),
81+
AccountName,
82+
() => { DataServiceClient.PurgeManagedStorageAccount(VaultName, AccountName); });
83+
84+
return;
85+
}
86+
6187
PSDeletedKeyVaultManagedStorageAccount managedManagedStorageAccount = null;
6288
ConfirmAction(
6389
Force.IsPresent,

src/ResourceManager/KeyVault/Commands.KeyVault/Commands/RemoveAzureKeyVaultCertificate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public class RemoveAzureKeyVaultCertificate : KeyVaultCmdletBase
6969
public PSKeyVaultCertificateIdentityItem InputObject { get; set; }
7070

7171
/// <summary>
72-
/// If present, operate on the deleted key entity.
72+
/// If present, operate on the deleted entity.
7373
/// </summary>
7474
[Parameter(Mandatory = false,
7575
HelpMessage = "Permanently remove the previously deleted certificate.")]

src/ResourceManager/KeyVault/Commands.KeyVault/Properties/Resources.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/KeyVault/Commands.KeyVault/Properties/Resources.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,4 +474,10 @@ You can find the object ID using Azure Active Directory Module for Windows Power
474474
<data name="RecoverManagedStorageSasDefinition" xml:space="preserve">
475475
<value>Recover KeyVault-managed storage account SAS definition.</value>
476476
</data>
477+
<data name="RemoveDeletedManagedStorageAccountWarning" xml:space="preserve">
478+
<value>Are you sure you want to purge managed storage account '{0}'</value>
479+
</data>
480+
<data name="RemoveDeletedManagedStorageAccountWhatIfMessage" xml:space="preserve">
481+
<value>Purge managed storage account</value>
482+
</data>
477483
</root>

src/ResourceManager/KeyVault/Commands.KeyVault/help/Remove-AzureKeyVaultManagedStorageAccount.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Removes a Key Vault managed Azure Storage Account and all associated SAS definit
1313
## SYNTAX
1414

1515
```
16-
Remove-AzureKeyVaultManagedStorageAccount [-VaultName] <String> [-AccountName] <String> [-Force] [-PassThru]
17-
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
16+
Remove-AzureKeyVaultManagedStorageAccount [-VaultName] <String> [-AccountName] <String> [-InRemovedState]
17+
[-Force] [-PassThru] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
1818
```
1919

2020
## DESCRIPTION
@@ -36,6 +36,18 @@ PS C:\> Remove-AzureKeyVaultManagedStorageAccount -VaultName 'myvault' -AccountN
3636

3737
Disassociates Azure Storage Account 'mystorageaccount' from Key Vault 'myvault' and stops Key Vault from managing its keys. The account 'mystorageaccount' will not be removed. All Key Vault managed Storage SAS definitions associated with this account will be removed.
3838

39+
### Example 3: Permanently delete (purge) a Key Vault managed Azure Storage Account and all associated SAS definitions from a soft-delete-enabled vault.
40+
```
41+
PS C:\> Remove-AzureKeyVaultManagedStorageAccount -VaultName 'myvault' -AccountName 'mystorageaccount'
42+
PS C:\> Get-AzureKeyVaultManagedStorageAccount -VaultName 'myvault' -AccountName 'mystorageaccount' -InRemovedState
43+
PS C:\> Remove-AzureKeyVaultManagedStorageAccount -VaultName 'myvault' -AccountName 'mystorageaccount' -InRemovedState
44+
```
45+
46+
The example assumes that soft-delete is enabled for this vault. Verify whether that is the case by examining the vault properties, or the RecoveryLevel attribute of an entity in the vault.
47+
The first cmdlet disassociates Azure Storage Account 'mystorageaccount' from Key Vault 'myvault' and stops Key Vault from managing its keys. The account 'mystorageaccount' will not be removed. All Key Vault managed Storage SAS definitions associated with this account will be removed.
48+
The second cmdlet verifies that the storage account is in a deleted, but recoverable state. Reaching this state may require some time, please allow ~30s before attempting.
49+
The third cmdlet permanently removes the storage account - recovery will no longer be possible.
50+
3951
## PARAMETERS
4052

4153
### -AccountName
@@ -83,6 +95,19 @@ Accept pipeline input: False
8395
Accept wildcard characters: False
8496
```
8597
98+
### -InRemovedState
99+
Permanently remove the previously deleted managed storage account.```yaml
100+
Type: SwitchParameter
101+
Parameter Sets: (All)
102+
Aliases:
103+
104+
Required: False
105+
Position: Named
106+
Default value: None
107+
Accept pipeline input: False
108+
Accept wildcard characters: False
109+
```
110+
86111
### -PassThru
87112
Cmdlet does not return an object by default.
88113
If this switch is specified, cmdlet returns the managed storage account that was deleted.

0 commit comments

Comments
 (0)