Exemple #1
0
        public void UpdateContainer_allParameter()
        {
            if (isResourceMode)
            {
                string containerName = Utility.GenNameString("container");

                Hashtable metadata = new Hashtable(2);
                metadata.Add("key1", "value1");
                metadata.Add("key2", "value2");
                // metadata.Add("key3", "value3");

                //Creat container
                Test.Assert(CommandAgent.NewAzureRmStorageContainer(resourceGroupName, accountName, containerName), "Create Container should success.");
                PSContainer con = GetContainer(containerName);
                ValidateContainer(con, resourceGroupName, accountName, containerName);

                //Set Container
                Test.Assert(CommandAgent.UpdateAzureRmStorageContainer(resourceGroupName, accountName, containerName, metadata, PSPublicAccess.Blob), "Update Container should success.");
                con = GetContainer(containerName);
                ValidateContainer(con, resourceGroupName, accountName, containerName, metadata, PSPublicAccess.Blob);


                //Set Container
                Test.Assert(CommandAgent.UpdateAzureRmStorageContainer(resourceGroupName, accountName, containerName, new Hashtable(), PSPublicAccess.None), "Update Container should success.");
                con = GetContainer(containerName);
                ValidateContainer(con, resourceGroupName, accountName, containerName);

                //Remove Container
                Test.Assert(CommandAgent.RemoveAzureRmStorageContainer(resourceGroupName, accountName, containerName), "Remove Container should success.");
            }
        }
Exemple #2
0
        public void ListContainer()
        {
            if (isResourceMode)
            {
                string containerName = Utility.GenNameString("container");


                PSContainer[] cons1 = ListContainersFromServer();

                //Creat container
                Test.Assert(CommandAgent.NewAzureRmStorageContainer(resourceGroupName, accountName, containerName, PublicAccess: PSPublicAccess.Container), "Create Container should success.");
                PSContainer con = GetContainer(containerName);
                ValidateContainer(con, resourceGroupName, accountName, containerName, publicaccess: PSPublicAccess.Container);

                //get Container
                PSContainer[] cons2 = ListContainersFromServer();
                Test.AssertEqual(cons1.Length + 1, cons2.Length);

                //Remove Container
                Test.Assert(CommandAgent.RemoveAzureRmStorageContainer(resourceGroupName, accountName, containerName), "Remove Container should success.");


                //get Container
                cons2 = ListContainersFromServer();
                Test.AssertEqual(cons1.Length, cons2.Length);
            }
        }
Exemple #3
0
 public static void ValidateContainer(PSContainer container, string resourceGroupName, string accoutName, string containerName, Hashtable metadata = null, PSPublicAccess?publicaccess = PSPublicAccess.None)
 {
     Test.AssertEqual(containerName, container.Name);
     Test.AssertEqual(resourceGroupName, container.ResourceGroupName);
     Test.AssertEqual(accountName, container.StorageAccountName);
     Test.AssertEqual(publicaccess.ToString(), container.PublicAccess == null ? PSPublicAccess.None.ToString() : container.PublicAccess.ToString());
     accountUtils.ValidateTags(metadata == null ? null : new Hashtable[] { metadata }, container.Metadata);
 }
Exemple #4
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            if (ShouldProcess(this.ContainerName, "Set container ImmutabilityPolicy"))
            {
                switch (ParameterSetName)
                {
                case ContainerObjectParameterSet:
                case ExtendContainerObjectParameterSet:
                    this.ResourceGroupName  = Container.ResourceGroupName;
                    this.StorageAccountName = Container.StorageAccountName;
                    this.ContainerName      = Container.Name;
                    break;

                case AccountObjectParameterSet:
                case ExtendAccountObjectParameterSet:
                    this.ResourceGroupName  = StorageAccount.ResourceGroupName;
                    this.StorageAccountName = StorageAccount.StorageAccountName;
                    break;

                case ImmutabilityPolicyObjectParameterSet:
                case ExtendImmutabilityPolicyObjectParameterSet:
                    this.ResourceGroupName  = PSContainer.ParseResourceGroupFromId(InputObject.Id);
                    this.StorageAccountName = PSContainer.ParseStorageAccountNameFromId(InputObject.Id);
                    this.ContainerName      = PSContainer.ParseStorageContainerNameFromId(InputObject.Id);
                    this.Etag = InputObject.Etag;
                    break;

                default:
                    break;
                }

                ImmutabilityPolicy policy;
                if (!ExtendPolicy.IsPresent)
                {
                    policy = this.StorageClient.BlobContainers.CreateOrUpdateImmutabilityPolicy(
                        this.ResourceGroupName,
                        this.StorageAccountName,
                        this.ContainerName,
                        new ImmutabilityPolicy(
                            immutabilityPeriodSinceCreationInDays: immutabilityPeriod,
                            allowProtectedAppendWrites: this.allowProtectedAppendWrite),
                        this.Etag);
                }
                else
                {
                    policy = this.StorageClient.BlobContainers.ExtendImmutabilityPolicy(
                        this.ResourceGroupName,
                        this.StorageAccountName,
                        this.ContainerName,
                        this.Etag,
                        new ImmutabilityPolicy(
                            immutabilityPeriodSinceCreationInDays: immutabilityPeriod));
                }
                WriteObject(new PSImmutabilityPolicy(policy));
            }
        }
