示例#1
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            var isSingleObjectDelete = this.ParameterSetName == ParamSet_WithKey;

            var context = new CmdletContext
            {
                BucketName = this.BucketName
            };

            string resourceIdentifiersText;

            if (isSingleObjectDelete)
            {
                resourceIdentifiersText = context.Key;

                context.Key       = AmazonS3Helper.CleanKey(this.Key);
                context.VersionId = this.VersionId;
            }
            else
            {
                resourceIdentifiersText = FormatParameterValuesForConfirmationMsg("KeyCollection", MyInvocation.BoundParameters);

                if (this.KeyCollection != null && this.KeyCollection.Length > 0)
                {
                    context.KeyCollection = new List <string>(this.KeyCollection);
                }
                if (this.KeyAndVersionCollection != null && this.KeyAndVersionCollection.Length > 0)
                {
                    context.KeyAndVersionCollection = new List <KeyVersion>(this.KeyAndVersionCollection);
                }
                if (this.InputObject != null && this.InputObject.Length > 0)
                {
                    context.S3ObjectCollection = new List <S3Object>(this.InputObject);
                }

                if (this.ReportErrorsOnly.IsPresent)
                {
                    context.Quiet = true;
                }
            }

            if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Remove-S3Object (DeleteObjects)"))
            {
                return;
            }

            context.SerialNumber        = this.SerialNumber;
            context.AuthenticationValue = this.AuthenticationValue;

            var output = Execute(context) as CmdletOutput;

            ProcessOutput(output);
        }
        protected override void PostExecutionContextLoad(ExecutorContext context)
        {
            var cmdletContext = context as CmdletContext;

            if (this.Key != null)
            {
                this.Key             = AmazonS3Helper.CleanKey(this.Key);
                cmdletContext.Prefix = this.Key;
            }
            else
            {
                cmdletContext.Prefix = rootIndicators.Contains <string>(this.Prefix, StringComparer.OrdinalIgnoreCase)
                    ? null : AmazonS3Helper.CleanKey(this.Prefix);
            }
        }
        protected override void PostExecutionContextLoad(ExecutorContext context)
        {
            var cmdletContext = context as CmdletContext;

            cmdletContext.Key = AmazonS3Helper.CleanKey(this.Key);

            if (string.IsNullOrEmpty(this.CannedACL))
            {
#pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute
                if (this.PublicReadOnly.IsPresent)
                {
                    cmdletContext.CannedACL = S3CannedACL.PublicRead;
                }
                else if (this.PublicReadWrite.IsPresent)
                {
                    cmdletContext.CannedACL = S3CannedACL.PublicReadWrite;
                }
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
            }
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            if (!ConfirmShouldProceed(this.Force.IsPresent, this.BucketName, "Write-S3Object (PutObject)"))
            {
                return;
            }

            var context = new CmdletContext
            {
                BucketName = this.BucketName
            };

            if (this.Key != null)
            {
                context.Key = AmazonS3Helper.CleanKey(this.Key);
            }

            if (this.ParameterSetName == ParamSet_FromLocalFile)
            {
                context.File = PSHelpers.PSPathToAbsolute(this.SessionState.Path, this.File.Trim());
                if (string.IsNullOrEmpty(context.Key))
                {
                    context.Key = Path.GetFileName(context.File);
                }
            }
            else if (this.ParameterSetName == ParamSet_FromStream)
            {
                context.Stream = this.Stream;
            }
            else if (this.ParameterSetName == ParamSet_FromContent)
            {
                context.Content = this.Content;
            }
            else
            {
                context.Folder            = PSHelpers.PSPathToAbsolute(this.SessionState.Path, this.Folder.Trim());
                context.Recurse           = this.Recurse.IsPresent;
                context.OriginalKeyPrefix = this.KeyPrefix;
                if (!rootIndicators.Contains <string>(this.KeyPrefix, StringComparer.OrdinalIgnoreCase))
                {
                    context.KeyPrefix = AmazonS3Helper.CleanKey(this.KeyPrefix);
                }
                if (!string.IsNullOrEmpty(this.SearchPattern))
                {
                    context.SearchPattern = this.SearchPattern;
                }
            }

            if (!string.IsNullOrEmpty(this.CannedACLName))
            {
                context.CannedACL = this.CannedACLName;
            }
            else if (this.PublicReadOnly.IsPresent)
            {
                context.CannedACL = S3CannedACL.PublicRead;
            }
            else if (this.PublicReadWrite.IsPresent)
            {
                context.CannedACL = S3CannedACL.PublicReadWrite;
            }

            context.ContentType = this.ContentType;

            if (ParameterWasBound("StorageClass"))
            {
                context.StorageClass = this.StorageClass;
            }
            else
            {
                if (this.StandardStorage.IsPresent)
                {
                    context.StorageClass = S3StorageClass.Standard;
                }
                else if (this.ReducedRedundancyStorage.IsPresent)
                {
                    context.StorageClass = S3StorageClass.ReducedRedundancy;
                }
            }

            if (!string.IsNullOrEmpty(this.ServerSideEncryption))
            {
                context.ServerSideEncryptionMethod = AmazonS3Helper.Convert(this.ServerSideEncryption);
            }

            if (!string.IsNullOrEmpty(this.ServerSideEncryptionCustomerMethod))
            {
                context.ServerSideEncryptionCustomerMethod = this.ServerSideEncryptionCustomerMethod;
            }

            context.ServerSideEncryptionCustomerProvidedKey       = this.ServerSideEncryptionCustomerProvidedKey;
            context.ServerSideEncryptionCustomerProvidedKeyMD5    = this.ServerSideEncryptionCustomerProvidedKeyMD5;
            context.ServerSideEncryptionKeyManagementServiceKeyId = this.ServerSideEncryptionKeyManagementServiceKeyId;

            if (this.ConcurrentServiceRequest.HasValue)
            {
                if (this.ConcurrentServiceRequest.Value <= 0)
                {
                    throw new ArgumentOutOfRangeException("ConcurrentServiceRequests",
                                                          "ConcurrentServiceRequests should be set to a positive integer value.");
                }

                context.ConcurrentServiceRequests = this.ConcurrentServiceRequest.Value;
            }

            context.Metadata = this.Metadata;
            context.Headers  = this.HeaderCollection;
            context.TagSet   = this.TagSet;

            var output = Execute(context) as CmdletOutput;

            ProcessOutput(output);
        }
