From 55bba5537c98aefea3abe48fa3ad8553792e640d Mon Sep 17 00:00:00 2001 From: Jim Kalafut Date: Wed, 4 Dec 2019 06:18:45 -0800 Subject: [PATCH] Fix S3 configurable path handling (#7966) Also remove some incorrect skipping of the S3 test. Fixes #7362 --- physical/s3/s3.go | 9 +++++++-- physical/s3/s3_test.go | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/physical/s3/s3.go b/physical/s3/s3.go index 315b6d3269..b131678d47 100644 --- a/physical/s3/s3.go +++ b/physical/s3/s3.go @@ -225,6 +225,11 @@ func (s *S3Backend) Get(ctx context.Context, key string) (*physical.Entry, error return nil, err } + // Strip path prefix + if s.path != "" { + key = strings.TrimPrefix(key, s.path+"/") + } + ent := &physical.Entry{ Key: key, Value: data.Bytes(), @@ -266,8 +271,8 @@ func (s *S3Backend) List(ctx context.Context, prefix string) ([]string, error) { // Setup prefix prefix = path.Join(s.path, prefix) - // Validate prefix is ending with a "/" - if !strings.HasSuffix(prefix, "/") { + // Validate prefix (if present) is ending with a "/" + if prefix != "" && !strings.HasSuffix(prefix, "/") { prefix += "/" } diff --git a/physical/s3/s3_test.go b/physical/s3/s3_test.go index 849ab6b278..a7a7245541 100644 --- a/physical/s3/s3_test.go +++ b/physical/s3/s3_test.go @@ -34,12 +34,12 @@ func DoS3BackendTest(t *testing.T, kmsKeyId string) { credsChain, err := credsConfig.GenerateCredentialChain() if err != nil { - t.SkipNow() + t.Fatal(err) } _, err = credsChain.Get() if err != nil { - t.SkipNow() + t.Fatal(err) } // If the variable is empty or doesn't exist, the default