-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More efficient s3 paging #2780
Merged
Merged
More efficient s3 paging #2780
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c16e024
Move appendIfMissing function to common location.
deverton a81736e
Have S3 group folders before sending response.
deverton 8f58b3d
Allow S3 integration tests to use shared creds.
deverton 7d2c3f1
Merge remote-tracking branch 'origin' into more-efficient-s3-paging
deverton 9dde160
Use the awsutil helper to find test creds
deverton a51865c
Move appendIfMissing to helper/strutil
deverton 9b6b9c1
Check we can get credentials before starting test.
deverton 9c1935e
Typo fix.
deverton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package physical | ||
|
||
func appendIfMissing(slice []string, i string) []string { | ||
for _, ele := range slice { | ||
if ele == i { | ||
return slice | ||
} | ||
} | ||
return append(slice, i) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package physical | ||
|
||
import "testing" | ||
|
||
func TestAppendIfMissing(t *testing.T) { | ||
keys := []string{} | ||
|
||
keys = appendIfMissing(keys, "foo") | ||
|
||
if len(keys) != 1 { | ||
t.Fatalf("expected slice to be length of 1: %v", keys) | ||
} | ||
if keys[0] != "foo" { | ||
t.Fatalf("expected slice to contain key 'foo': %v", keys) | ||
} | ||
|
||
keys = appendIfMissing(keys, "bar") | ||
|
||
if len(keys) != 2 { | ||
t.Fatalf("expected slice to be length of 2: %v", keys) | ||
} | ||
if keys[0] != "foo" { | ||
t.Fatalf("expected slice to contain key 'foo': %v", keys) | ||
} | ||
if keys[1] != "bar" { | ||
t.Fatalf("expected slice to contain key 'bar': %v", keys) | ||
} | ||
|
||
keys = appendIfMissing(keys, "foo") | ||
|
||
if len(keys) != 2 { | ||
t.Fatalf("expected slice to still be length of 2: %v", keys) | ||
} | ||
if keys[0] != "foo" { | ||
t.Fatalf("expected slice to still contain key 'foo': %v", keys) | ||
} | ||
if keys[1] != "bar" { | ||
t.Fatalf("expected slice to still contain key 'bar': %v", keys) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,23 +7,21 @@ import ( | |
"testing" | ||
"time" | ||
|
||
"github.com/hashicorp/vault/helper/awsutil" | ||
"github.com/hashicorp/vault/helper/logformat" | ||
log "github.com/mgutz/logxi/v1" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/credentials" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/s3" | ||
) | ||
|
||
func TestS3Backend(t *testing.T) { | ||
if os.Getenv("AWS_ACCESS_KEY_ID") == "" || os.Getenv("AWS_SECRET_ACCESS_KEY") == "" { | ||
t.SkipNow() | ||
} | ||
credsConfig := &awsutil.CredentialsConfig{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These environment variables were guarding the test from running on a system without credentials. The travis tests are failing because these tests are running now. I don't think the below error check is working |
||
|
||
creds, err := credentials.NewEnvCredentials().Get() | ||
credsChain, err := credsConfig.GenerateCredentialChain() | ||
if err != nil { | ||
t.Fatalf("err: %v", err) | ||
t.SkipNow() | ||
} | ||
|
||
// If the variable is empty or doesn't exist, the default | ||
|
@@ -36,7 +34,7 @@ func TestS3Backend(t *testing.T) { | |
} | ||
|
||
s3conn := s3.New(session.New(&aws.Config{ | ||
Credentials: credentials.NewEnvCredentials(), | ||
Credentials: credsChain, | ||
Endpoint: aws.String(endpoint), | ||
Region: aws.String(region), | ||
})) | ||
|
@@ -77,11 +75,9 @@ func TestS3Backend(t *testing.T) { | |
|
||
logger := logformat.NewVaultLogger(log.LevelTrace) | ||
|
||
// This uses the same logic to find the AWS credentials as we did at the beginning of the test | ||
b, err := NewBackend("s3", logger, map[string]string{ | ||
"access_key": creds.AccessKeyID, | ||
"secret_key": creds.SecretAccessKey, | ||
"session_token": creds.SessionToken, | ||
"bucket": bucket, | ||
"bucket": bucket, | ||
}) | ||
if err != nil { | ||
t.Fatalf("err: %s", err) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than do this, can you make this a method in
helper/strutil
? There's an existing method to do the search.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I totally missed the helper/strutil package when I did this originally. This is much better.