Skip to content

Commit

Permalink
[Storage] Supported BaseBlob DaysAfterCreationGreaterThan in Manageme…
Browse files Browse the repository at this point in the history
…nt Policy (#18561)
  • Loading branch information
blueww authored Jun 17, 2022
1 parent 5fe28a3 commit 52ef681
Show file tree
Hide file tree
Showing 8 changed files with 325 additions and 231 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ function Test-StorageAccountManagementPolicy
Assert-AreEqual $kind $sto.Kind;

# create Rule1
$action1 = Add-AzStorageAccountManagementPolicyAction -BaseBlobAction Delete -daysAfterModificationGreaterThan 100
$action1 = Add-AzStorageAccountManagementPolicyAction -BaseBlobAction Delete -DaysAfterCreationGreaterThan 100
$action1 = Add-AzStorageAccountManagementPolicyAction -InputObject $action1 -BaseBlobAction TierToArchive -daysAfterModificationGreaterThan 50 -DaysAfterLastTierChangeGreaterThan 40
$action1 = Add-AzStorageAccountManagementPolicyAction -InputObject $action1 -BaseBlobAction TierToCool -daysAfterModificationGreaterThan 30
$action1 = Add-AzStorageAccountManagementPolicyAction -InputObject $action1 -SnapshotAction Delete -daysAfterCreationGreaterThan 100
Expand All @@ -1084,7 +1084,7 @@ function Test-StorageAccountManagementPolicy
Assert-AreEqual 3 $policy.Rules.Count
Assert-AreEqual $rule1.Enabled $policy.Rules[0].Enabled
Assert-AreEqual $rule1.Name $policy.Rules[0].Name
Assert-AreEqual $rule1.Definition.Actions.BaseBlob.Delete.DaysAfterModificationGreaterThan $policy.Rules[0].Definition.Actions.BaseBlob.Delete.DaysAfterModificationGreaterThan
Assert-AreEqual $rule1.Definition.Actions.BaseBlob.Delete.DaysAfterCreationGreaterThan $policy.Rules[0].Definition.Actions.BaseBlob.Delete.DaysAfterCreationGreaterThan
Assert-AreEqual $rule1.Definition.Actions.BaseBlob.TierToArchive.DaysAfterModificationGreaterThan $policy.Rules[0].Definition.Actions.BaseBlob.TierToArchive.DaysAfterModificationGreaterThan
Assert-AreEqual $rule1.Definition.Actions.BaseBlob.TierToArchive.DaysAfterLastTierChangeGreaterThan $policy.Rules[0].Definition.Actions.BaseBlob.TierToArchive.DaysAfterLastTierChangeGreaterThan
Assert-AreEqual $rule1.Definition.Actions.BaseBlob.TierToCool.DaysAfterModificationGreaterThan $policy.Rules[0].Definition.Actions.BaseBlob.TierToCool.DaysAfterModificationGreaterThan
Expand Down Expand Up @@ -1120,7 +1120,7 @@ function Test-StorageAccountManagementPolicy
Assert-AreEqual 3 $policy.Rules.Count
Assert-AreEqual $rule1.Enabled $policy.Rules[0].Enabled
Assert-AreEqual $rule1.Name $policy.Rules[0].Name
Assert-AreEqual $rule1.Definition.Actions.BaseBlob.Delete.DaysAfterModificationGreaterThan $policy.Rules[0].Definition.Actions.BaseBlob.Delete.DaysAfterModificationGreaterThan
Assert-AreEqual $rule1.Definition.Actions.BaseBlob.Delete.DaysAfterCreationGreaterThan $policy.Rules[0].Definition.Actions.BaseBlob.Delete.DaysAfterCreationGreaterThan
Assert-AreEqual $rule1.Definition.Actions.BaseBlob.TierToArchive.DaysAfterModificationGreaterThan $policy.Rules[0].Definition.Actions.BaseBlob.TierToArchive.DaysAfterModificationGreaterThan
Assert-AreEqual $rule1.Definition.Actions.BaseBlob.TierToArchive.DaysAfterLastTierChangeGreaterThan $policy.Rules[0].Definition.Actions.BaseBlob.TierToArchive.DaysAfterLastTierChangeGreaterThan
Assert-AreEqual $rule1.Definition.Actions.BaseBlob.TierToCool.DaysAfterModificationGreaterThan $policy.Rules[0].Definition.Actions.BaseBlob.TierToCool.DaysAfterModificationGreaterThan
Expand Down Expand Up @@ -1160,7 +1160,7 @@ function Test-StorageAccountManagementPolicy
Assert-AreEqual 3 $policy.Rules.Count
Assert-AreEqual $rule1.Enabled $policy.Rules[0].Enabled
Assert-AreEqual $rule1.Name $policy.Rules[0].Name
Assert-AreEqual $rule1.Definition.Actions.BaseBlob.Delete.DaysAfterModificationGreaterThan $policy.Rules[0].Definition.Actions.BaseBlob.Delete.DaysAfterModificationGreaterThan
Assert-AreEqual $rule1.Definition.Actions.BaseBlob.Delete.DaysAfterCreationGreaterThan $policy.Rules[0].Definition.Actions.BaseBlob.Delete.DaysAfterCreationGreaterThan
Assert-AreEqual $rule1.Definition.Actions.BaseBlob.TierToArchive.DaysAfterModificationGreaterThan $policy.Rules[0].Definition.Actions.BaseBlob.TierToArchive.DaysAfterModificationGreaterThan
Assert-AreEqual $rule1.Definition.Actions.BaseBlob.TierToArchive.DaysAfterLastTierChangeGreaterThan $policy.Rules[0].Definition.Actions.BaseBlob.TierToArchive.DaysAfterLastTierChangeGreaterThan
Assert-AreEqual $rule1.Definition.Actions.BaseBlob.TierToCool.DaysAfterModificationGreaterThan $policy.Rules[0].Definition.Actions.BaseBlob.TierToCool.DaysAfterModificationGreaterThan
Expand Down

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/Storage/Storage.Management/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
- Additional information about change #1
-->
## Upcoming Release
* Supported BaseBlob DaysAfterCreationGreaterThan in Management Policy
- `Add-AzStorageAccountManagementPolicyAction`

## Version 4.6.0
* Supported generate Sas token for DataLakeGen2
Expand Down
22 changes: 21 additions & 1 deletion src/Storage/Storage.Management/Models/PSDataPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ public class PSDateAfterModification
{
public int? DaysAfterModificationGreaterThan { get; set; }
public int? DaysAfterLastAccessTimeGreaterThan { get; set; }
public int? DaysAfterCreationGreaterThan { get; set; }
public int? DaysAfterLastTierChangeGreaterThan { get; set; }

public PSDateAfterModification()
Expand Down Expand Up @@ -331,6 +332,14 @@ public PSDateAfterModification(int? daysAfterModificationGreaterThan, int? daysA
this.DaysAfterLastTierChangeGreaterThan = DaysAfterLastTierChangeGreaterThan;
}

public PSDateAfterModification(int? daysAfterModificationGreaterThan, int? daysAfterLastAccessTimeGreaterThan, int? DaysAfterLastTierChangeGreaterThan, int? DaysAfterCreationGreaterThan)
{
this.DaysAfterModificationGreaterThan = daysAfterModificationGreaterThan;
this.DaysAfterLastAccessTimeGreaterThan = daysAfterLastAccessTimeGreaterThan;
this.DaysAfterLastTierChangeGreaterThan = DaysAfterLastTierChangeGreaterThan;
this.DaysAfterCreationGreaterThan = DaysAfterCreationGreaterThan;
}

public PSDateAfterModification(DateAfterModification data)
{
if (data.DaysAfterModificationGreaterThan is null)
Expand All @@ -357,10 +366,21 @@ public PSDateAfterModification(DateAfterModification data)
{
this.DaysAfterLastTierChangeGreaterThan = Convert.ToInt32(data.DaysAfterLastTierChangeGreaterThan);
}
if (data.DaysAfterCreationGreaterThan is null)
{
this.DaysAfterCreationGreaterThan = null;
}
else
{
this.DaysAfterCreationGreaterThan = Convert.ToInt32(data.DaysAfterCreationGreaterThan);
}
}
public DateAfterModification ParseDateAfterModification()
{
return new DateAfterModification(this.DaysAfterModificationGreaterThan, this.DaysAfterLastAccessTimeGreaterThan, this.DaysAfterLastTierChangeGreaterThan);
return new DateAfterModification(this.DaysAfterModificationGreaterThan,
this.DaysAfterLastAccessTimeGreaterThan,
this.DaysAfterLastTierChangeGreaterThan,
this.DaysAfterCreationGreaterThan);
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/Storage/Storage.Management/Storage.Management.format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@
<ScriptBlock>$_.BaseBlob.TierToCool.DaysAfterLastAccessTimeGreaterThan</ScriptBlock>
<Label>BaseBlob.TierToCool.DaysAfterLastAccessTimeGreaterThan</Label>
</ListItem>
<ListItem>
<ScriptBlock>$_.BaseBlob.TierToCool.DaysAfterCreationGreaterThan</ScriptBlock>
<Label>BaseBlob.TierToCool.DaysAfterCreationGreaterThan</Label>
</ListItem>
<ListItem>
<ScriptBlock>$_.BaseBlob.EnableAutoTierToHotFromCool</ScriptBlock>
<Label>BaseBlob.EnableAutoTierToHotFromCool</Label>
Expand All @@ -275,6 +279,10 @@
<ScriptBlock>$_.BaseBlob.TierToArchive.DaysAfterLastAccessTimeGreaterThan</ScriptBlock>
<Label>BaseBlob.TierToArchive.DaysAfterLastAccessTimeGreaterThan</Label>
</ListItem>
<ListItem>
<ScriptBlock>$_.BaseBlob.TierToArchive.DaysAfterCreationGreaterThan</ScriptBlock>
<Label>BaseBlob.TierToArchive.DaysAfterCreationGreaterThan</Label>
</ListItem>
<ListItem>
<ScriptBlock>$_.BaseBlob.TierToArchive.DaysAfterLastTierChangeGreaterThan</ScriptBlock>
<Label>BaseBlob.TierToArchive.DaysAfterLastTierChangeGreaterThan</Label>
Expand All @@ -287,6 +295,10 @@
<ScriptBlock>$_.BaseBlob.Delete.DaysAfterLastAccessTimeGreaterThan</ScriptBlock>
<Label>BaseBlob.Delete.DaysAfterLastAccessTimeGreaterThan</Label>
</ListItem>
<ListItem>
<ScriptBlock>$_.BaseBlob.Delete.DaysAfterCreationGreaterThan</ScriptBlock>
<Label>BaseBlob.Delete.DaysAfterCreationGreaterThan</Label>
</ListItem>
<ListItem>
<ScriptBlock>$_.Snapshot.TierToCool.DaysAfterCreationGreaterThan</ScriptBlock>
<Label>Snapshot.TierToCool.DaysAfterCreationGreaterThan</Label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class AddAzureStorageAccountManagementPolicyActionCommand : StorageAccoun
{
protected const string BaseBlobParameterSet = "BaseBlob";
protected const string BaseBlobLastAccessTimeParameterSet = "BaseBlobLastAccessTime";
protected const string BaseBlobCreationTimeParameterSet = "BaseBlobCreationTime";
protected const string SnapshotParameterSet = "Snapshot";
protected const string BlobVersionParameterSet = "BlobVersion";
[Parameter(Mandatory = true,
Expand All @@ -35,6 +36,9 @@ public class AddAzureStorageAccountManagementPolicyActionCommand : StorageAccoun
[Parameter(Mandatory = true,
HelpMessage = "The management policy action for baseblob.",
ParameterSetName = BaseBlobLastAccessTimeParameterSet)]
[Parameter(Mandatory = true,
HelpMessage = "The management policy action for baseblob.",
ParameterSetName = BaseBlobCreationTimeParameterSet)]
[ValidateSet(ManagementPolicyAction.Delete,
ManagementPolicyAction.TierToArchive,
ManagementPolicyAction.TierToCool,
Expand Down Expand Up @@ -65,8 +69,22 @@ public class AddAzureStorageAccountManagementPolicyActionCommand : StorageAccoun
[Parameter(Mandatory = true,
HelpMessage = "Integer value indicating the age in days after creation.",
ParameterSetName = BlobVersionParameterSet)]
[Parameter(Mandatory = true,
HelpMessage = "Integer value indicating the age in days after creation.",
ParameterSetName = BaseBlobCreationTimeParameterSet)]
[ValidateNotNullOrEmpty]
public int DaysAfterCreationGreaterThan { get; set; }
public int DaysAfterCreationGreaterThan
{
get
{
return daysAfterCreationGreaterThan is null ? 0 : daysAfterCreationGreaterThan.Value;
}
set
{
daysAfterCreationGreaterThan = value;
}
}
public int? daysAfterCreationGreaterThan;

[Parameter(Mandatory = true,
HelpMessage = "Integer value indicating the age in days after last modification.",
Expand Down Expand Up @@ -149,6 +167,7 @@ public override void ExecuteCmdlet()
{
case BaseBlobParameterSet:
case BaseBlobLastAccessTimeParameterSet:
case BaseBlobCreationTimeParameterSet:
if (action.BaseBlob is null)
{
action.BaseBlob = new PSManagementPolicyBaseBlob();
Expand All @@ -172,17 +191,20 @@ public override void ExecuteCmdlet()
case ManagementPolicyAction.Delete:
action.BaseBlob.Delete = new PSDateAfterModification(this.daysAfterModificationGreaterThan,
this.daysAfterLastAccessTimeGreaterThan,
this.daysAfterLastTierChangeGreaterThan);
this.daysAfterLastTierChangeGreaterThan,
this.daysAfterCreationGreaterThan);
break;
case ManagementPolicyAction.TierToCool:
action.BaseBlob.TierToCool = new PSDateAfterModification(this.daysAfterModificationGreaterThan,
this.daysAfterLastAccessTimeGreaterThan,
this.daysAfterLastTierChangeGreaterThan);
this.daysAfterLastTierChangeGreaterThan,
this.daysAfterCreationGreaterThan);
break;
case ManagementPolicyAction.TierToArchive:
action.BaseBlob.TierToArchive = new PSDateAfterModification(this.daysAfterModificationGreaterThan,
this.daysAfterLastAccessTimeGreaterThan,
this.daysAfterLastTierChangeGreaterThan);
this.daysAfterLastTierChangeGreaterThan,
this.daysAfterCreationGreaterThan);
break;
default:
throw new PSArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid BaseBlobAction: {0}", this.BaseBlobAction));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,23 @@ The **Add-AzStorageAccountManagementPolicyAction** cmdlet adds an action to the

### Example 1: Creates a ManagementPolicy Action Group object with 4 actions, then add it to a management policy rule and set to a Storage account
```
PS C:\>$action = Add-AzStorageAccountManagementPolicyAction -BaseBlobAction Delete -daysAfterModificationGreaterThan 100
PS C:\>$action = Add-AzStorageAccountManagementPolicyAction -BaseBlobAction Delete -DaysAfterCreationGreaterThan 100
PS C:\>$action = Add-AzStorageAccountManagementPolicyAction -BaseBlobAction TierToArchive -daysAfterModificationGreaterThan 50 -DaysAfterLastTierChangeGreaterThan 40 -InputObject $action
PS C:\>$action = Add-AzStorageAccountManagementPolicyAction -BaseBlobAction TierToCool -DaysAfterLastAccessTimeGreaterThan 30 -EnableAutoTierToHotFromCool -InputObject $action
PS C:\>$action = Add-AzStorageAccountManagementPolicyAction -SnapshotAction Delete -daysAfterCreationGreaterThan 100 -InputObject $action
PS C:\>$action
BaseBlob.TierToCool.DaysAfterModificationGreaterThan :
BaseBlob.TierToCool.DaysAfterLastAccessTimeGreaterThan : 30
BaseBlob.TierToCool.DaysAfterCreationGreaterThan :
BaseBlob.EnableAutoTierToHotFromCool : True
BaseBlob.TierToArchive.DaysAfterModificationGreaterThan : 50
BaseBlob.TierToArchive.DaysAfterLastAccessTimeGreaterThan :
BaseBlob.TierToArchive.DaysAfterCreationGreaterThan :
BaseBlob.TierToArchive.DaysAfterLastTierChangeGreaterThan : 40
BaseBlob.Delete.DaysAfterModificationGreaterThan : 100
BaseBlob.Delete.DaysAfterModificationGreaterThan :
BaseBlob.Delete.DaysAfterLastAccessTimeGreaterThan :
BaseBlob.Delete.DaysAfterCreationGreaterThan : 100
Snapshot.TierToCool.DaysAfterCreationGreaterThan :
Snapshot.TierToArchive.DaysAfterCreationGreaterThan :
Snapshot.TierToArchive.DaysAfterLastTierChangeGreaterThan :
Expand Down Expand Up @@ -95,10 +98,15 @@ PS C:\> $action
BaseBlob.TierToCool.DaysAfterModificationGreaterThan :
BaseBlob.TierToCool.DaysAfterLastAccessTimeGreaterThan :
BaseBlob.TierToCool.DaysAfterCreationGreaterThan :
BaseBlob.EnableAutoTierToHotFromCool :
BaseBlob.TierToArchive.DaysAfterModificationGreaterThan :
BaseBlob.TierToArchive.DaysAfterLastAccessTimeGreaterThan :
BaseBlob.TierToArchive.DaysAfterCreationGreaterThan :
BaseBlob.TierToArchive.DaysAfterLastTierChangeGreaterThan :
BaseBlob.Delete.DaysAfterModificationGreaterThan :
BaseBlob.Delete.DaysAfterLastAccessTimeGreaterThan :
BaseBlob.Delete.DaysAfterCreationGreaterThan :
Snapshot.TierToCool.DaysAfterCreationGreaterThan : 60
Snapshot.TierToArchive.DaysAfterCreationGreaterThan : 50
Snapshot.TierToArchive.DaysAfterLastTierChangeGreaterThan :
Expand Down
Loading

0 comments on commit 52ef681

Please sign in to comment.