From a9cd490c9b7c00c6acb5fa45a80a005b67bc7710 Mon Sep 17 00:00:00 2001 From: Itai Gilo Date: Mon, 3 Jun 2024 15:41:21 +0300 Subject: [PATCH 01/13] Return an informative error message when using 'api/v1' for S3 GW endpoint --- pkg/gateway/errors/errors.go | 6 ++++++ pkg/gateway/middleware.go | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/pkg/gateway/errors/errors.go b/pkg/gateway/errors/errors.go index 39066db6303..3bace7f1afb 100644 --- a/pkg/gateway/errors/errors.go +++ b/pkg/gateway/errors/errors.go @@ -80,6 +80,7 @@ const ( ErrNoSuchBucket ErrNoSuchBucketPolicy ErrNoSuchBucketLifecycle + ErrNoSuchBucketPossibleAPIEndpoint ErrNoSuchKey ErrNoSuchUpload ErrNoSuchVersion @@ -341,6 +342,11 @@ var Codes = errorCodeMap{ Description: "The bucket lifecycle configuration does not exist", HTTPStatusCode: http.StatusNotFound, }, + ErrNoSuchBucketPossibleAPIEndpoint: { + Code: "ErrNoSuchBucketPossibleAPIEndpoint", + Description: "Using lakeFS API URI as the endpoint. Try removing the 'api/v1/' part from the endpoint.", + HTTPStatusCode: http.StatusNotFound, + }, ErrNoSuchKey: { Code: "NoSuchKey", Description: "The specified key does not exist.", diff --git a/pkg/gateway/middleware.go b/pkg/gateway/middleware.go index 4411b5648a1..06c4144316f 100644 --- a/pkg/gateway/middleware.go +++ b/pkg/gateway/middleware.go @@ -184,6 +184,13 @@ func EnrichWithRepositoryOrFallback(c *catalog.Catalog, authService auth.Gateway fallbackProxy.ServeHTTP(w, req) return } + + // see: github.com/treeverse/lakeFS/issues/3082 + if strings.HasPrefix(req.RequestURI, "/api/v1") { + _ = o.EncodeError(w, req, err, gatewayerrors.ErrNoSuchBucketPossibleAPIEndpoint.ToAPIErr()) + return + } + _ = o.EncodeError(w, req, err, gatewayerrors.ErrNoSuchBucket.ToAPIErr()) return } From a33c8470df369bd29f48ddcd6eece35e0c148c44 Mon Sep 17 00:00:00 2001 From: Itai Gilo Date: Mon, 3 Jun 2024 17:06:06 +0300 Subject: [PATCH 02/13] Update const and comment --- pkg/gateway/middleware.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/gateway/middleware.go b/pkg/gateway/middleware.go index 06c4144316f..0b47b05606a 100644 --- a/pkg/gateway/middleware.go +++ b/pkg/gateway/middleware.go @@ -9,6 +9,7 @@ import ( "strings" "time" + "github.com/treeverse/lakefs/pkg/api/apiutil" "github.com/treeverse/lakefs/pkg/auth" "github.com/treeverse/lakefs/pkg/catalog" gatewayerrors "github.com/treeverse/lakefs/pkg/gateway/errors" @@ -185,8 +186,9 @@ func EnrichWithRepositoryOrFallback(c *catalog.Catalog, authService auth.Gateway return } - // see: github.com/treeverse/lakeFS/issues/3082 - if strings.HasPrefix(req.RequestURI, "/api/v1") { + // users often set the gateway endpoint in the clients with /api/v1/ which is the openAPI endpoint. + // returning a more informative error in such case. + if strings.HasPrefix(req.RequestURI, apiutil.BaseURL) { _ = o.EncodeError(w, req, err, gatewayerrors.ErrNoSuchBucketPossibleAPIEndpoint.ToAPIErr()) return } From b6f532b9a375eca53c10107f21c8a230c5aeb81a Mon Sep 17 00:00:00 2001 From: Itai Gilo Date: Mon, 3 Jun 2024 17:52:06 +0300 Subject: [PATCH 03/13] Add system test --- esti/s3_gateway_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/esti/s3_gateway_test.go b/esti/s3_gateway_test.go index 96e7607647b..1487b01dc6f 100644 --- a/esti/s3_gateway_test.go +++ b/esti/s3_gateway_test.go @@ -655,3 +655,26 @@ func TestS3ReadObjectRedirect(t *testing.T) { require.Contains(t, err.Error(), "307 Temporary Redirect") }) } + +func TestPossibleAPIEndpointError(t *testing.T) { + ctx, _, repo := setupTest(t) + defer tearDownTest(repo) + + accessKeyID := viper.GetString("access_key_id") + secretAccessKey := viper.GetString("secret_access_key") + endpoint := "/api/v1" + viper.GetString("s3_endpoint") + endpointSecure := viper.GetBool("s3_endpoint_secure") + + minioClient, err := minio.New(endpoint, &minio.Options{ + Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""), + Secure: endpointSecure, + }) + if err != nil { + t.Fatalf("minio.New: %s", err) + } + + t.Run("use_api_v1_for_client_endpoint", func(t *testing.T) { + _, err := minioClient.GetObject(ctx, repo, "main/some", minio.GetObjectOptions{}) + require.Contains(t, err.Error(), "Using lakeFS API URI as the endpoint") + }) +} From d48f4fc3079def8020c37f4f82598db0f448d21d Mon Sep 17 00:00:00 2001 From: Itai Gilo Date: Mon, 3 Jun 2024 22:03:22 +0300 Subject: [PATCH 04/13] Fix tests --- esti/s3_gateway_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/esti/s3_gateway_test.go b/esti/s3_gateway_test.go index 1487b01dc6f..8ef264319cc 100644 --- a/esti/s3_gateway_test.go +++ b/esti/s3_gateway_test.go @@ -662,7 +662,7 @@ func TestPossibleAPIEndpointError(t *testing.T) { accessKeyID := viper.GetString("access_key_id") secretAccessKey := viper.GetString("secret_access_key") - endpoint := "/api/v1" + viper.GetString("s3_endpoint") + endpoint := viper.GetString("s3_endpoint") + apiutil.BaseURL endpointSecure := viper.GetBool("s3_endpoint_secure") minioClient, err := minio.New(endpoint, &minio.Options{ @@ -673,8 +673,9 @@ func TestPossibleAPIEndpointError(t *testing.T) { t.Fatalf("minio.New: %s", err) } - t.Run("use_api_v1_for_client_endpoint", func(t *testing.T) { + t.Run("use_open_api_for_client_endpoint", func(t *testing.T) { _, err := minioClient.GetObject(ctx, repo, "main/some", minio.GetObjectOptions{}) + require.NotNil(t, err) require.Contains(t, err.Error(), "Using lakeFS API URI as the endpoint") }) } From a13940c4e6be86c733317adcdc4982c3ec97c496 Mon Sep 17 00:00:00 2001 From: Itai Gilo Date: Mon, 3 Jun 2024 22:07:58 +0300 Subject: [PATCH 05/13] Update error message --- esti/s3_gateway_test.go | 2 +- pkg/gateway/errors/errors.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/esti/s3_gateway_test.go b/esti/s3_gateway_test.go index 8ef264319cc..0a67025d4de 100644 --- a/esti/s3_gateway_test.go +++ b/esti/s3_gateway_test.go @@ -676,6 +676,6 @@ func TestPossibleAPIEndpointError(t *testing.T) { t.Run("use_open_api_for_client_endpoint", func(t *testing.T) { _, err := minioClient.GetObject(ctx, repo, "main/some", minio.GetObjectOptions{}) require.NotNil(t, err) - require.Contains(t, err.Error(), "Using lakeFS API URI as the endpoint") + require.Contains(t, err.Error(), `Repository "api" not found`) }) } diff --git a/pkg/gateway/errors/errors.go b/pkg/gateway/errors/errors.go index 3bace7f1afb..aa0371fbfec 100644 --- a/pkg/gateway/errors/errors.go +++ b/pkg/gateway/errors/errors.go @@ -2,6 +2,7 @@ package errors import ( "encoding/xml" + "github.com/treeverse/lakefs/pkg/api/apiutil" "net/http" ) @@ -344,7 +345,7 @@ var Codes = errorCodeMap{ }, ErrNoSuchBucketPossibleAPIEndpoint: { Code: "ErrNoSuchBucketPossibleAPIEndpoint", - Description: "Using lakeFS API URI as the endpoint. Try removing the 'api/v1/' part from the endpoint.", + Description: `Repository "api" not found; this can happen if your endpoint URL mistakenly ends in "` + apiutil.BaseURL + `".`, HTTPStatusCode: http.StatusNotFound, }, ErrNoSuchKey: { From 13af4dfeb58c994f80f090bbae3c989242602a02 Mon Sep 17 00:00:00 2001 From: Itai Gilo Date: Mon, 3 Jun 2024 22:22:31 +0300 Subject: [PATCH 06/13] Fix lint --- pkg/gateway/errors/errors.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/gateway/errors/errors.go b/pkg/gateway/errors/errors.go index aa0371fbfec..b3c182afe53 100644 --- a/pkg/gateway/errors/errors.go +++ b/pkg/gateway/errors/errors.go @@ -2,8 +2,9 @@ package errors import ( "encoding/xml" - "github.com/treeverse/lakefs/pkg/api/apiutil" "net/http" + + "github.com/treeverse/lakefs/pkg/api/apiutil" ) /* From 7a18b48dd70960126b37110bc345baa946927ab4 Mon Sep 17 00:00:00 2001 From: Itai Gilo Date: Wed, 5 Jun 2024 10:37:47 +0300 Subject: [PATCH 07/13] Update test --- esti/s3_gateway_test.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/esti/s3_gateway_test.go b/esti/s3_gateway_test.go index 0a67025d4de..ded36549788 100644 --- a/esti/s3_gateway_test.go +++ b/esti/s3_gateway_test.go @@ -4,6 +4,8 @@ import ( "bytes" "context" "fmt" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/s3" "io" "math/rand" "net/http" @@ -662,19 +664,12 @@ func TestPossibleAPIEndpointError(t *testing.T) { accessKeyID := viper.GetString("access_key_id") secretAccessKey := viper.GetString("secret_access_key") - endpoint := viper.GetString("s3_endpoint") + apiutil.BaseURL - endpointSecure := viper.GetBool("s3_endpoint_secure") - minioClient, err := minio.New(endpoint, &minio.Options{ - Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""), - Secure: endpointSecure, - }) - if err != nil { - t.Fatalf("minio.New: %s", err) - } + s3Client, err := testutil.SetupTestS3Client("http://127.0.0.1:8000/api/v1", accessKeyID, secretAccessKey) + require.NoError(t, err, "failed creating s3 client") t.Run("use_open_api_for_client_endpoint", func(t *testing.T) { - _, err := minioClient.GetObject(ctx, repo, "main/some", minio.GetObjectOptions{}) + _, err := s3Client.ListObjectsV2(ctx, &s3.ListObjectsV2Input{Bucket: aws.String("test")}) require.NotNil(t, err) require.Contains(t, err.Error(), `Repository "api" not found`) }) From d0a58f444f82ec20d21a584dc88717cef2f0a991 Mon Sep 17 00:00:00 2001 From: Itai Gilo Date: Wed, 5 Jun 2024 11:00:23 +0300 Subject: [PATCH 08/13] Fix test --- esti/s3_gateway_test.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/esti/s3_gateway_test.go b/esti/s3_gateway_test.go index ded36549788..bc927e5d076 100644 --- a/esti/s3_gateway_test.go +++ b/esti/s3_gateway_test.go @@ -665,12 +665,23 @@ func TestPossibleAPIEndpointError(t *testing.T) { accessKeyID := viper.GetString("access_key_id") secretAccessKey := viper.GetString("secret_access_key") - s3Client, err := testutil.SetupTestS3Client("http://127.0.0.1:8000/api/v1", accessKeyID, secretAccessKey) - require.NoError(t, err, "failed creating s3 client") - t.Run("use_open_api_for_client_endpoint", func(t *testing.T) { - _, err := s3Client.ListObjectsV2(ctx, &s3.ListObjectsV2Input{Bucket: aws.String("test")}) - require.NotNil(t, err) - require.Contains(t, err.Error(), `Repository "api" not found`) + endpoint := viper.GetString("s3_endpoint") + apiutil.BaseURL + s3Client, err := testutil.SetupTestS3Client(endpoint, accessKeyID, secretAccessKey) + require.NoError(t, err, "failed creating s3 client") + + _, listErr := s3Client.ListObjectsV2(ctx, &s3.ListObjectsV2Input{Bucket: aws.String("test")}) + require.NotNil(t, listErr) + require.Contains(t, listErr.Error(), `Repository "api" not found`) + }) + + t.Run("use_proper_client_endpoint", func(t *testing.T) { + endpoint := viper.GetString("s3_endpoint") + s3Client, err := testutil.SetupTestS3Client(endpoint, accessKeyID, secretAccessKey) + require.NoError(t, err, "failed creating s3 client") + + _, listErr := s3Client.ListObjectsV2(ctx, &s3.ListObjectsV2Input{Bucket: aws.String("test")}) + require.NotNil(t, listErr) + require.NotContains(t, listErr.Error(), `Repository "api" not found`) }) } From 140164c52ea6c8584fde9b8cf5142db547320e51 Mon Sep 17 00:00:00 2001 From: Itai Gilo Date: Wed, 5 Jun 2024 13:45:58 +0300 Subject: [PATCH 09/13] Clarify test --- esti/s3_gateway_test.go | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/esti/s3_gateway_test.go b/esti/s3_gateway_test.go index bc927e5d076..2ceeabc9067 100644 --- a/esti/s3_gateway_test.go +++ b/esti/s3_gateway_test.go @@ -658,30 +658,27 @@ func TestS3ReadObjectRedirect(t *testing.T) { }) } +func createS3Client(endpoint string, t *testing.T) *s3.Client { + accessKeyID := viper.GetString("access_key_id") + secretAccessKey := viper.GetString("secret_access_key") + s3Client, err := testutil.SetupTestS3Client(endpoint, accessKeyID, secretAccessKey) + require.NoError(t, err, "failed creating s3 client") + return s3Client +} + func TestPossibleAPIEndpointError(t *testing.T) { ctx, _, repo := setupTest(t) defer tearDownTest(repo) - accessKeyID := viper.GetString("access_key_id") - secretAccessKey := viper.GetString("secret_access_key") - t.Run("use_open_api_for_client_endpoint", func(t *testing.T) { - endpoint := viper.GetString("s3_endpoint") + apiutil.BaseURL - s3Client, err := testutil.SetupTestS3Client(endpoint, accessKeyID, secretAccessKey) - require.NoError(t, err, "failed creating s3 client") - - _, listErr := s3Client.ListObjectsV2(ctx, &s3.ListObjectsV2Input{Bucket: aws.String("test")}) - require.NotNil(t, listErr) - require.Contains(t, listErr.Error(), `Repository "api" not found`) + s3Client := createS3Client(viper.GetString("s3_endpoint")+apiutil.BaseURL, t) + _, listErr := s3Client.ListObjectsV2(ctx, &s3.ListObjectsV2Input{Bucket: aws.String("not-exists")}) + require.ErrorContains(t, listErr, gtwerrors.ErrNoSuchBucketPossibleAPIEndpoint.Error()) }) t.Run("use_proper_client_endpoint", func(t *testing.T) { - endpoint := viper.GetString("s3_endpoint") - s3Client, err := testutil.SetupTestS3Client(endpoint, accessKeyID, secretAccessKey) - require.NoError(t, err, "failed creating s3 client") - - _, listErr := s3Client.ListObjectsV2(ctx, &s3.ListObjectsV2Input{Bucket: aws.String("test")}) - require.NotNil(t, listErr) - require.NotContains(t, listErr.Error(), `Repository "api" not found`) + s3Client := createS3Client(viper.GetString("s3_endpoint"), t) + _, listErr := s3Client.ListObjectsV2(ctx, &s3.ListObjectsV2Input{Bucket: aws.String("not-exists")}) + require.ErrorContains(t, listErr, gtwerrors.ErrNoSuchBucket.Error()) }) } From 0f0fdde3aa51d12e7b2d8feee00d06c023aafd2e Mon Sep 17 00:00:00 2001 From: Itai Gilo Date: Wed, 5 Jun 2024 14:45:10 +0300 Subject: [PATCH 10/13] Fix test --- esti/s3_gateway_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/esti/s3_gateway_test.go b/esti/s3_gateway_test.go index 2ceeabc9067..3c7fd16286d 100644 --- a/esti/s3_gateway_test.go +++ b/esti/s3_gateway_test.go @@ -671,13 +671,13 @@ func TestPossibleAPIEndpointError(t *testing.T) { defer tearDownTest(repo) t.Run("use_open_api_for_client_endpoint", func(t *testing.T) { - s3Client := createS3Client(viper.GetString("s3_endpoint")+apiutil.BaseURL, t) + s3Client := createS3Client(endpointURL+apiutil.BaseURL, t) _, listErr := s3Client.ListObjectsV2(ctx, &s3.ListObjectsV2Input{Bucket: aws.String("not-exists")}) require.ErrorContains(t, listErr, gtwerrors.ErrNoSuchBucketPossibleAPIEndpoint.Error()) }) t.Run("use_proper_client_endpoint", func(t *testing.T) { - s3Client := createS3Client(viper.GetString("s3_endpoint"), t) + s3Client := createS3Client(endpointURL, t) _, listErr := s3Client.ListObjectsV2(ctx, &s3.ListObjectsV2Input{Bucket: aws.String("not-exists")}) require.ErrorContains(t, listErr, gtwerrors.ErrNoSuchBucket.Error()) }) From 57a5be2e41a476cf0d0f4b839d4d4a1d8fe5b51d Mon Sep 17 00:00:00 2001 From: Itai Gilo Date: Wed, 5 Jun 2024 17:31:21 +0300 Subject: [PATCH 11/13] Fix test --- esti/s3_gateway_test.go | 2 +- pkg/testutil/setup.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/esti/s3_gateway_test.go b/esti/s3_gateway_test.go index 3c7fd16286d..6c192df9e62 100644 --- a/esti/s3_gateway_test.go +++ b/esti/s3_gateway_test.go @@ -661,7 +661,7 @@ func TestS3ReadObjectRedirect(t *testing.T) { func createS3Client(endpoint string, t *testing.T) *s3.Client { accessKeyID := viper.GetString("access_key_id") secretAccessKey := viper.GetString("secret_access_key") - s3Client, err := testutil.SetupTestS3Client(endpoint, accessKeyID, secretAccessKey) + s3Client, err := testutil.SetupTestS3ClientWithForcePathStyle(endpoint, accessKeyID, secretAccessKey, true) require.NoError(t, err, "failed creating s3 client") return s3Client } diff --git a/pkg/testutil/setup.go b/pkg/testutil/setup.go index 5e3897de9fc..3c40f37f899 100644 --- a/pkg/testutil/setup.go +++ b/pkg/testutil/setup.go @@ -136,6 +136,10 @@ func SetupTestingEnv(params *SetupTestingEnvParams) (logging.Logger, apigen.Clie } func SetupTestS3Client(endpoint, key, secret string) (*s3.Client, error) { + return SetupTestS3ClientWithForcePathStyle(endpoint, key, secret, viper.GetBool("force_path_style")) +} + +func SetupTestS3ClientWithForcePathStyle(endpoint, key, secret string, forcePathStyle bool) (*s3.Client, error) { if !strings.HasPrefix(endpoint, "http") { endpoint = "http://" + endpoint } @@ -146,10 +150,9 @@ func SetupTestS3Client(endpoint, key, secret string) (*s3.Client, error) { if err != nil { return nil, err } - forcePathStyleS3Client := viper.GetBool("force_path_style") svc := s3.NewFromConfig(cfg, func(options *s3.Options) { options.BaseEndpoint = aws.String(endpoint) - options.UsePathStyle = forcePathStyleS3Client + options.UsePathStyle = forcePathStyle }) return svc, nil } From 1547bcf9d7edd13b96b088567409763dad943559 Mon Sep 17 00:00:00 2001 From: Itai Gilo Date: Wed, 5 Jun 2024 17:44:02 +0300 Subject: [PATCH 12/13] Refactor tests --- esti/catalog_export_test.go | 2 +- esti/delete_objects_test.go | 3 ++- esti/s3_gateway_test.go | 2 +- pkg/testutil/setup.go | 9 +++------ 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/esti/catalog_export_test.go b/esti/catalog_export_test.go index ebd93be464c..f8072b810d6 100644 --- a/esti/catalog_export_test.go +++ b/esti/catalog_export_test.go @@ -177,7 +177,7 @@ func testSymlinkS3Exporter(t *testing.T, ctx context.Context, repo string, tmplD storageURL, err := url.Parse(symlinksPrefix) require.NoError(t, err, "failed extracting bucket name") - s3Client, err := testutil.SetupTestS3Client("https://s3.amazonaws.com", testData.AWSAccessKeyID, testData.AWSSecretAccessKey) + s3Client, err := testutil.SetupTestS3Client("https://s3.amazonaws.com", testData.AWSAccessKeyID, testData.AWSSecretAccessKey, viper.GetBool("force_path_style")) require.NoError(t, err, "failed creating s3 client") diff --git a/esti/delete_objects_test.go b/esti/delete_objects_test.go index a854dbe9189..782483824d1 100644 --- a/esti/delete_objects_test.go +++ b/esti/delete_objects_test.go @@ -87,7 +87,8 @@ func TestDeleteObjects_Viewer(t *testing.T) { key := resCreateCreds.JSON201.AccessKeyId secret := resCreateCreds.JSON201.SecretAccessKey s3Endpoint := viper.GetString("s3_endpoint") - s3Client, err := testutil.SetupTestS3Client(s3Endpoint, key, secret) + forcePathStyle := viper.GetBool("force_path_style") + s3Client, err := testutil.SetupTestS3Client(s3Endpoint, key, secret, forcePathStyle) require.NoError(t, err) // delete objects using viewer diff --git a/esti/s3_gateway_test.go b/esti/s3_gateway_test.go index 6c192df9e62..1a150c1b12d 100644 --- a/esti/s3_gateway_test.go +++ b/esti/s3_gateway_test.go @@ -661,7 +661,7 @@ func TestS3ReadObjectRedirect(t *testing.T) { func createS3Client(endpoint string, t *testing.T) *s3.Client { accessKeyID := viper.GetString("access_key_id") secretAccessKey := viper.GetString("secret_access_key") - s3Client, err := testutil.SetupTestS3ClientWithForcePathStyle(endpoint, accessKeyID, secretAccessKey, true) + s3Client, err := testutil.SetupTestS3Client(endpoint, accessKeyID, secretAccessKey, true) require.NoError(t, err, "failed creating s3 client") return s3Client } diff --git a/pkg/testutil/setup.go b/pkg/testutil/setup.go index 3c40f37f899..21ea918dd2a 100644 --- a/pkg/testutil/setup.go +++ b/pkg/testutil/setup.go @@ -128,18 +128,15 @@ func SetupTestingEnv(params *SetupTestingEnvParams) (logging.Logger, apigen.Clie } s3Endpoint := viper.GetString("s3_endpoint") - svc, err := SetupTestS3Client(s3Endpoint, key, secret) + forcePathStyle := viper.GetBool("force_path_style") + svc, err := SetupTestS3Client(s3Endpoint, key, secret, forcePathStyle) if err != nil { logger.WithError(err).Fatal("could not initialize S3 client") } return logger, client, svc, endpointURL } -func SetupTestS3Client(endpoint, key, secret string) (*s3.Client, error) { - return SetupTestS3ClientWithForcePathStyle(endpoint, key, secret, viper.GetBool("force_path_style")) -} - -func SetupTestS3ClientWithForcePathStyle(endpoint, key, secret string, forcePathStyle bool) (*s3.Client, error) { +func SetupTestS3Client(endpoint, key, secret string, forcePathStyle bool) (*s3.Client, error) { if !strings.HasPrefix(endpoint, "http") { endpoint = "http://" + endpoint } From 52f7251eb968864eed6e383e3da2793cf0e298a7 Mon Sep 17 00:00:00 2001 From: Itai Gilo Date: Thu, 6 Jun 2024 12:10:03 +0300 Subject: [PATCH 13/13] Improve code style --- esti/catalog_export_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/esti/catalog_export_test.go b/esti/catalog_export_test.go index f8072b810d6..290d7d6cf51 100644 --- a/esti/catalog_export_test.go +++ b/esti/catalog_export_test.go @@ -177,7 +177,11 @@ func testSymlinkS3Exporter(t *testing.T, ctx context.Context, repo string, tmplD storageURL, err := url.Parse(symlinksPrefix) require.NoError(t, err, "failed extracting bucket name") - s3Client, err := testutil.SetupTestS3Client("https://s3.amazonaws.com", testData.AWSAccessKeyID, testData.AWSSecretAccessKey, viper.GetBool("force_path_style")) + key := testData.AWSAccessKeyID + secret := testData.AWSSecretAccessKey + endpoint := "https://s3.amazonaws.com" + forcePathStyle := viper.GetBool("force_path_style") + s3Client, err := testutil.SetupTestS3Client(endpoint, key, secret, forcePathStyle) require.NoError(t, err, "failed creating s3 client")