Exemple #5
0
        public void ImmutabilityPolicy_LockExtend()
        {
            if (isResourceMode)
            {
                string containerName = Utility.GenNameString("container");

                int immutabilityPeriod = 5;

                //Creat container
                Test.Assert(CommandAgent.NewAzureRmStorageContainer(resourceGroupName, accountName, containerName, PublicAccess: PSPublicAccess.None), "Create Container should success.");
                PSContainer con = GetContainer(containerName);
                ValidateContainer(con, resourceGroupName, accountName, containerName, publicaccess: PSPublicAccess.None);

                //Set ImmutabilityPolicy
                Test.Assert(CommandAgent.SetAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName, immutabilityPeriod), "Set Container ImmutabilityPolicy should success.");
                PSImmutabilityPolicy immuPolicy = GetImmutabilityPolicyFromOutput();
                ValidateImmutabilityPolicy(immuPolicy, immutabilityPeriod, "Unlocked");

                //Lock ImmutabilityPolicy
                Test.Assert(CommandAgent.LockAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName, immuPolicy.Etag), "Lock Container ImmutabilityPolicy should success.");
                immuPolicy = GetImmutabilityPolicyFromOutput();
                ValidateImmutabilityPolicy(immuPolicy, immutabilityPeriod, "Locked");

                //Get ImmutabilityPolicy
                Test.Assert(CommandAgent.GetAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName), "Get Container ImmutabilityPolicy should success.");
                immuPolicy = GetImmutabilityPolicyFromOutput();
                ValidateImmutabilityPolicy(immuPolicy, immutabilityPeriod, "Locked");

                //Set ImmutabilityPolicy fail
                Test.Assert(!CommandAgent.SetAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName, 2, Etag: immuPolicy.Etag), "Set Container ImmutabilityPolicy should fail.");
                ExpectedContainErrorMessage(string.Format("Operation not allowed on immutability policy with current state."));

                //Extend ImmutabilityPolicy
                immutabilityPeriod = 10;
                Test.Assert(CommandAgent.SetAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName, immutabilityPeriod, extendPolicy: true, Etag: immuPolicy.Etag), "Extend Container ImmutabilityPolicy should success.");
                immuPolicy = GetImmutabilityPolicyFromOutput();
                ValidateImmutabilityPolicy(immuPolicy, immutabilityPeriod, "Locked");

                //Get ImmutabilityPolicy
                Test.Assert(CommandAgent.GetAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName), "Get Container ImmutabilityPolicy should success.");
                immuPolicy = GetImmutabilityPolicyFromOutput();
                ValidateImmutabilityPolicy(immuPolicy, immutabilityPeriod, "Locked");

                //Remove ImmutabilityPolicy fail
                Test.Assert(!CommandAgent.RemoveAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName, immuPolicy.Etag), "Remove Container ImmutabilityPolicy should fail.");
                ExpectedContainErrorMessage(string.Format("Operation not allowed on immutability policy with current state."));

                //Remove Container
                Test.Assert(CommandAgent.RemoveAzureRmStorageContainer(resourceGroupName, accountName, containerName), "Remove Container should success.");
            }
        }