示例#5
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            var context = new CmdletContext
            {
                BucketName = this.BucketName
            };

            switch (this.ParameterSetName)
            {
            case ParamSet_ToLocalFile:
            {
                context.Key     = AmazonS3Helper.CleanKey(this.Key);
                context.File    = PSHelpers.PSPathToAbsolute(this.SessionState.Path, this.File);
                context.Version = this.Version;
            }
            break;

            case ParamSet_ToLocalFolder:
            {
                context.OriginalKeyPrefix = this.KeyPrefix;
                context.KeyPrefix         = rootIndicators.Contains <string>(this.KeyPrefix, StringComparer.OrdinalIgnoreCase)
                            ? "/" : AmazonS3Helper.CleanKey(this.KeyPrefix);
                context.Folder = PSHelpers.PSPathToAbsolute(this.SessionState.Path, this.Folder);
            }
            break;

            case ParamSet_FromS3Object:
            {
                context.BucketName = this.S3Object.BucketName;
                context.Key        = this.S3Object.Key;
                var s3ObjectVersion = this.S3Object as S3ObjectVersion;
                context.Version = s3ObjectVersion == null ? null : s3ObjectVersion.VersionId;

                if (this.ParameterWasBound("File"))
                {
                    context.File = PSHelpers.PSPathToAbsolute(this.SessionState.Path, this.File);
                }
                else
                {
                    var path = PSHelpers.PSPathToAbsolute(this.SessionState.Path, this.Folder);
                    context.File = Path.Combine(path, S3Object.Key);
                }
            }
            break;
            }

            if (ParameterWasBound("UtcModifiedSinceDate"))
            {
                context.UtcModifiedSinceDate = this.UtcModifiedSinceDate;
            }
            if (ParameterWasBound("UtcUnmodifiedSinceDate"))
            {
                context.UtcUnmodifiedSinceDate = this.UtcUnmodifiedSinceDate;
            }
#pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute
            if (ParameterWasBound("ModifiedSinceDate"))
            {
                context.ModifiedSinceDate = this.ModifiedSinceDate;
            }
            if (ParameterWasBound("UnmodifiedSinceDate"))
            {
                context.UnmodifiedSinceDate = this.UnmodifiedSinceDate;
            }
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute

            if (ParameterWasBound("ServerSideEncryptionCustomerMethod"))
            {
                context.ServerSideEncryptionCustomerMethod = this.ServerSideEncryptionCustomerMethod;
            }

            context.ServerSideEncryptionCustomerProvidedKey    = this.ServerSideEncryptionCustomerProvidedKey;
            context.ServerSideEncryptionCustomerProvidedKeyMD5 = this.ServerSideEncryptionCustomerProvidedKeyMD5;

            var output = Execute(context) as CmdletOutput;
            ProcessOutput(output);
        }