Пример #1
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));
            }
        }
Пример #2
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));
                }
            }
        }
Пример #3
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));
            }
        }
Пример #4
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));
            }
        }