Exemple #6
0
        public void CreateContainer_allParameter()
        {
            if (isResourceMode)
            {
                string containerName = Utility.GenNameString("container");
                //Hashtable[] metadata = StorageAccountTest.GetUnicodeTags();
                Hashtable metadata = new Hashtable(2);
                metadata.Add("key1", "value1");
                metadata.Add("key2", "value2");
                //metadata.Add("key3", "value3");

                Test.Assert(CommandAgent.NewAzureRmStorageContainer(resourceGroupName, accountName, containerName, metadata, PublicAccess: PSPublicAccess.Container), "Create Container should success.");
                PSContainer con = GetContainer(containerName);
                ValidateContainer(con, resourceGroupName, accountName, containerName, metadata, PSPublicAccess.Container);

                CommandAgent.RemoveAzureRmStorageContainer(resourceGroupName, accountName, containerName);
            }
        }
Exemple #7
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            if (ShouldProcess(this.ContainerName, "Lock ImmutabilityPolicy"))
            {
                switch (ParameterSetName)
                {
                case ContainerObjectParameterSet:
                    this.ResourceGroupName  = Container.ResourceGroupName;
                    this.StorageAccountName = Container.StorageAccountName;
                    this.ContainerName      = Container.Name;
                    break;

                case AccountObjectParameterSet:
                    this.ResourceGroupName  = StorageAccount.ResourceGroupName;
                    this.StorageAccountName = StorageAccount.StorageAccountName;
                    break;

                case ImmutabilityPolicyObjectParameterSet:
                    this.ResourceGroupName  = PSContainer.ParseResourceGroupFromId(InputObject.Id);
                    this.StorageAccountName = PSContainer.ParseStorageAccountNameFromId(InputObject.Id);
                    this.ContainerName      = PSContainer.ParseStorageContainerNameFromId(InputObject.Id);
                    this.Etag = InputObject.Etag;
                    break;

                default:
                    break;
                }

                if (Force || ShouldContinue(string.Format("Lock ImmutabilityPolicy in container '{0}' with Etag {1}", this.ContainerName, this.Etag), ""))
                {
                    ImmutabilityPolicy policy = this.StorageClient.BlobContainers.LockImmutabilityPolicy(
                        this.ResourceGroupName,
                        this.StorageAccountName,
                        this.ContainerName,
                        this.Etag);

                    WriteObject(new PSImmutabilityPolicy(policy));
                }
            }
        }
Exemple #8
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            if (ShouldProcess(this.ContainerName, "Remove ImmutabilityPolicy"))
            {
                switch (ParameterSetName)
                {
                case ContainerObjectParameterSet:
                    this.ResourceGroupName  = Container.ResourceGroupName;
                    this.StorageAccountName = Container.StorageAccountName;
                    this.ContainerName      = Container.Name;
                    break;

                case AccountObjectParameterSet:
                    this.ResourceGroupName  = StorageAccount.ResourceGroupName;
                    this.StorageAccountName = StorageAccount.StorageAccountName;
                    break;

                case ImmutabilityPolicyObjectParameterSet:
                    this.ResourceGroupName  = PSContainer.ParseResourceGroupFromId(InputObject.Id);
                    this.StorageAccountName = PSContainer.ParseStorageAccountNameFromId(InputObject.Id);
                    this.ContainerName      = PSContainer.ParseStorageContainerNameFromId(InputObject.Id);
                    this.Etag = InputObject.Etag;
                    break;

                default:
                    break;
                }

                ImmutabilityPolicy policy = this.StorageClient.BlobContainers.DeleteImmutabilityPolicy(
                    this.ResourceGroupName,
                    this.StorageAccountName,
                    this.ContainerName,
                    this.Etag);

                WriteObject(new PSImmutabilityPolicy(policy));
            }
        }
