Example #1
0
        public ManagementPolicyRule ParseManagementPolicyRule()
        {
            ManagementPolicyRule rule = new ManagementPolicyRule();

            rule.Enabled    = this.Enabled;
            rule.Name       = this.Name;
            rule.Definition = this.Definition is null ? null : this.Definition.ParseManagementPolicyDefination();
            return(rule);
        }
        public void It_has_a_constructor_that_takes_an_IdmResource_without_Creator()
        {
            var resource = new IdmResource
            {
                DisplayName = "My Display Name",
            };
            var it = new ManagementPolicyRule(resource);

            Assert.AreEqual("My Display Name", it.DisplayName);
            Assert.IsNull(it.Creator);
        }
        public void It_has_a_constructor_that_takes_an_IdmResource()
        {
            var resource = new IdmResource
            {
                DisplayName = "My Display Name",
                Creator     = new Person {
                    DisplayName = "Creator Display Name", ObjectID = "Creator ObjectID"
                },
            };
            var it = new ManagementPolicyRule(resource);

            Assert.AreEqual("ManagementPolicyRule", it.ObjectType);
            Assert.AreEqual("My Display Name", it.DisplayName);
            Assert.AreEqual("Creator Display Name", it.Creator.DisplayName);
        }
Example #4
0
        public PolicyRule.Update.IUpdate UpdateRule(string name)
        {
            ManagementPolicyRule ruleToUpdate = null;

            foreach (ManagementPolicyRule rule in this.Inner.Policy.Rules)
            {
                if (rule.Name.Equals(name))
                {
                    ruleToUpdate = rule;
                }
            }
            if (ruleToUpdate == null)
            {
                throw new NotSupportedException("There is no rule that exists with the name " + name + ". Please define a rule with this name before updating.");
            }
            return(new PolicyRuleImpl(ruleToUpdate, this));
        }
Example #5
0
        public ManagementPolicy.Update.IUpdate WithoutRule(string name)
        {
            ManagementPolicyRule ruleToDelete = null;

            foreach (ManagementPolicyRule rule in this.Inner.Policy.Rules)
            {
                if (rule.Name.Equals(name))
                {
                    ruleToDelete = rule;
                }
            }
            if (ruleToDelete == null)
            {
                throw new NotSupportedException("There is no rule that exists with the name " + name + " so this rule can not be deleted.");
            }
            List <ManagementPolicyRule> currentRules = this.upolicy.Rules as List <ManagementPolicyRule>;

            currentRules.Remove(ruleToDelete);
            this.upolicy.Rules = currentRules;
            return(this);
        }
Example #6
0
 public PSManagementPolicyRule(ManagementPolicyRule rule)
 {
     this.Enabled    = rule.Enabled;
     this.Name       = rule.Name;
     this.Definition = rule.Definition is null ? null : new PSManagementPolicyDefinition(rule.Definition);
 }
 public ManagementPolicyRuleTests()
 {
     _it = new ManagementPolicyRule();
 }
        public void It_has_a_constructor_that_takes_an_IdmResource_without_Creator()
        {
            var resource = new IdmResource
            {
                DisplayName = "My Display Name",
            };
            var it = new ManagementPolicyRule(resource);

            Assert.AreEqual("My Display Name", it.DisplayName);
            Assert.IsNull(it.Creator);
        }
        public void It_has_a_constructor_that_takes_an_IdmResource()
        {
            var resource = new IdmResource
            {
                DisplayName = "My Display Name",
                Creator = new Person { DisplayName = "Creator Display Name", ObjectID = "Creator ObjectID"},
            };
            var it = new ManagementPolicyRule(resource);

            Assert.AreEqual("ManagementPolicyRule", it.ObjectType);
            Assert.AreEqual("My Display Name", it.DisplayName);
            Assert.AreEqual("Creator Display Name", it.Creator.DisplayName);
        }
 public ManagementPolicyRuleTests()
 {
     _it = new ManagementPolicyRule();
 }
Example #11
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();
        }