Skip to content

Commit

Permalink
s3: fix loading credentials in TestS3ETag
Browse files Browse the repository at this point in the history
Signed-off-by: Janusz Marcinkiewicz <[email protected]>
  • Loading branch information
VirrageS committed Nov 20, 2024
1 parent 91fe18e commit 2367bb8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions ais/test/s3_compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"net"
"net/http"
"net/url"
"os"
"strings"
"testing"
"time"
Expand All @@ -27,6 +28,7 @@ import (
"github.com/NVIDIA/aistore/tools/tassert"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
s3manager "github.com/aws/aws-sdk-go-v2/feature/s3/manager"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
Expand Down Expand Up @@ -123,6 +125,20 @@ func setBucketFeatures(t *testing.T, bck cmn.Bck, bprops *cmn.Bprops, nf feat.Fl
})
}

func loadCredentials(t *testing.T) (f func(*config.LoadOptions) error) {
if os.Getenv("AWS_ACCESS_KEY_ID") != "" && os.Getenv("AWS_SECRET_ACCESS_KEY") != "" {
f = config.WithCredentialsProvider(
credentials.NewStaticCredentialsProvider(os.Getenv("AWS_ACCESS_KEY_ID"), os.Getenv("AWS_SECRET_ACCESS_KEY"), ""),
)
} else if os.Getenv("AWS_PROFILE") != "" {
f = config.WithSharedConfigProfile(os.Getenv("AWS_PROFILE"))
} else {
t.Skip("Failed to load credentials, none of AWS_PROFILE, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY are set")
f = func(*config.LoadOptions) error { return nil }
}
return f
}

func TestS3PresignedPutGet(t *testing.T) {
tools.CheckSkip(t, &tools.SkipTestArgs{Bck: cliBck, RequiresTLS: true, RequiredCloudProvider: apc.AWS})

Expand Down Expand Up @@ -288,7 +304,7 @@ func TestDisableColdGet(t *testing.T) {
tassert.Fatalf(t, err != nil, "Expected GET to fail %v", err)
}

// export AIS_ENDPOINT="http://localhost:8080"; export BUCKET="aws://..."; go test -v -run="TestS3ETag" -count=1 ./ais/test/.
// export AWS_PROFILE=default; export AIS_ENDPOINT="http://localhost:8080"; export BUCKET="aws://..."; go test -v -run="TestS3ETag" -count=1 ./ais/test/.
func TestS3ETag(t *testing.T) {
tools.CheckSkip(t, &tools.SkipTestArgs{Long: true, Bck: cliBck, RequiredCloudProvider: apc.AWS})

Expand All @@ -303,7 +319,7 @@ func TestS3ETag(t *testing.T) {

cfg, err := config.LoadDefaultConfig(
context.Background(),
config.WithSharedConfigProfile(cos.GetEnvOrDefault("AWS_PROFILE", "default")),
loadCredentials(t),
)
tassert.CheckFatal(t, err)
s3Client := s3.NewFromConfig(cfg)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/OneOfOne/xxhash v1.2.8
github.com/aws/aws-sdk-go-v2 v1.32.5
github.com/aws/aws-sdk-go-v2/config v1.28.5
github.com/aws/aws-sdk-go-v2/credentials v1.17.46
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.39
github.com/aws/aws-sdk-go-v2/service/s3 v1.67.1
github.com/aws/smithy-go v1.22.1
Expand Down Expand Up @@ -56,7 +57,6 @@ require (
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.49.0 // indirect
github.com/andybalholm/brotli v1.1.1 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.7 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.46 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.20 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.24 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.24 // indirect
Expand Down

0 comments on commit 2367bb8

Please sign in to comment.