Skip to content

Commit

Permalink
Fix S3 configurable path handling (#7966)
Browse files Browse the repository at this point in the history
Also remove some incorrect skipping of the S3 test.

Fixes #7362
  • Loading branch information
Jim Kalafut authored Dec 4, 2019
1 parent 967b8c9 commit 55bba55
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions physical/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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 += "/"
}

Expand Down
4 changes: 2 additions & 2 deletions physical/s3/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 55bba55

Please sign in to comment.