question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Can not set PrefixMatch on ManagementPolicyFilter

See original GitHub issue

Describe the bug Can not set PrefixMatch on ManagementPolicyFilter

Expected behavior Able to set PrefixMatch on ManagementPolicyFilter, either via construction or public property

Actual behavior (include Exception or Stack Trace) What is the actual behavior? Not able to set PrefixMatch on ManagementPolicyFilter, either via construction or public property. Please refer to following source code

public class ManagementPolicyFilter : IUtf8JsonSerializable
{
 public ManagementPolicyFilter(IEnumerable<string> blobTypes);
 public IList<string> PrefixMatch { get; }
}

To Reproduce Steps to reproduce the behavior (include a code snippet, screenshot, or any additional information that might help us reproduce the issue)

Use following code to create ManagementPolicyRule instance, failed can not set PrefixMatch

    var rules = new List<ManagementPolicyRule>();
    var rule1 = new ManagementPolicyRule("DeleteLongerThan24Hours", RuleType.Lifecycle, 
        new ManagementPolicyDefinition(new ManagementPolicyAction {BaseBlob = new ManagementPolicyBaseBlob(){ Delete =new DateAfterModification(1)},})
        {
            Filters = new ManagementPolicyFilter(new List<string> { "blockBlob" })
            {
                PrefixMatch = new List<string> { "upload" }
            }
        });
    rules.Add(rule1);

Environment:

  • Name and version of the Library package used: [e.g. Azure.Storage.Blobs 12.2.0] azure.resourcemanager.storage 1.0.0-preview.2
  • Hosting platform or OS and .NET runtime version (dotnet --info output for .NET Core projects): [e.g. Azure AppService or Windows 10 .NET Framework 4.8] Windows 10, DotNet Core
  • IDE and version : [e.g. Visual Studio 16.3] VS version does not matter

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ArcturusZhangcommented, Dec 27, 2021

Hi @blrchen please try this:

    var rules = new List<ManagementPolicyRule>();
    var rule1 = new ManagementPolicyRule("DeleteLongerThan24Hours", RuleType.Lifecycle, 
        new ManagementPolicyDefinition(new ManagementPolicyAction {BaseBlob = new ManagementPolicyBaseBlob(){ Delete =new DateAfterModification(1)},})
        {
            Filters = new ManagementPolicyFilter(new List<string> { "blockBlob" })
            {
                PrefixMatch = { "upload" }
            }
        });
    rules.Add(rule1);

Please note since the property PrefixMatch is unassignable, you cannot construct a new list and assign to that property. The SDK will initialize this property with a built-in List type, and the fact of no-setter could ensure you cannot change the list to another instance. The usage above is a C# grammar sugar of the collection initialization, check out more information here: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/object-and-collection-initializers#object-initializers-with-collection-read-only-property-initialization

0reactions
blrchencommented, Dec 27, 2021

This works, thanks man.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating Azure Lifecycle Management rules from C# - ...
Is there a way to create Lifecycle Management rules for an Azure Storage Account directly from C#?. I know how to do it...
Read more >
armstorage
GetProperties - Returns the properties for the specified storage account including but not limited to name, SKU name, location, and account ...
Read more >
Azure blob Storage Life Cycle Management not working ...
Based on the provided lifecycle rule configuration, it appears that the rule is set up correctly. However, there are a few factors to...
Read more >
Azure storage deletion policy does not work
All blobs to be deleted in the container. I do not have any extra folders in that container. So with prefixMatch = queryresults...
Read more >
Optimize costs by automatically managing the data lifecycle
Use Azure Storage lifecycle management policies to create automated rules for moving data between hot, cool, cold, and archive tiers.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found