From 720935790412281fa39ebe1f43909cba504b638e Mon Sep 17 00:00:00 2001 From: Michael Anthony <5498095+manthonygfp@users.noreply.github.com> Date: Thu, 17 Nov 2022 11:55:27 -0700 Subject: [PATCH] [QT-309] Resolve AWS config before testing ACC (#17949) * Check to resolve AWS config before testing ACC * Adjust wording of error to be more clear --- builtin/logical/aws/backend_test.go | 22 ++++++++++++++++++++++ go.mod | 5 +++++ 2 files changed, 27 insertions(+) diff --git a/builtin/logical/aws/backend_test.go b/builtin/logical/aws/backend_test.go index 0489006750..5831dfea77 100644 --- a/builtin/logical/aws/backend_test.go +++ b/builtin/logical/aws/backend_test.go @@ -12,6 +12,7 @@ import ( "testing" "time" + "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/credentials" @@ -195,6 +196,10 @@ func TestBackend_throttled(t *testing.T) { } func testAccPreCheck(t *testing.T) { + if !hasAWSCredentials() { + t.Skip("Skipping because AWS credentials could not be resolved. See https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html#specifying-credentials for information on how to set up AWS credentials.") + } + initSetup.Do(func() { if v := os.Getenv("AWS_DEFAULT_REGION"); v == "" { log.Println("[INFO] Test: Using us-west-2 as test region") @@ -203,6 +208,23 @@ func testAccPreCheck(t *testing.T) { }) } +func hasAWSCredentials() bool { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + + cfg, err := config.LoadDefaultConfig(ctx) + if err != nil { + return false + } + + creds, err := cfg.Credentials.Retrieve(ctx) + if err != nil { + return false + } + + return creds.HasKeys() +} + func getAccountID() (string, error) { awsConfig := &aws.Config{ Region: aws.String("us-east-1"), diff --git a/go.mod b/go.mod index 5802e3cf30..e4c2c2a44f 100644 --- a/go.mod +++ b/go.mod @@ -33,6 +33,7 @@ require ( github.com/armon/go-radix v1.0.0 github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef github.com/aws/aws-sdk-go v1.44.128 + github.com/aws/aws-sdk-go-v2/config v1.6.0 github.com/axiomhq/hyperloglog v0.0.0-20220105174342-98591331716a github.com/cenkalti/backoff/v3 v3.2.2 github.com/chrismalek/oktasdk-go v0.0.0-20181212195951-3430665dfaa0 @@ -240,11 +241,15 @@ require ( github.com/apache/arrow/go/arrow v0.0.0-20210818145353-234c94e4ce64 // indirect github.com/aws/aws-sdk-go-v2 v1.8.0 // indirect github.com/aws/aws-sdk-go-v2/credentials v1.3.2 // indirect + github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.4.0 // indirect github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.4.0 // indirect + github.com/aws/aws-sdk-go-v2/internal/ini v1.2.0 // indirect github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.2.2 // indirect github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.2.2 // indirect github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.5.2 // indirect github.com/aws/aws-sdk-go-v2/service/s3 v1.12.0 // indirect + github.com/aws/aws-sdk-go-v2/service/sso v1.3.2 // indirect + github.com/aws/aws-sdk-go-v2/service/sts v1.6.1 // indirect github.com/aws/smithy-go v1.7.0 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bgentry/speakeasy v0.1.0 // indirect