From 49e13a88316e8c9be3d7f24986e4765566acbf96 Mon Sep 17 00:00:00 2001 From: Dan Salmon Date: Wed, 5 Nov 2025 21:30:31 -0600 Subject: [PATCH] style: lint --- cmd/regioncheck/linode.go | 2 +- provider/aws.go | 10 ++++------ provider/clientmap/clientmap.go | 7 ++++--- provider/credentials.go | 5 +++-- provider/custom.go | 9 +++++---- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/cmd/regioncheck/linode.go b/cmd/regioncheck/linode.go index 6a5aa900..a867077a 100644 --- a/cmd/regioncheck/linode.go +++ b/cmd/regioncheck/linode.go @@ -28,7 +28,7 @@ func GetRegionsLinode() ([]string, error) { regions := []string{} doc.Find(".rdmd-table:nth-of-type(1) tbody tr td:nth-of-type(4)").Each(func(_ int, t *goquery.Selection) { for _, r := range regionRe.FindAllString(t.Text(), -1) { - regions = append(regions, strings.Replace(r, ".linodeobjects.com", "", -1)) + regions = append(regions, strings.ReplaceAll(r, ".linodeobjects.com", "")) } }) diff --git a/provider/aws.go b/provider/aws.go index 158655de..564ac866 100644 --- a/provider/aws.go +++ b/provider/aws.go @@ -4,11 +4,12 @@ import ( "context" "errors" "fmt" + "net/http" + "time" + "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/feature/ec2/imds" "github.com/sa7mon/s3scanner/permission" - "net/http" - "time" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" "github.com/aws/aws-sdk-go-v2/config" @@ -73,10 +74,7 @@ func (a *AWS) Scan(b *bucket.Bucket, doDestructiveChecks bool) error { } func (a *AWS) Enumerate(b *bucket.Bucket) error { - useCreds := false - if b.PermAuthUsersRead == bucket.PermissionAllowed { - useCreds = true - } + useCreds := b.PermAuthUsersRead == bucket.PermissionAllowed client, err := a.getRegionClient(b.Region, useCreds) if err != nil { return err diff --git a/provider/clientmap/clientmap.go b/provider/clientmap/clientmap.go index d7afdd52..27226ada 100644 --- a/provider/clientmap/clientmap.go +++ b/provider/clientmap/clientmap.go @@ -1,8 +1,9 @@ package clientmap import ( - "github.com/aws/aws-sdk-go-v2/service/s3" "sync" + + "github.com/aws/aws-sdk-go-v2/service/s3" ) type ClientKey struct { @@ -22,10 +23,10 @@ func New() *ClientMap { } } -func WithCapacity(cap int) *ClientMap { +func WithCapacity(capacity int) *ClientMap { return &ClientMap{ Mutex: sync.Mutex{}, - inner: make(map[ClientKey]*s3.Client, cap), + inner: make(map[ClientKey]*s3.Client, capacity), } } diff --git a/provider/credentials.go b/provider/credentials.go index abe1468b..dbeb0fb1 100644 --- a/provider/credentials.go +++ b/provider/credentials.go @@ -3,6 +3,7 @@ package provider import ( "context" "errors" + "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/s3" "github.com/aws/smithy-go" @@ -18,7 +19,7 @@ func HasCredentials(cfg aws.Config) (bool, string) { if credsErr != nil { var oe *smithy.OperationError if errors.As(credsErr, &oe) { - if !(oe.ServiceID == "ec2imds" && oe.OperationName == "GetMetadata") { + if oe.ServiceID != "ec2imds" || oe.OperationName != "GetMetadata" { log.WithFields(log.Fields{"method": "provider.HasCredentials"}).Error(oe.Error()) } return false, "" @@ -32,7 +33,7 @@ func ClientHasCredentials(client *s3.Client) bool { if credsErr != nil { var oe *smithy.OperationError if errors.As(credsErr, &oe) { - if !(oe.ServiceID == "ec2imds" && oe.OperationName == "GetMetadata") { + if oe.ServiceID != "ec2imds" || oe.OperationName != "GetMetadata" { log.WithFields(log.Fields{"method": "provider.ClientHasCredentials"}).Error(oe.Error()) } return false diff --git a/provider/custom.go b/provider/custom.go index 88797718..d2a5b3bd 100644 --- a/provider/custom.go +++ b/provider/custom.go @@ -80,11 +80,12 @@ func NewCustomProvider(addressStyle string, insecure bool, regions []string, end cp.regions = regions cp.insecure = insecure cp.endpointFormat = endpointFormat - if addressStyle == "path" { + switch addressStyle { + case "path": cp.addressStyle = PathStyle - } else if addressStyle == "vhost" { + case "vhost": cp.addressStyle = VirtualHostStyle - } else { + default: return cp, fmt.Errorf("unknown custom provider address style: %s. Expected 'path' or 'vhost'", addressStyle) } @@ -99,7 +100,7 @@ func NewCustomProvider(addressStyle string, insecure bool, regions []string, end func (cp *CustomProvider) newClients() (*clientmap.ClientMap, error) { clients := clientmap.WithCapacity(len(cp.regions)) for _, r := range cp.regions { - regionURL := strings.Replace(cp.endpointFormat, "$REGION", r, -1) + regionURL := strings.ReplaceAll(cp.endpointFormat, "$REGION", r) client, err := newNonAWSClient(cp, regionURL) if err != nil { return nil, err