Skip to content

Commit 4b04111

Browse files
authored
feat: add linter config (#341)
1 parent 8ec6aa9 commit 4b04111

28 files changed

+279
-263
lines changed

.golangci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
linters-settings:
2+
misspell:
3+
locale: US
4+
gosec:
5+
excludes:
6+
- G115 # Flags for potentially-unsafe casting of ints
7+
8+
issues:
9+
exclude-rules:
10+
- path: provider/providers.go # TLS verification is skipped when provider.Insecure() == true
11+
text: "InsecureSkipVerify"
12+
13+
linters:
14+
enable:
15+
- gosec
16+
- govet
17+
- loggercheck
18+
- misspell
19+
- revive
20+
- sloglint
21+
- tparallel
22+
- unconvert
23+
- unparam
24+
- unused
25+
- whitespace

bucket/bucket.go

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ var bucketRe = regexp.MustCompile(`[^.\-a-z0-9]`)
2828

2929
type 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 {
230230
func Permission(canDo bool) uint8 {
231231
if canDo {
232232
return PermissionAllowed
233-
} else {
234-
return PermissionDenied
235233
}
234+
return PermissionDenied
236235
}
237236

238237
func IsValidS3BucketName(bucketName string) bool {

bucket/bucket_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,9 @@ func TestBucket_ParseAclOutputv2(t *testing.T) {
246246

247247
for _, tt := range tests {
248248
t.Run(tt.name, func(t2 *testing.T) {
249+
t2.Parallel()
249250
b := NewBucket("mytestbucket")
250-
err := b.ParseAclOutputv2(&tt.acl)
251+
err := b.ParseACLOutputV2(&tt.acl)
251252
assert.Nil(t2, err)
252253

253254
for grantee, perms := range tt.expectedAllowed {
@@ -382,8 +383,8 @@ func TestBucket_String(t *testing.T) {
382383

383384
for _, tt := range tests {
384385
t.Run(tt.name, func(t2 *testing.T) {
386+
t2.Parallel()
385387
assert.Equal(t2, tt.string, tt.bucket.String())
386388
})
387389
}
388-
389390
}

cmd/mqingest/mqingest.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ type BucketMessage struct {
3333
func main() {
3434
var filename string
3535
var url string
36-
var queue_name string
36+
var queueName string
3737

3838
flag.StringVar(&filename, "file", "", "File name of buckets to send to MQ")
3939
flag.StringVar(&url, "url", "amqp://guest:guest@localhost:5672/", "AMQP URI of RabbitMQ server")
40-
flag.StringVar(&queue_name, "queue", "", "Name of message queue to publish buckets to")
40+
flag.StringVar(&queueName, "queue", "", "Name of message queue to publish buckets to")
4141

4242
flag.Parse()
4343

44-
if filename == "" || queue_name == "" {
44+
if filename == "" || queueName == "" {
4545
fmt.Println("Flags 'file' and 'queue' are required")
4646
printUsage()
4747
os.Exit(1)
@@ -56,16 +56,16 @@ func main() {
5656
defer ch.Close()
5757

5858
// Declare dead letter queue
59-
dlq, dlErr := ch.QueueDeclare(queue_name+"_dead", true, false, false,
59+
dlq, dlErr := ch.QueueDeclare(queueName+"_dead", true, false, false,
6060
false, nil)
6161
failOnError(dlErr, "Failed to declare dead letter queue")
6262

6363
q, err := ch.QueueDeclare(
64-
queue_name, // name
65-
true, // durable
66-
false, // delete when unused
67-
false, // exclusive
68-
false, // no-wait
64+
queueName, // name
65+
true, // durable
66+
false, // delete when unused
67+
false, // exclusive
68+
false, // no-wait
6969
amqp.Table{
7070
"x-dead-letter-exchange": "",
7171
"x-dead-letter-routing-key": dlq.Name,
@@ -112,12 +112,11 @@ func main() {
112112
if err != nil {
113113
failOnError(err, "Failed to publish to channel")
114114
}
115-
msgsPublished += 1
115+
msgsPublished++
116116
}
117117
if err := fileScanner.Err(); err != nil {
118118
failOnError(err, "fileScanner failed")
119119
}
120120

121-
log.Printf("%v bucket names published to queue %v\n", msgsPublished, queue_name)
122-
121+
log.Printf("%v bucket names published to queue %v\n", msgsPublished, queueName)
123122
}

cmd/regioncheck/regioncheck.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,35 +45,35 @@ func GetRegionsDO() ([]string, error) {
4545
}
4646

4747
regions := []string{}
48-
doc.Find("h3#other-products + table thead tr th").Each(func(i int, t *goquery.Selection) {
48+
doc.Find("h3#other-products + table thead tr th").Each(func(_ int, t *goquery.Selection) {
4949
regions = append(regions, t.Text())
5050
})
5151

52-
spaces_supported := []bool{}
53-
doc.Find("h3#other-products + table tbody tr").Each(func(i int, t *goquery.Selection) {
52+
spacesSupported := []bool{}
53+
doc.Find("h3#other-products + table tbody tr").Each(func(_ int, t *goquery.Selection) {
5454
// For each row, check the first cell for a value of "Spaces"
5555
rowHeader := t.Find("td").First().Text()
5656
if rowHeader == "Spaces" {
5757
// For each cell in the "Spaces" row, check if the contents are not empty - meaning Spaces is supported
58-
t.Find("td").Each(func(j int, v *goquery.Selection) {
58+
t.Find("td").Each(func(_ int, v *goquery.Selection) {
5959
supported := v.Text() != ""
60-
spaces_supported = append(spaces_supported, supported)
60+
spacesSupported = append(spacesSupported, supported)
6161
})
6262
}
6363
})
6464

65-
supported_regions := []string{}
65+
supportedRegions := []string{}
6666
for i := 0; i < len(regions); i++ {
6767
if regions[i] == "Product" {
6868
continue
6969
}
70-
if spaces_supported[i] {
71-
supported_regions = append(supported_regions, strings.ToLower(regions[i]))
70+
if spacesSupported[i] {
71+
supportedRegions = append(supportedRegions, strings.ToLower(regions[i]))
7272
}
7373
}
7474

7575
// Return slice of region names
76-
return supported_regions, nil
76+
return supportedRegions, nil
7777
}
7878

7979
// GetRegionsLinode fetches region names from Linode docs HTML page. Linode also provides this info via
@@ -105,7 +105,7 @@ func GetRegionsLinode() ([]string, error) {
105105
}
106106

107107
regions := []string{}
108-
doc.Find(".rdmd-table:nth-of-type(1) tbody tr td:nth-of-type(2)").Each(func(i int, t *goquery.Selection) {
108+
doc.Find(".rdmd-table:nth-of-type(1) tbody tr td:nth-of-type(2)").Each(func(_ int, t *goquery.Selection) {
109109
regions = append(regions, t.Text())
110110
})
111111

@@ -152,7 +152,7 @@ func main() {
152152
for name, get := range p {
153153
name := name
154154
get := get
155-
go func(w *sync.WaitGroup) {
155+
go func(_ *sync.WaitGroup) {
156156
results[name], errors[name] = get()
157157
wg.Done()
158158
}(&wg)

0 commit comments

Comments
 (0)