Skip to content

Commit 1e5dfe4

Browse files
tas50claude
andcommitted
🧹 aws: modernize Go syntax (interface{} → any, slices.Chunk, stdlib slices)
- Replace `interface{}` with `any` across 12 files (118 occurrences) - Convert 5 manual batch loops to `slices.Chunk` (route53, guardduty, opensearch, athena, macie) - Replace `golang.org/x/exp/slices` with stdlib `slices` in timestream - Remove dead `remove()` function from aws.go - Drop `golang.org/x/exp` dependency from go.mod Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2116076 commit 1e5dfe4

17 files changed

+130
-158
lines changed

‎providers/aws/go.mod‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ require (
9191
github.com/spf13/afero v1.15.0
9292
github.com/stretchr/testify v1.11.1
9393
go.mondoo.com/mql/v13 v13.0.0-rc7
94-
golang.org/x/exp v0.0.0-20260218203240-3dfff04db8fa
9594
k8s.io/client-go v0.35.2
9695
)
9796

‎providers/aws/resources/aws.go‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -254,15 +254,6 @@ func mapStringInterfaceToStringString(m map[string]any) map[string]string {
254254
return newM
255255
}
256256

257-
func remove(s []string, r string) []string {
258-
for i, v := range s {
259-
if v == r {
260-
return append(s[:i], s[i+1:]...)
261-
}
262-
}
263-
return s
264-
}
265-
266257
// securityGroupIdHandler is a helper struct to handle security group ids and convert them to resources
267258
// This makes it easy to extend the internal representation of a resource and fetch security groups asynchronous
268259
type securityGroupIdHandler struct {

‎providers/aws/resources/aws_athena.go‎

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package resources
66
import (
77
"context"
88
"fmt"
9+
"slices"
910
"sync"
1011

1112
"github.com/aws/aws-sdk-go-v2/service/athena"
@@ -107,8 +108,8 @@ type mqlAwsAthenaWorkgroupInternal struct {
107108
cachedPublish bool
108109
cachedRequester bool
109110
cachedBytesCutoff int64
110-
cachedEngineVer interface{}
111-
cachedResultCfg interface{}
111+
cachedEngineVer any
112+
cachedResultCfg any
112113
lock sync.Mutex
113114
}
114115

@@ -189,14 +190,14 @@ func (a *mqlAwsAthenaWorkgroup) requesterPaysEnabled() (bool, error) {
189190
return a.cachedRequester, nil
190191
}
191192

192-
func (a *mqlAwsAthenaWorkgroup) engineVersion() (interface{}, error) {
193+
func (a *mqlAwsAthenaWorkgroup) engineVersion() (any, error) {
193194
if err := a.fetchConfig(); err != nil {
194195
return nil, err
195196
}
196197
return a.cachedEngineVer, nil
197198
}
198199

199-
func (a *mqlAwsAthenaWorkgroup) resultConfiguration() (interface{}, error) {
200+
func (a *mqlAwsAthenaWorkgroup) resultConfiguration() (any, error) {
200201
if err := a.fetchConfig(); err != nil {
201202
return nil, err
202203
}
@@ -282,7 +283,7 @@ func newMqlAwsAthenaDataCatalog(runtime *plugin.Runtime, region string, catalog
282283
type mqlAwsAthenaDataCatalogInternal struct {
283284
fetchedDetail bool
284285
cachedDesc string
285-
cachedParams map[string]interface{}
286+
cachedParams map[string]any
286287
lock sync.Mutex
287288
}
288289

@@ -309,7 +310,7 @@ func (a *mqlAwsAthenaDataCatalog) fetchDetail() error {
309310
if resp.DataCatalog != nil {
310311
a.cachedDesc = convert.ToValue(resp.DataCatalog.Description)
311312
if resp.DataCatalog.Parameters != nil {
312-
params := make(map[string]interface{}, len(resp.DataCatalog.Parameters))
313+
params := make(map[string]any, len(resp.DataCatalog.Parameters))
313314
for k, v := range resp.DataCatalog.Parameters {
314315
params[k] = v
315316
}
@@ -327,7 +328,7 @@ func (a *mqlAwsAthenaDataCatalog) description() (string, error) {
327328
return a.cachedDesc, nil
328329
}
329330

330-
func (a *mqlAwsAthenaDataCatalog) parameters() (map[string]interface{}, error) {
331+
func (a *mqlAwsAthenaDataCatalog) parameters() (map[string]any, error) {
331332
if err := a.fetchDetail(); err != nil {
332333
return nil, err
333334
}
@@ -382,13 +383,9 @@ func (a *mqlAwsAthena) getNamedQueries(conn *connection.AwsConnection) []*jobpoo
382383
}
383384

384385
// Batch get named queries (max 50 per call)
385-
for i := 0; i < len(queryIds); i += 50 {
386-
end := i + 50
387-
if end > len(queryIds) {
388-
end = len(queryIds)
389-
}
386+
for chunk := range slices.Chunk(queryIds, 50) {
390387
batch, err := svc.BatchGetNamedQuery(ctx, &athena.BatchGetNamedQueryInput{
391-
NamedQueryIds: queryIds[i:end],
388+
NamedQueryIds: chunk,
392389
})
393390
if err != nil {
394391
return nil, err
@@ -428,7 +425,7 @@ func newMqlAwsAthenaNamedQuery(runtime *plugin.Runtime, region string, nq athena
428425
return resource.(*mqlAwsAthenaNamedQuery), nil
429426
}
430427

431-
func (a *mqlAwsAthenaWorkgroup) tags() (map[string]interface{}, error) {
428+
func (a *mqlAwsAthenaWorkgroup) tags() (map[string]any, error) {
432429
if a.Arn.Error != nil {
433430
return nil, a.Arn.Error
434431
}
@@ -442,7 +439,7 @@ func (a *mqlAwsAthenaWorkgroup) tags() (map[string]interface{}, error) {
442439
svc := conn.Athena(region)
443440
ctx := context.Background()
444441

445-
tags := make(map[string]interface{})
442+
tags := make(map[string]any)
446443
var nextToken *string
447444
for {
448445
resp, err := svc.ListTagsForResource(ctx, &athena.ListTagsForResourceInput{

‎providers/aws/resources/aws_documentdb.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (a *mqlAwsDocumentdbCluster) kmsKey() (*mqlAwsKmsKey, error) {
136136
return mqlKey.(*mqlAwsKmsKey), nil
137137
}
138138

139-
func (a *mqlAwsDocumentdbCluster) tags() (map[string]interface{}, error) {
139+
func (a *mqlAwsDocumentdbCluster) tags() (map[string]any, error) {
140140
conn := a.MqlRuntime.Connection.(*connection.AwsConnection)
141141
svc := conn.DocumentDB(a.Region.Data)
142142
ctx := context.Background()
@@ -148,7 +148,7 @@ func (a *mqlAwsDocumentdbCluster) tags() (map[string]interface{}, error) {
148148
if err != nil {
149149
return nil, err
150150
}
151-
tags := make(map[string]interface{})
151+
tags := make(map[string]any)
152152
for _, t := range resp.TagList {
153153
if t.Key != nil && t.Value != nil {
154154
tags[*t.Key] = *t.Value
@@ -421,7 +421,7 @@ func (a *mqlAwsDocumentdbSnapshot) vpc() (*mqlAwsVpc, error) {
421421
return mqlVpc.(*mqlAwsVpc), nil
422422
}
423423

424-
func (a *mqlAwsDocumentdbInstance) tags() (map[string]interface{}, error) {
424+
func (a *mqlAwsDocumentdbInstance) tags() (map[string]any, error) {
425425
conn := a.MqlRuntime.Connection.(*connection.AwsConnection)
426426
svc := conn.DocumentDB(a.Region.Data)
427427
ctx := context.Background()
@@ -433,7 +433,7 @@ func (a *mqlAwsDocumentdbInstance) tags() (map[string]interface{}, error) {
433433
if err != nil {
434434
return nil, err
435435
}
436-
tags := make(map[string]interface{})
436+
tags := make(map[string]any)
437437
for _, t := range resp.TagList {
438438
if t.Key != nil && t.Value != nil {
439439
tags[*t.Key] = *t.Value

‎providers/aws/resources/aws_drs.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (a *mqlAwsDrs) createSourceServerResource(server drstypes.SourceServer, reg
126126
return nil, err
127127
}
128128

129-
tags := make(map[string]interface{})
129+
tags := make(map[string]any)
130130
for k, v := range server.Tags {
131131
tags[k] = v
132132
}
@@ -169,12 +169,12 @@ func (a *mqlAwsDrsSourceServer) replicationConfiguration() (*mqlAwsDrsReplicatio
169169
return nil, err
170170
}
171171

172-
stagingAreaTags := make(map[string]interface{})
172+
stagingAreaTags := make(map[string]any)
173173
for k, v := range resp.StagingAreaTags {
174174
stagingAreaTags[k] = v
175175
}
176176

177-
replicatedDisks := make([]interface{}, 0, len(resp.ReplicatedDisks))
177+
replicatedDisks := make([]any, 0, len(resp.ReplicatedDisks))
178178
for _, disk := range resp.ReplicatedDisks {
179179
diskMap, err := convert.JsonToDict(disk)
180180
if err != nil {
@@ -313,7 +313,7 @@ func (a *mqlAwsDrs) getJobs(conn *connection.AwsConnection) []*jobpool.Job {
313313
}
314314

315315
func (a *mqlAwsDrs) createJobResource(job drstypes.Job, region string) (*mqlAwsDrsJob, error) {
316-
participatingServers := make([]interface{}, 0, len(job.ParticipatingServers))
316+
participatingServers := make([]any, 0, len(job.ParticipatingServers))
317317
for _, server := range job.ParticipatingServers {
318318
serverMap, err := convert.JsonToDict(server)
319319
if err != nil {

‎providers/aws/resources/aws_ec2.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ func (i *mqlAwsEc2Image) id() (string, error) {
13851385
return i.Arn.Data, nil
13861386
}
13871387

1388-
func (i *mqlAwsEc2Image) launchPermissions() ([]interface{}, error) {
1388+
func (i *mqlAwsEc2Image) launchPermissions() ([]any, error) {
13891389
imageId := i.Id.Data
13901390
region := i.Region.Data
13911391
conn := i.MqlRuntime.Connection.(*connection.AwsConnection)
@@ -1402,7 +1402,7 @@ func (i *mqlAwsEc2Image) launchPermissions() ([]interface{}, error) {
14021402
}
14031403

14041404
imageArn := i.Arn.Data
1405-
permissions := make([]interface{}, 0, len(result.LaunchPermissions))
1405+
permissions := make([]any, 0, len(result.LaunchPermissions))
14061406
for _, perm := range result.LaunchPermissions {
14071407
// Build unique ID based on which field is set
14081408
var permId string

‎providers/aws/resources/aws_glue.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func newMqlAwsGlueCrawler(runtime *plugin.Runtime, region string, accountID stri
122122
return resource.(*mqlAwsGlueCrawler), nil
123123
}
124124

125-
func (a *mqlAwsGlueCrawler) tags() (map[string]interface{}, error) {
125+
func (a *mqlAwsGlueCrawler) tags() (map[string]any, error) {
126126
conn := a.MqlRuntime.Connection.(*connection.AwsConnection)
127127
svc := conn.Glue(a.Region.Data)
128128
ctx := context.Background()
@@ -243,7 +243,7 @@ func newMqlAwsGlueJob(runtime *plugin.Runtime, region string, accountID string,
243243
return resource.(*mqlAwsGlueJob), nil
244244
}
245245

246-
func (a *mqlAwsGlueJob) tags() (map[string]interface{}, error) {
246+
func (a *mqlAwsGlueJob) tags() (map[string]any, error) {
247247
conn := a.MqlRuntime.Connection.(*connection.AwsConnection)
248248
svc := conn.Glue(a.Region.Data)
249249
ctx := context.Background()
@@ -321,7 +321,7 @@ func (a *mqlAwsGlue) getSecurityConfigurations(conn *connection.AwsConnection) [
321321
func newMqlAwsGlueSecurityConfiguration(runtime *plugin.Runtime, region string, accountID string, secConf glue_types.SecurityConfiguration) (*mqlAwsGlueSecurityConfiguration, error) {
322322
id := fmt.Sprintf("arn:aws:glue:%s:%s:security-configuration/%s", region, accountID, convert.ToValue(secConf.Name))
323323

324-
var s3Enc, cwEnc, jbEnc interface{}
324+
var s3Enc, cwEnc, jbEnc any
325325
if secConf.EncryptionConfiguration != nil {
326326
var err error
327327
if len(secConf.EncryptionConfiguration.S3Encryption) > 0 {
@@ -416,7 +416,7 @@ func (a *mqlAwsGlue) getDatabases(conn *connection.AwsConnection) []*jobpool.Job
416416
func newMqlAwsGlueDatabase(runtime *plugin.Runtime, region string, db glue_types.Database) (*mqlAwsGlueDatabase, error) {
417417
id := fmt.Sprintf("glue/database/%s/%s/%s", region, convert.ToValue(db.CatalogId), convert.ToValue(db.Name))
418418

419-
var params map[string]interface{}
419+
var params map[string]any
420420
if db.Parameters != nil {
421421
params = toInterfaceMap(db.Parameters)
422422
}
@@ -476,7 +476,7 @@ func newMqlAwsGlueDatabaseTable(runtime *plugin.Runtime, region string, table gl
476476
return nil, err
477477
}
478478

479-
var params map[string]interface{}
479+
var params map[string]any
480480
if table.Parameters != nil {
481481
params = toInterfaceMap(table.Parameters)
482482
}
@@ -664,7 +664,7 @@ func newMqlAwsGlueWorkflow(runtime *plugin.Runtime, region string, accountID str
664664
return resource.(*mqlAwsGlueWorkflow), nil
665665
}
666666

667-
func (a *mqlAwsGlueWorkflow) tags() (map[string]interface{}, error) {
667+
func (a *mqlAwsGlueWorkflow) tags() (map[string]any, error) {
668668
conn := a.MqlRuntime.Connection.(*connection.AwsConnection)
669669
svc := conn.Glue(a.Region.Data)
670670
ctx := context.Background()

‎providers/aws/resources/aws_guardduty.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package resources
66
import (
77
"context"
88
"errors"
9+
"slices"
910
"time"
1011

1112
"github.com/aws/aws-sdk-go-v2/service/guardduty"
@@ -271,8 +272,7 @@ func fetchFindings(svc *guardduty.Client, detectorId string, regionVal string, p
271272

272273
// fetch all findings, we can only fetch 50 at a time
273274
fetched := 0
274-
for i := 0; i < len(findingIds); i += 50 {
275-
findingIdsChunk := findingIds[i:min(i+50, len(findingIds))]
275+
for findingIdsChunk := range slices.Chunk(findingIds, 50) {
276276
findingDetails, err := svc.GetFindings(ctx, &guardduty.GetFindingsInput{
277277
FindingIds: findingIdsChunk,
278278
DetectorId: &detectorId,

‎providers/aws/resources/aws_kinesis.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,15 @@ func (a *mqlAwsKinesis) streamConsumers() ([]any, error) {
293293
return res, nil
294294
}
295295

296-
func (a *mqlAwsKinesisStream) tags() (map[string]interface{}, error) {
296+
func (a *mqlAwsKinesisStream) tags() (map[string]any, error) {
297297
arn := a.Arn.Data
298298
region := a.Region.Data
299299
conn := a.MqlRuntime.Connection.(*connection.AwsConnection)
300300

301301
svc := conn.Kinesis(region)
302302
ctx := context.Background()
303303

304-
tags := make(map[string]interface{})
304+
tags := make(map[string]any)
305305
var exclusiveStartTagKey *string
306306
for {
307307
input := &kinesis.ListTagsForStreamInput{
@@ -445,15 +445,15 @@ func newMqlAwsKinesisFirehoseDeliveryStream(runtime *plugin.Runtime, region stri
445445
return resource.(*mqlAwsKinesisFirehoseDeliveryStream), nil
446446
}
447447

448-
func (a *mqlAwsKinesisFirehoseDeliveryStream) tags() (map[string]interface{}, error) {
448+
func (a *mqlAwsKinesisFirehoseDeliveryStream) tags() (map[string]any, error) {
449449
name := a.Name.Data
450450
region := a.Region.Data
451451
conn := a.MqlRuntime.Connection.(*connection.AwsConnection)
452452

453453
svc := conn.Firehose(region)
454454
ctx := context.Background()
455455

456-
tags := make(map[string]interface{})
456+
tags := make(map[string]any)
457457
var exclusiveStartTagKey *string
458458
for {
459459
input := &firehose.ListTagsForDeliveryStreamInput{

‎providers/aws/resources/aws_macie.go‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package resources
66
import (
77
"context"
88
"errors"
9+
"slices"
910
"sync"
1011
"time"
1112

@@ -501,13 +502,7 @@ func fetchMacieFindings(svc *macie2.Client, region string, findingIds []string,
501502
ctx := context.Background()
502503

503504
// Process findings in chunks of 50 (API limit)
504-
for i := 0; i < len(findingIds); i += 50 {
505-
end := i + 50
506-
if end > len(findingIds) {
507-
end = len(findingIds)
508-
}
509-
chunk := findingIds[i:end]
510-
505+
for chunk := range slices.Chunk(findingIds, 50) {
511506
findingDetails, err := svc.GetFindings(ctx, &macie2.GetFindingsInput{
512507
FindingIds: chunk,
513508
})

0 commit comments

Comments
 (0)