Exemple #9
0
        public void ImmutabilityPolicy_SetGetDelete()
        {
            if (isResourceMode)
            {
                string containerName = Utility.GenNameString("container");

                int immutabilityPeriod = 3;

                //Creat container
                Test.Assert(CommandAgent.NewAzureRmStorageContainer(resourceGroupName, accountName, containerName, PublicAccess: PSPublicAccess.Blob), "Create Container should success.");
                PSContainer con = GetContainer(containerName);
                ValidateContainer(con, resourceGroupName, accountName, containerName, publicaccess: PSPublicAccess.Blob);

                //Get ImmutabilityPolicy
                Test.Assert(CommandAgent.GetAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName), "Get Container ImmutabilityPolicy should success.");
                PSImmutabilityPolicy immuPolicy = GetImmutabilityPolicyFromOutput();
                ValidateImmutabilityPolicy(immuPolicy, 0, "Unlocked");

                //Set ImmutabilityPolicy
                Test.Assert(CommandAgent.SetAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName, immutabilityPeriod), "Set Container ImmutabilityPolicy should success.");
                immuPolicy = GetImmutabilityPolicyFromOutput();
                ValidateImmutabilityPolicy(immuPolicy, immutabilityPeriod, "Unlocked");

                //Get ImmutabilityPolicy
                Test.Assert(CommandAgent.GetAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName), "Get Container ImmutabilityPolicy should success.");
                immuPolicy = GetImmutabilityPolicyFromOutput();
                ValidateImmutabilityPolicy(immuPolicy, immutabilityPeriod, "Unlocked");

                //Remove ImmutabilityPolicy
                Test.Assert(CommandAgent.RemoveAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName, immuPolicy.Etag), "Remove Container ImmutabilityPolicy should success.");
                Test.Assert(CommandAgent.GetAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName), "Get Container ImmutabilityPolicy should success.");
                immuPolicy = GetImmutabilityPolicyFromOutput();
                ValidateImmutabilityPolicy(immuPolicy, 0, "Deleted");

                //Remove Container
                Test.Assert(CommandAgent.RemoveAzureRmStorageContainer(resourceGroupName, accountName, containerName), "Remove Container should success.");
            }
        }
Exemple #10
0
        public void LegalHoldTest()
        {
            if (isResourceMode)
            {
                string containerName = Utility.GenNameString("container");

                string[] legalhold        = new string[] { "tag1", "tag2", "tag3", "tag4" };
                string[] legalhold2Remove = new string[] { "tag2", "tag3" };
                string[] legalholdLeft    = new string[] { "tag1", "tag4" };

                //Creat container
                Test.Assert(CommandAgent.NewAzureRmStorageContainer(resourceGroupName, accountName, containerName, PublicAccess: PSPublicAccess.Container), "Create Container should success.");
                PSContainer con = GetContainer(containerName);
                ValidateContainer(con, resourceGroupName, accountName, containerName, publicaccess: PSPublicAccess.Container);

                //Add Container LegalHold
                Test.Assert(CommandAgent.AddAzureRmStorageContainerLegalHold(resourceGroupName, accountName, containerName, legalhold), "Add Container LegalHold should success.");
                PSLegalHold outputLegalhold = GetLegalholdFromOutput();
                CompareLegalhold(legalhold, outputLegalhold);

                //Remove Container LegalHold
                Test.Assert(CommandAgent.RemoveAzureRmStorageContainerLegalHold(resourceGroupName, accountName, containerName, legalhold2Remove), "Remove Container LegalHold should success.");
                outputLegalhold = GetLegalholdFromOutput();
                CompareLegalhold(legalholdLeft, outputLegalhold);

                //Remove Container fail when legalhold exist
                Test.Assert(!CommandAgent.RemoveAzureRmStorageContainer(resourceGroupName, accountName, containerName), "Remove Container with legalhold should fail.");
                ExpectedContainErrorMessage(string.Format("The storage account {0} container {1} is protected from deletion due to LegalHold.", accountName, containerName));

                //Remove Container LegalHold
                Test.Assert(CommandAgent.RemoveAzureRmStorageContainerLegalHold(resourceGroupName, accountName, containerName, legalholdLeft), "Remove Container LegalHold should success.");
                outputLegalhold = GetLegalholdFromOutput();
                CompareLegalhold(null, outputLegalhold);

                //Remove container
                Test.Assert(CommandAgent.RemoveAzureRmStorageContainer(resourceGroupName, accountName, containerName), "Remove Container should success.");
            }
        }
