-
Notifications
You must be signed in to change notification settings - Fork 75
/
policy.go
68 lines (58 loc) · 1.67 KB
/
policy.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package policy
import (
s3action "github.com/bittorrent/go-btfs/s3/action"
)
const (
PublicReadWrite = "public-read-write"
PublicRead = "public-read"
Private = "private"
)
var rwActionMap = map[s3action.Action]struct{}{
s3action.ListObjectsAction: {},
s3action.ListObjectsV2Action: {},
s3action.HeadObjectAction: {},
s3action.PutObjectAction: {},
s3action.GetObjectAction: {},
s3action.CopyObjectAction: {},
s3action.DeleteObjectAction: {},
s3action.DeleteObjectsAction: {},
s3action.CreateMultipartUploadAction: {},
s3action.AbortMultipartUploadAction: {},
s3action.CompleteMultipartUploadAction: {},
s3action.UploadPartAction: {},
}
// checkActionInPublicReadWrite - returns whether action is RW or not.
func checkActionInPublicReadWrite(action s3action.Action) bool {
_, ok := rwActionMap[action]
return ok
}
var rdActionMap = map[s3action.Action]struct{}{
s3action.ListObjectsAction: {},
s3action.ListObjectsV2Action: {},
s3action.HeadObjectAction: {},
s3action.GetObjectAction: {},
}
// checkActionInPublicRead - returns whether action is Read or not.
func checkActionInPublicRead(action s3action.Action) bool {
_, ok := rdActionMap[action]
return ok
}
func IsAllowed(own bool, acl string, action s3action.Action) (allow bool) {
if own {
return true
}
if action.IsBucketAction() {
return false
}
if action.IsObjectAction() {
switch acl {
case Private:
return own
case PublicRead:
return checkActionInPublicRead(action)
case PublicReadWrite:
return checkActionInPublicReadWrite(action)
}
}
return false
}