Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -784,13 +784,6 @@ function Test-UpdateKeyVault {
$vault = $originVault | Update-AzKeyVault -EnablePurgeProtection
Assert-True { $vault.EnableSoftDelete } "3. EnableSoftDelete should be true"
Assert-True { $vault.EnablePurgeProtection } "3. EnablePurgeProtection should be true"
Assert-True { $vault.SoftDeleteRetentionInDays -eq $originVault.SoftDeleteRetentionInDays }

# # Only enable purge protection (TODO: uncomment this assert after keyvault team deploys their fix)
# $vault = New-AzKeyVault -VaultName (getAssetName) -ResourceGroupName $resourceGroupName -Location $vaultLocation
# Assert-Throws { $vault = $vault | Update-AzKeyVault -EnablePurgeProtection }
# # Retention cannot be updated once set
# Assert-Throws { $vault = $vault | Update-AzKeyVault -SoftDeleteRetentionInDays 80}

#Set EnableRbacAuthorization true
$vault = $vault | Update-AzKeyVault -EnableRbacAuthorization $true
Expand Down
9 changes: 8 additions & 1 deletion src/KeyVault/KeyVault/Commands/UpdateAzureKeyVault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public class UpdateTopLevelResourceCommand : KeyVaultManagementCmdletBase
[Parameter(Mandatory = false, HelpMessage = "Enable or disable this key vault to authorize data actions by Role Based Access Control (RBAC).")]
public bool? EnableRbacAuthorization { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Specifies how long deleted resources are retained, and how long until a vault or an object in the deleted state can be purged. The default is " + Constants.DefaultSoftDeleteRetentionDaysString + " days.")]
[ValidateRange(Constants.MinSoftDeleteRetentionDays, Constants.MaxSoftDeleteRetentionDays)]
[ValidateNotNullOrEmpty]
public int SoftDeleteRetentionInDays { get; set; }

public override void ExecuteCmdlet()
{
if (this.IsParameterBound(c => c.InputObject))
Expand Down Expand Up @@ -96,7 +101,9 @@ public override void ExecuteCmdlet()
null,
EnablePurgeProtection.IsPresent ? (true as bool?) : null,
EnableRbacAuthorization,
null,
this.IsParameterBound(c => c.SoftDeleteRetentionInDays)
? (SoftDeleteRetentionInDays as int?)
: (existingResource.SoftDeleteRetentionInDays ?? Constants.DefaultSoftDeleteRetentionDays),
existingResource.NetworkAcls
);

Expand Down
32 changes: 28 additions & 4 deletions src/KeyVault/KeyVault/help/Update-AzKeyVault.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,36 @@ Update the state of an Azure key vault.
### UpdateByNameParameterSet (Default)
```
Update-AzKeyVault -ResourceGroupName <String> -VaultName <String> [-EnablePurgeProtection]
[-EnableRbacAuthorization <Boolean>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
[<CommonParameters>]
[-EnableRbacAuthorization <Boolean>] [-SoftDeleteRetentionInDays <Int32>]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### UpdateByInputObjectParameterSet
```
Update-AzKeyVault -InputObject <PSKeyVault> [-EnablePurgeProtection] [-EnableRbacAuthorization <Boolean>]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
[-SoftDeleteRetentionInDays <Int32>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
[<CommonParameters>]
```

### UpdateByResourceIdParameterSet
```
Update-AzKeyVault -ResourceId <String> [-EnablePurgeProtection] [-EnableRbacAuthorization <Boolean>]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
[-SoftDeleteRetentionInDays <Int32>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
[<CommonParameters>]
```

## DESCRIPTION
This cmdlet updates the state of an Azure key vault.

## EXAMPLES

### Example 1
```powershell
PS C:\> Update-AzKeyVault -VaultName $keyVaultName -ResourceGroupName $resourceGroupName -SoftDeleteRetentionInDays 45
```

Change the days to retain deleted vault to 45.

### Example 2
```powershell
PS C:\> Get-AzKeyVault -VaultName $keyVaultName -ResourceGroupName $resourceGroupName | Update-AzKeyVault -EnablePurgeProtection
Expand Down Expand Up @@ -137,6 +146,21 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -SoftDeleteRetentionInDays
Specifies how long deleted resources are retained, and how long until a vault or an object in the deleted state can be purged. The default is 90 days.

```yaml
Type: System.Int32
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -VaultName
Name of the key vault.

Expand Down