-
Notifications
You must be signed in to change notification settings - Fork 5
/
bucket_meta.go
48 lines (42 loc) · 1.34 KB
/
bucket_meta.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package store
import (
"context"
"github.com/filedag-project/filedag-storage/objectservice/pkg/policy"
)
// UpdateBucketPolicy Update bucket metadata .
// The configData data should not be modified after being sent here.
func (sys *bucketMetadataSys) UpdateBucketPolicy(ctx context.Context, bucket string, p *policy.Policy) error {
lk := sys.NewNSLock(bucket)
lkctx, err := lk.GetLock(ctx, globalOperationTimeout)
if err != nil {
return err
}
ctx = lkctx.Context()
defer lk.Unlock(lkctx.Cancel)
meta, err := sys.getBucketMeta(bucket)
if err != nil {
return err
}
meta.PolicyConfig = p
return sys.setBucketMeta(bucket, &meta)
}
// DeleteBucketPolicy Delete bucket metadata .
// The configData data should not be modified after being sent here.
func (sys *bucketMetadataSys) DeleteBucketPolicy(ctx context.Context, bucket string) error {
return sys.UpdateBucketPolicy(ctx, bucket, nil)
}
// GetPolicyConfig returns configured bucket policy
func (sys *bucketMetadataSys) GetPolicyConfig(ctx context.Context, bucket string) (*policy.Policy, error) {
meta, err := sys.GetBucketMeta(ctx, bucket)
if err != nil {
switch err.(type) {
case BucketNotFound:
return nil, BucketPolicyNotFound{Bucket: bucket}
}
return nil, err
}
if meta.PolicyConfig == nil {
return nil, BucketPolicyNotFound{Bucket: bucket}
}
return meta.PolicyConfig, nil
}