Exemple #11
0
        public void GetContainer_withLegalHoldAndImmutabilityPolicy()
        {
            if (isResourceMode)
            {
                string containerName = Utility.GenNameString("container");

                //Creat container
                Test.Assert((CommandAgent as PowerShellAgent).InvokePSScript(
                                string.Format("Get-AzureRMStorageAccount -ResourceGroupName {0} -Name {1} | New-AzureRmStorageContainer -ContainerName {2}",
                                              resourceGroupName,
                                              accountName,
                                              containerName)),
                            string.Format("Create container for storage account {0} in the resource group {1} should success.", accountName, resourceGroupName));
                PSContainer con = GetContainerFromServer(containerName);
                ValidateContainer(con, resourceGroupName, accountName, containerName, publicaccess: PSPublicAccess.None);

                //Set ImmutabilityPolicy
                int immutabilityPeriod = 5;
                Test.Assert((CommandAgent as PowerShellAgent).InvokePSScript(
                                string.Format("Get-AzureRMStorageAccount -ResourceGroupName {0} -Name {1} | Set-AzureRmStorageContainerImmutabilityPolicy -ContainerName {2} -ImmutabilityPeriod {3}",
                                              resourceGroupName,
                                              accountName,
                                              containerName,
                                              immutabilityPeriod)),
                            string.Format("Set Container ImmutabilityPolicy should success."));
                Test.Assert(CommandAgent.GetAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName), "Get Container ImmutabilityPolicy should success.");
                PSImmutabilityPolicy immuPolicy = GetImmutabilityPolicyFromOutput();
                ValidateImmutabilityPolicy(immuPolicy, immutabilityPeriod, "Unlocked");

                //Lock ImmutabilityPolicy
                Test.Assert((CommandAgent as PowerShellAgent).InvokePSScript(
                                string.Format("Get-AzureRmStorageContainer -ResourceGroupName {0} -StorageAccountName {1} -Name {2} | Lock-AzureRmStorageContainerImmutabilityPolicy -Etag '{3}' -Force",
                                              resourceGroupName,
                                              accountName,
                                              containerName,
                                              immuPolicy.Etag)),
                            string.Format("Lock Container ImmutabilityPolicy should success."));
                Test.Assert(CommandAgent.GetAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName), "Get Container ImmutabilityPolicy should success.");
                immuPolicy = GetImmutabilityPolicyFromOutput();
                ValidateImmutabilityPolicy(immuPolicy, immutabilityPeriod, "Locked");

                //Extend ImmutabilityPolicy
                int immutabilityPeriod2 = 10;
                Test.Assert((CommandAgent as PowerShellAgent).InvokePSScript(
                                string.Format("Get-AzureRmStorageContainerImmutabilityPolicy -ResourceGroupName {0} -StorageAccountName {1} -ContainerName {2} | Set-AzureRmStorageContainerImmutabilityPolicy -ImmutabilityPeriod {3} -ExtendPolicy",
                                              resourceGroupName,
                                              accountName,
                                              containerName,
                                              immutabilityPeriod2)),
                            string.Format("Extend Container ImmutabilityPolicy should success."));
                Test.Assert(CommandAgent.GetAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName), "Get Container ImmutabilityPolicy should success.");
                immuPolicy = GetImmutabilityPolicyFromOutput();
                ValidateImmutabilityPolicy(immuPolicy, immutabilityPeriod2, "Locked");

                //Add Container LegalHold
                string[] legalhold = new string[] { "legalholdtag1", "legalholdtag2" };
                Test.Assert(CommandAgent.AddAzureRmStorageContainerLegalHold(resourceGroupName, accountName, containerName, legalhold), "Add Container LegalHold should success.");
                PSLegalHold outputLegalhold = GetLegalholdFromOutput();
                CompareLegalhold(legalhold, outputLegalhold);

                //get Container and validate legalhold, ImmutabilityPolicy
                con = GetContainerFromServer(containerName);
                ValidateContainer(con, resourceGroupName, accountName, containerName, publicaccess: PSPublicAccess.None);
                Test.Assert(con.HasImmutabilityPolicy.Value, "Should has HasImmutabilityPolicy = true");
                Test.Assert(con.HasLegalHold.Value, "Should has HasLegalHold = true");

                Test.AssertEqual(immutabilityPeriod2, con.ImmutabilityPolicy.ImmutabilityPeriodSinceCreationInDays);
                Test.AssertEqual("Locked", con.ImmutabilityPolicy.State);
                Test.AssertEqual(3, con.ImmutabilityPolicy.UpdateHistory.Length);
                Test.AssertEqual("put", con.ImmutabilityPolicy.UpdateHistory[0].Update);
                Test.AssertEqual(immutabilityPeriod, con.ImmutabilityPolicy.UpdateHistory[0].ImmutabilityPeriodSinceCreationInDays.Value);
                Test.AssertEqual("lock", con.ImmutabilityPolicy.UpdateHistory[1].Update);
                Test.AssertEqual(immutabilityPeriod, con.ImmutabilityPolicy.UpdateHistory[1].ImmutabilityPeriodSinceCreationInDays.Value);
                Test.AssertEqual("extend", con.ImmutabilityPolicy.UpdateHistory[2].Update);
                Test.AssertEqual(immutabilityPeriod2, con.ImmutabilityPolicy.UpdateHistory[2].ImmutabilityPeriodSinceCreationInDays.Value);

                Test.AssertEqual(legalhold.Length, con.LegalHold.Tags.Length);
                if (legalhold.Length == con.LegalHold.Tags.Length)
                {
                    for (int i = 0; i < legalhold.Length; i++)
                    {
                        Test.AssertEqual(legalhold[i], con.LegalHold.Tags[i].Tag);
                    }
                }

                //Remove Legalhold and Container
                //Test.Assert(CommandAgent.RemoveAzureRmStorageContainerLegalHold(resourceGroupName, accountName, containerName, legalhold), "Remove Container LegalHold should success.");
                Test.Assert((CommandAgent as PowerShellAgent).InvokePSScript(
                                string.Format("Get-AzureRMStorageAccount -ResourceGroupName {0} -Name {1} | Remove-AzureRmStorageContainerLegalHold -Name {2} -Tag {3}",
                                              resourceGroupName,
                                              accountName,
                                              containerName,
                                              legalhold[0] + "," + legalhold[1])),
                            string.Format("Remove Container LegalHold should success."));
                //outputLegalhold = GetLegalholdFromOutput();
                //CompareLegalhold(null, outputLegalhold);


                //Test.Assert(CommandAgent.RemoveAzureRmStorageContainer(resourceGroupName, accountName, containerName), "Remove Container should success.");
                Test.Assert((CommandAgent as PowerShellAgent).InvokePSScript(
                                string.Format("Get-AzureRmStorageContainer -ResourceGroupName {0} -StorageAccountName {1} -Name {2} | Remove-AzureRmStorageContainer -Force",
                                              resourceGroupName,
                                              accountName,
                                              containerName)),
                            string.Format("Remove Container should success."));
            }
        }
