Skip to content

Commit a60e25d

Browse files
pablo1664arttor
authored andcommitted
feat: add feature preserveACLGrants
1 parent e7d5e1f commit a60e25d

7 files changed

Lines changed: 16 additions & 18 deletions

File tree

docker-compose/s3-credentials.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ storage:
1111
secretAccessKey: fakeSecret
1212
provider: Other # <Ceph|Minio|AWS|Other see providers list in rclone config> https://rclone.org/s3/#configuration
1313
isMain: true # <true|false> one of the storages in should be main
14-
syncACLGrants: false # Set true to synchronize ACL Grants from source
1514
healthCheckInterval: 10s
1615
httpTimeout: 1m
1716
isSecure: false #set false for http address
@@ -27,7 +26,6 @@ storage:
2726
secretAccessKey: fakeSecret2
2827
provider: Other
2928
isMain: false
30-
syncACLGrants: false
3129
healthCheckInterval: 10s
3230
httpTimeout: 1m
3331
isSecure: false

docker-compose/worker-conf.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ features:
1919
acl: false # sync object/bucket ACLs
2020
lifecycle: false # sync bucket Lifecycle
2121
policy: false # sync bucket Policies
22+
preserveACLGrants: false # preserve object/bucket ACL Grants from source
2223

pkg/config/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ features:
3535
acl: true # sync object/bucket ACLs
3636
lifecycle: false # sync bucket Lifecycle
3737
policy: false # sync bucket Policies
38+
preserveACLGrants: false # preserve object/bucket ACL Grants from source

pkg/features/features.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ package features
1919
import "context"
2020

2121
type Config struct {
22-
Versioning bool `yaml:"versioning"`
23-
Tagging bool `yaml:"tagging"`
24-
ACL bool `yaml:"acl"`
25-
Lifecycle bool `yaml:"lifecycle"`
26-
Policy bool `yaml:"policy"`
22+
Versioning bool `yaml:"versioning"`
23+
Tagging bool `yaml:"tagging"`
24+
ACL bool `yaml:"acl"`
25+
Lifecycle bool `yaml:"lifecycle"`
26+
Policy bool `yaml:"policy"`
27+
PreserveACLGrants bool `yaml:"preserveACLGrants"`
2728
}
2829

2930
var val *Config
@@ -51,3 +52,7 @@ func Lifecycle(_ context.Context) bool {
5152
func Policy(_ context.Context) bool {
5253
return val.Policy
5354
}
55+
56+
func PreserveACLGrants(_ context.Context) bool {
57+
return val.PreserveACLGrants
58+
}

pkg/s3/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ type Storage struct {
4848
HealthCheckInterval time.Duration `yaml:"healthCheckInterval"`
4949
HttpTimeout time.Duration `yaml:"httpTimeout"`
5050
IsSecure bool `yaml:"isSecure"`
51-
SyncACLGrants bool `yaml:"syncACLGrants"`
5251
DefaultRegion string `yaml:"defaultRegion"`
5352

5453
RateLimit RateLimit `yaml:"rateLimit"`

service/worker/config.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ storage:
4747
# secretAccessKey: <user2 v4 secretKey credential>
4848
# provider: <Ceph|Minio|AWS|Other see providers list in rclone config> # https://rclone.org/s3/#configuration
4949
# isMain: true # <true|false> one of the storages in should be main
50-
# syncACLGrants: false #set true to synchronize ACL Grants from source
5150
# healthCheckInterval: 10s
5251
# httpTimeout: 1m
5352
# isSecure: true #set false for http address
@@ -66,7 +65,6 @@ storage:
6665
# secretAccessKey: <user2 v4 secretKey credential>
6766
# provider: <Ceph|Minio|AWS|Other see providers list in rclone config> # https://rclone.org/s3/#configuration
6867
# isMain: false # <true|false> one of the storages in should be main
69-
# syncACLGrants: false #set true to synchronize ACL Grants from source
7068
# healthCheckInterval: 10s
7169
# httpTimeout: 1m
7270
# isSecure: true #set false for http address

service/worker/handler/acl.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,8 @@ func (s *svc) syncBucketACL(ctx context.Context, fromClient, toClient s3client.C
156156
toOwnerID = toACL.Owner.ID
157157
}
158158

159-
var syncACLGrants bool = toClient.Config().SyncACLGrants
160-
161159
_, err = toClient.AWS().PutBucketAclWithContext(ctx, &aws_s3.PutBucketAclInput{
162-
AccessControlPolicy: mappedOwnersACL(fromACL.Owner, fromACL.Grants, toOwnerID, syncACLGrants),
160+
AccessControlPolicy: mappedOwnersACL(fromACL.Owner, fromACL.Grants, toOwnerID, features.PreserveACLGrants(ctx)),
163161
Bucket: &bucket,
164162
})
165163
if err != nil {
@@ -220,10 +218,8 @@ func (s *svc) syncObjectACL(ctx context.Context, fromClient, toClient s3client.C
220218
toOwnerID = toACL.Owner.ID
221219
}
222220

223-
var syncACLGrants bool = toClient.Config().SyncACLGrants
224-
225221
_, err = toClient.AWS().PutObjectAclWithContext(ctx, &aws_s3.PutObjectAclInput{
226-
AccessControlPolicy: mappedOwnersACL(fromACL.Owner, fromACL.Grants, toOwnerID, syncACLGrants),
222+
AccessControlPolicy: mappedOwnersACL(fromACL.Owner, fromACL.Grants, toOwnerID, features.PreserveACLGrants(ctx)),
227223
Bucket: &bucket,
228224
Key: &object,
229225
VersionId: nil, //todo: versioning
@@ -248,11 +244,11 @@ func srcOwnerToDstOwner(owner, srcBucketOwner, dstBucketOwner *string) *string {
248244
return dstBucketOwner
249245
}
250246

251-
func mappedOwnersACL(srcOwner *aws_s3.Owner, srcGrants []*aws_s3.Grant, dstOwner *string, syncACLGrants bool) *aws_s3.AccessControlPolicy {
247+
func mappedOwnersACL(srcOwner *aws_s3.Owner, srcGrants []*aws_s3.Grant, dstOwner *string, preserveACLGrants bool) *aws_s3.AccessControlPolicy {
252248
grants := make([]*aws_s3.Grant, len(srcGrants))
253249
for i, grant := range srcGrants {
254250
var dstID *string
255-
if syncACLGrants {
251+
if preserveACLGrants {
256252
dstID = grant.Grantee.ID
257253
} else {
258254
dstID = srcOwnerToDstOwner(grant.Grantee.ID, srcOwner.ID, dstOwner)

0 commit comments

Comments
 (0)