1
mirror of https://github.com/rclone/rclone synced 2024-12-23 14:23:44 +01:00

s3: add requester pays option - fixes #301

This commit is contained in:
kelv 2020-12-03 10:30:06 +08:00 committed by Nick Craig-Wood
parent c8cfa43ccc
commit 9e87f5090f

View File

@ -868,6 +868,12 @@ isn't set then "acl" is used instead.`,
Value: "authenticated-read", Value: "authenticated-read",
Help: "Owner gets FULL_CONTROL. The AuthenticatedUsers group gets READ access.", Help: "Owner gets FULL_CONTROL. The AuthenticatedUsers group gets READ access.",
}}, }},
}, {
Name: "requester_pays",
Help: "Enables requester pays option when interacting with S3 bucket.",
Provider: "AWS",
Default: false,
Advanced: true,
}, { }, {
Name: "server_side_encryption", Name: "server_side_encryption",
Help: "The server-side encryption algorithm used when storing this object in S3.", Help: "The server-side encryption algorithm used when storing this object in S3.",
@ -1253,6 +1259,7 @@ type Options struct {
LocationConstraint string `config:"location_constraint"` LocationConstraint string `config:"location_constraint"`
ACL string `config:"acl"` ACL string `config:"acl"`
BucketACL string `config:"bucket_acl"` BucketACL string `config:"bucket_acl"`
RequesterPays bool `config:"requester_pays"`
ServerSideEncryption string `config:"server_side_encryption"` ServerSideEncryption string `config:"server_side_encryption"`
SSEKMSKeyID string `config:"sse_kms_key_id"` SSEKMSKeyID string `config:"sse_kms_key_id"`
SSECustomerAlgorithm string `config:"sse_customer_algorithm"` SSECustomerAlgorithm string `config:"sse_customer_algorithm"`
@ -1794,6 +1801,9 @@ func (f *Fs) list(ctx context.Context, bucket, directory, prefix string, addBuck
if urlEncodeListings { if urlEncodeListings {
req.EncodingType = aws.String(s3.EncodingTypeUrl) req.EncodingType = aws.String(s3.EncodingTypeUrl)
} }
if f.opt.RequesterPays {
req.RequestPayer = aws.String(s3.RequestPayerRequester)
}
var resp *s3.ListObjectsOutput var resp *s3.ListObjectsOutput
var err error var err error
err = f.pacer.Call(func() (bool, error) { err = f.pacer.Call(func() (bool, error) {
@ -2169,6 +2179,9 @@ func (f *Fs) copy(ctx context.Context, req *s3.CopyObjectInput, dstBucket, dstPa
req.Key = &dstPath req.Key = &dstPath
source := pathEscape(path.Join(srcBucket, srcPath)) source := pathEscape(path.Join(srcBucket, srcPath))
req.CopySource = &source req.CopySource = &source
if f.opt.RequesterPays {
req.RequestPayer = aws.String(s3.RequestPayerRequester)
}
if f.opt.ServerSideEncryption != "" { if f.opt.ServerSideEncryption != "" {
req.ServerSideEncryption = &f.opt.ServerSideEncryption req.ServerSideEncryption = &f.opt.ServerSideEncryption
} }
@ -2740,6 +2753,9 @@ func (o *Object) headObject(ctx context.Context) (resp *s3.HeadObjectOutput, err
Bucket: &bucket, Bucket: &bucket,
Key: &bucketPath, Key: &bucketPath,
} }
if o.fs.opt.RequesterPays {
req.RequestPayer = aws.String(s3.RequestPayerRequester)
}
if o.fs.opt.SSECustomerAlgorithm != "" { if o.fs.opt.SSECustomerAlgorithm != "" {
req.SSECustomerAlgorithm = &o.fs.opt.SSECustomerAlgorithm req.SSECustomerAlgorithm = &o.fs.opt.SSECustomerAlgorithm
} }
@ -2858,6 +2874,9 @@ func (o *Object) SetModTime(ctx context.Context, modTime time.Time) error {
Metadata: o.meta, Metadata: o.meta,
MetadataDirective: aws.String(s3.MetadataDirectiveReplace), // replace metadata with that passed in MetadataDirective: aws.String(s3.MetadataDirectiveReplace), // replace metadata with that passed in
} }
if o.fs.opt.RequesterPays {
req.RequestPayer = aws.String(s3.RequestPayerRequester)
}
return o.fs.copy(ctx, &req, bucket, bucketPath, bucket, bucketPath, o) return o.fs.copy(ctx, &req, bucket, bucketPath, bucket, bucketPath, o)
} }
@ -2873,6 +2892,9 @@ func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.Read
Bucket: &bucket, Bucket: &bucket,
Key: &bucketPath, Key: &bucketPath,
} }
if o.fs.opt.RequesterPays {
req.RequestPayer = aws.String(s3.RequestPayerRequester)
}
if o.fs.opt.SSECustomerAlgorithm != "" { if o.fs.opt.SSECustomerAlgorithm != "" {
req.SSECustomerAlgorithm = &o.fs.opt.SSECustomerAlgorithm req.SSECustomerAlgorithm = &o.fs.opt.SSECustomerAlgorithm
} }
@ -3157,6 +3179,9 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
if md5sum != "" { if md5sum != "" {
req.ContentMD5 = &md5sum req.ContentMD5 = &md5sum
} }
if o.fs.opt.RequesterPays {
req.RequestPayer = aws.String(s3.RequestPayerRequester)
}
if o.fs.opt.ServerSideEncryption != "" { if o.fs.opt.ServerSideEncryption != "" {
req.ServerSideEncryption = &o.fs.opt.ServerSideEncryption req.ServerSideEncryption = &o.fs.opt.ServerSideEncryption
} }
@ -3277,6 +3302,9 @@ func (o *Object) Remove(ctx context.Context) error {
Bucket: &bucket, Bucket: &bucket,
Key: &bucketPath, Key: &bucketPath,
} }
if o.fs.opt.RequesterPays {
req.RequestPayer = aws.String(s3.RequestPayerRequester)
}
err := o.fs.pacer.Call(func() (bool, error) { err := o.fs.pacer.Call(func() (bool, error) {
_, err := o.fs.c.DeleteObjectWithContext(ctx, &req) _, err := o.fs.c.DeleteObjectWithContext(ctx, &req)
return o.fs.shouldRetry(err) return o.fs.shouldRetry(err)