Exemple #12
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            if ((this.allowProtectedAppendWrite.HasValue && this.allowProtectedAppendWrite.Value) &&
                (this.allowProtectedAppendWriteAll.HasValue && this.allowProtectedAppendWriteAll.Value))
            {
                throw new ArgumentException("'-AllowProtectedAppendWrites' and '-AllowProtectedAppendWritesAll' are mutually exclusive. They can't be set both to true.");
            }
            if (ShouldProcess(this.ContainerName, "Set container ImmutabilityPolicy"))
            {
                switch (ParameterSetName)
                {
                case ContainerObjectParameterSet:
                case ExtendContainerObjectParameterSet:
                    this.ResourceGroupName  = Container.ResourceGroupName;
                    this.StorageAccountName = Container.StorageAccountName;
                    this.ContainerName      = Container.Name;
                    break;

                case AccountObjectParameterSet:
                case ExtendAccountObjectParameterSet:
                    this.ResourceGroupName  = StorageAccount.ResourceGroupName;
                    this.StorageAccountName = StorageAccount.StorageAccountName;
                    break;

                case ImmutabilityPolicyObjectParameterSet:
                case ExtendImmutabilityPolicyObjectParameterSet:
                    this.ResourceGroupName  = PSContainer.ParseResourceGroupFromId(InputObject.Id);
                    this.StorageAccountName = PSContainer.ParseStorageAccountNameFromId(InputObject.Id);
                    this.ContainerName      = PSContainer.ParseStorageContainerNameFromId(InputObject.Id);
                    this.Etag = InputObject.Etag;
                    break;

                default:
                    break;
                }

                ImmutabilityPolicy policy;
                if (!ExtendPolicy.IsPresent)
                {
                    policy = this.StorageClient.BlobContainers.CreateOrUpdateImmutabilityPolicy(
                        this.ResourceGroupName,
                        this.StorageAccountName,
                        this.ContainerName,
                        new ImmutabilityPolicy(
                            immutabilityPeriodSinceCreationInDays: immutabilityPeriod,
                            allowProtectedAppendWrites: this.allowProtectedAppendWrite,
                            allowProtectedAppendWritesAll: this.allowProtectedAppendWriteAll),
                        this.Etag);
                }
                else
                {
                    policy = this.StorageClient.BlobContainers.ExtendImmutabilityPolicy(
                        this.ResourceGroupName,
                        this.StorageAccountName,
                        this.ContainerName,
                        this.Etag,
                        new ImmutabilityPolicy(
                            immutabilityPeriodSinceCreationInDays: immutabilityPeriod));
                }
                WriteObject(new PSImmutabilityPolicy(policy));
            }
        }