Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/regioncheck/linode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", ""))
}
})

Expand Down
10 changes: 4 additions & 6 deletions provider/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions provider/clientmap/clientmap.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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),
}
}

Expand Down
5 changes: 3 additions & 2 deletions provider/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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, ""
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions provider/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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
Expand Down