コード例 #1
0
 public PSManagementPolicyDefinition(ManagementPolicyDefinition defination)
 {
     this.Actions = defination.Actions is null ? null : new PSManagementPolicyActionGroup(defination.Actions);
     this.Filters = defination.Filters is null ? null : new PSManagementPolicyRuleFilter(defination.Filters);
 }
コード例 #2
0
        public async Task SetGetDeleteManagementPolicy()
        {
            //create resource group and storage account
            string accountName = await CreateValidAccountNameAsync(namePrefix);

            _resourceGroup = await CreateResourceGroupAsync();

            StorageAccountContainer        storageAccountContainer = _resourceGroup.GetStorageAccounts();
            StorageAccountCreateParameters parameters           = GetDefaultStorageAccountParameters(kind: Kind.StorageV2);
            StorageAccount            account                   = (await storageAccountContainer.CreateOrUpdateAsync(accountName, parameters)).Value;
            ManagementPolicyContainer managementPolicyContainer = account.GetManagementPolicies();

            //Enable LAT
            BlobServiceContainer blobServiceContainer = account.GetBlobServices();
            BlobService          blobService          = await blobServiceContainer.GetAsync("Default");

            blobService.Data.LastAccessTimeTrackingPolicy = new LastAccessTimeTrackingPolicy(true);
            _ = await blobService.SetServicePropertiesAsync(blobService.Data);

            // create ManagementPolicy to set, the type of policy rule should always be Lifecycle
            List <ManagementPolicyRule> rules  = new List <ManagementPolicyRule>();
            ManagementPolicyAction      action = new ManagementPolicyAction()
            {
                BaseBlob = new ManagementPolicyBaseBlob()
                {
                    Delete = new DateAfterModification(1000, null)
                }
            };
            ManagementPolicyDefinition definition1 = new ManagementPolicyDefinition(action)
            {
                Filters = new ManagementPolicyFilter(blobTypes: new List <string>()
                {
                    "blockBlob", "appendBlob"
                }),
            };
            ManagementPolicyRule rule1 = new ManagementPolicyRule("rule1", "Lifecycle", definition1);

            rules.Add(rule1);

            ManagementPolicyDefinition definition2 = new ManagementPolicyDefinition(action)
            {
                Filters = new ManagementPolicyFilter(blobTypes: new List <string>()
                {
                    "appendBlob"
                }),
            };
            ManagementPolicyRule rule2 = new ManagementPolicyRule("rule2", "Lifecycle", definition2);

            rules.Add(rule2);

            ManagementPolicyDefinition definition3 = new ManagementPolicyDefinition(action)
            {
                Filters = new ManagementPolicyFilter(blobTypes: new List <string>()
                {
                    "blockBlob"
                }),
            };
            ManagementPolicyRule rule3 = new ManagementPolicyRule("rule3", "Lifecycle", definition3);

            rules.Add(rule3);

            ManagementPolicyData parameter = new ManagementPolicyData()
            {
                Policy = new ManagementPolicySchema(rules)
            };

            //set management policy, the policy name should always be default
            ManagementPolicy managementPolicy = (await managementPolicyContainer.CreateOrUpdateAsync("default", parameter)).Value;

            Assert.NotNull(managementPolicy);
            Assert.AreEqual(managementPolicy.Data.Policy.Rules.Count, 3);

            //delete namagement policy
            await managementPolicy.DeleteAsync();
        }