@@ -28,19 +28,19 @@ var bucketRe = regexp.MustCompile(`[^.\-a-z0-9]`)
2828
2929type Bucket struct {
3030 //gorm.Model
31- ID uint `gorm:"primarykey" json:",omitempty"`
32- Name string `json:"name" gorm:"name;size:64;index"`
33- Region string `json:"region" gorm:"size:20"`
34- Exists uint8 `json:"exists"`
35- DateScanned time.Time `json:"date_scanned"`
36- Objects []BucketObject `json:"objects"`
37- ObjectsEnumerated bool `json:"objects_enumerated"`
38- Provider string `json:"provider"`
39- NumObjects int32 `json:"num_objects"`
31+ ID uint `gorm:"primarykey" json:",omitempty"`
32+ Name string `json:"name" gorm:"name;size:64;index"`
33+ Region string `json:"region" gorm:"size:20"`
34+ Exists uint8 `json:"exists"`
35+ DateScanned time.Time `json:"date_scanned"`
36+ Objects []Object `json:"objects"`
37+ ObjectsEnumerated bool `json:"objects_enumerated"`
38+ Provider string `json:"provider"`
39+ NumObjects int32 `json:"num_objects"`
4040
4141 // Total size of all bucket objects in bytes
4242 BucketSize uint64 `json:"bucket_size"`
43- OwnerId string `json:"owner_id"`
43+ OwnerID string `json:"owner_id"`
4444 OwnerDisplayName string `json:"owner_display_name"`
4545
4646 PermAuthUsersRead uint8 `json:"perm_auth_users_read"`
@@ -56,7 +56,7 @@ type Bucket struct {
5656 PermAllUsersFullControl uint8 `json:"perm_all_users_full_control"`
5757}
5858
59- type BucketObject struct {
59+ type Object struct {
6060 //gorm.Model
6161 ID uint `gorm:"primarykey" json:",omitempty"`
6262 Key string `json:"key" gorm:"type:string;size:1024"` // Keys can be up to 1,024 bytes long, UTF-8 encoded plus an additional byte just in case. https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html
@@ -82,63 +82,63 @@ func NewBucket(name string) Bucket {
8282 }
8383}
8484
85- func (bucket * Bucket ) String () string {
86- if bucket .Exists == BucketNotExist {
87- return fmt .Sprintf ("%v | bucket_not_exist" , bucket .Name )
85+ func (b * Bucket ) String () string {
86+ if b .Exists == BucketNotExist {
87+ return fmt .Sprintf ("%v | bucket_not_exist" , b .Name )
8888 }
8989
9090 var authUserPerms []string
91- if bucket .PermAuthUsersRead == PermissionAllowed {
91+ if b .PermAuthUsersRead == PermissionAllowed {
9292 authUserPerms = append (authUserPerms , "READ" )
9393 }
94- if bucket .PermAuthUsersWrite == PermissionAllowed {
94+ if b .PermAuthUsersWrite == PermissionAllowed {
9595 authUserPerms = append (authUserPerms , "WRITE" )
9696 }
97- if bucket .PermAuthUsersReadACL == PermissionAllowed {
97+ if b .PermAuthUsersReadACL == PermissionAllowed {
9898 authUserPerms = append (authUserPerms , "READ_ACP" )
9999 }
100- if bucket .PermAuthUsersWriteACL == PermissionAllowed {
100+ if b .PermAuthUsersWriteACL == PermissionAllowed {
101101 authUserPerms = append (authUserPerms , "WRITE_ACP" )
102102 }
103- if bucket .PermAuthUsersFullControl == PermissionAllowed {
103+ if b .PermAuthUsersFullControl == PermissionAllowed {
104104 authUserPerms = append (authUserPerms , "FULL_CONTROL" )
105105 }
106106
107107 var allUsersPerms []string
108- if bucket .PermAllUsersRead == PermissionAllowed {
108+ if b .PermAllUsersRead == PermissionAllowed {
109109 allUsersPerms = append (allUsersPerms , "READ" )
110110 }
111- if bucket .PermAllUsersWrite == PermissionAllowed {
111+ if b .PermAllUsersWrite == PermissionAllowed {
112112 allUsersPerms = append (allUsersPerms , "WRITE" )
113113 }
114- if bucket .PermAllUsersReadACL == PermissionAllowed {
114+ if b .PermAllUsersReadACL == PermissionAllowed {
115115 allUsersPerms = append (allUsersPerms , "READ_ACP" )
116116 }
117- if bucket .PermAllUsersWriteACL == PermissionAllowed {
117+ if b .PermAllUsersWriteACL == PermissionAllowed {
118118 allUsersPerms = append (allUsersPerms , "WRITE_ACP" )
119119 }
120- if bucket .PermAllUsersFullControl == PermissionAllowed {
120+ if b .PermAllUsersFullControl == PermissionAllowed {
121121 allUsersPerms = append (allUsersPerms , "FULL_CONTROL" )
122122 }
123123
124124 return fmt .Sprintf ("AuthUsers: [%v] | AllUsers: [%v]" , strings .Join (authUserPerms , ", " ), strings .Join (allUsersPerms , ", " ))
125125}
126126
127- func (bucket * Bucket ) Permissions () map [* types.Grantee ]map [string ]uint8 {
127+ func (b * Bucket ) Permissions () map [* types.Grantee ]map [string ]uint8 {
128128 return map [* types.Grantee ]map [string ]uint8 {
129129 groups .AllUsersv2 : {
130- "READ" : bucket .PermAllUsersRead ,
131- "WRITE" : bucket .PermAllUsersWrite ,
132- "READ_ACP" : bucket .PermAllUsersReadACL ,
133- "WRITE_ACP" : bucket .PermAllUsersWriteACL ,
134- "FULL_CONTROL" : bucket .PermAllUsersFullControl ,
130+ "READ" : b .PermAllUsersRead ,
131+ "WRITE" : b .PermAllUsersWrite ,
132+ "READ_ACP" : b .PermAllUsersReadACL ,
133+ "WRITE_ACP" : b .PermAllUsersWriteACL ,
134+ "FULL_CONTROL" : b .PermAllUsersFullControl ,
135135 },
136136 groups .AuthenticatedUsersv2 : {
137- "READ" : bucket .PermAuthUsersRead ,
138- "WRITE" : bucket .PermAuthUsersWrite ,
139- "READ_ACP" : bucket .PermAuthUsersReadACL ,
140- "WRITE_ACP" : bucket .PermAuthUsersWriteACL ,
141- "FULL_CONTROL" : bucket .PermAuthUsersFullControl ,
137+ "READ" : b .PermAuthUsersRead ,
138+ "WRITE" : b .PermAuthUsersWrite ,
139+ "READ_ACP" : b .PermAuthUsersReadACL ,
140+ "WRITE_ACP" : b .PermAuthUsersWriteACL ,
141+ "FULL_CONTROL" : b .PermAuthUsersFullControl ,
142142 },
143143 }
144144}
@@ -179,45 +179,45 @@ func ReadFromFile(bucketFile string, bucketChan chan Bucket) error {
179179 return nil
180180}
181181
182- // ParseAclOutputv2 TODO: probably move this to providers.go
183- func (bucket * Bucket ) ParseAclOutputv2 (aclOutput * s3.GetBucketAclOutput ) error {
184- bucket . OwnerId = * aclOutput .Owner .ID
182+ // ParseACLOutputV2 TODO: probably move this to providers.go
183+ func (b * Bucket ) ParseACLOutputV2 (aclOutput * s3.GetBucketAclOutput ) error {
184+ b . OwnerID = * aclOutput .Owner .ID
185185 if aclOutput .Owner .DisplayName != nil {
186- bucket .OwnerDisplayName = * aclOutput .Owner .DisplayName
186+ b .OwnerDisplayName = * aclOutput .Owner .DisplayName
187187 }
188188 // Since we can read the permissions, there should be no unknowns. Set all to denied, then read each grant and
189189 // set the corresponding permission to allowed.
190- bucket .DenyAll ()
190+ b .DenyAll ()
191191
192- for _ , b := range aclOutput .Grants {
193- if b .Grantee != nil && b .Grantee .Type == "Group" && * b .Grantee .URI == groups .AllUsersGroup {
194- switch b .Permission {
192+ for _ , g := range aclOutput .Grants {
193+ if g .Grantee != nil && g .Grantee .Type == "Group" && * g .Grantee .URI == groups .AllUsersGroup {
194+ switch g .Permission {
195195 case types .PermissionRead :
196- bucket .PermAllUsersRead = PermissionAllowed
196+ b .PermAllUsersRead = PermissionAllowed
197197 case types .PermissionWrite :
198- bucket .PermAllUsersWrite = PermissionAllowed
198+ b .PermAllUsersWrite = PermissionAllowed
199199 case types .PermissionReadAcp :
200- bucket .PermAllUsersReadACL = PermissionAllowed
200+ b .PermAllUsersReadACL = PermissionAllowed
201201 case types .PermissionWriteAcp :
202- bucket .PermAllUsersWriteACL = PermissionAllowed
202+ b .PermAllUsersWriteACL = PermissionAllowed
203203 case types .PermissionFullControl :
204- bucket .PermAllUsersFullControl = PermissionAllowed
204+ b .PermAllUsersFullControl = PermissionAllowed
205205 default :
206206 break
207207 }
208208 }
209- if b .Grantee != nil && b .Grantee .Type == "Group" && * b .Grantee .URI == groups .AuthUsersGroup {
210- switch b .Permission {
209+ if g .Grantee != nil && g .Grantee .Type == "Group" && * g .Grantee .URI == groups .AuthUsersGroup {
210+ switch g .Permission {
211211 case types .PermissionRead :
212- bucket .PermAuthUsersRead = PermissionAllowed
212+ b .PermAuthUsersRead = PermissionAllowed
213213 case types .PermissionWrite :
214- bucket .PermAuthUsersWrite = PermissionAllowed
214+ b .PermAuthUsersWrite = PermissionAllowed
215215 case types .PermissionReadAcp :
216- bucket .PermAuthUsersReadACL = PermissionAllowed
216+ b .PermAuthUsersReadACL = PermissionAllowed
217217 case types .PermissionWriteAcp :
218- bucket .PermAuthUsersWriteACL = PermissionAllowed
218+ b .PermAuthUsersWriteACL = PermissionAllowed
219219 case types .PermissionFullControl :
220- bucket .PermAuthUsersFullControl = PermissionAllowed
220+ b .PermAuthUsersFullControl = PermissionAllowed
221221 default :
222222 break
223223 }
@@ -230,9 +230,8 @@ func (bucket *Bucket) ParseAclOutputv2(aclOutput *s3.GetBucketAclOutput) error {
230230func Permission (canDo bool ) uint8 {
231231 if canDo {
232232 return PermissionAllowed
233- } else {
234- return PermissionDenied
235233 }
234+ return PermissionDenied
236235}
237236
238237func IsValidS3BucketName (bucketName string ) bool {
0 commit comments