-
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 3 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 |
---|---|---|
|
@@ -17,13 +17,15 @@ import ( | |
) | ||
|
||
func TestS3Backend(t *testing.T) { | ||
if os.Getenv("AWS_ACCESS_KEY_ID") == "" || os.Getenv("AWS_SECRET_ACCESS_KEY") == "" { | ||
t.SkipNow() | ||
} | ||
creds := credentials.NewChainCredentials( | ||
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. Please look at using |
||
[]credentials.Provider{ | ||
&credentials.EnvProvider{}, | ||
&credentials.SharedCredentialsProvider{Filename: "", Profile: ""}, | ||
}) | ||
|
||
creds, err := credentials.NewEnvCredentials().Get() | ||
credValue, err := creds.Get() | ||
if err != nil { | ||
t.Fatalf("err: %v", err) | ||
t.SkipNow() | ||
} | ||
|
||
// If the variable is empty or doesn't exist, the default | ||
|
@@ -36,7 +38,7 @@ func TestS3Backend(t *testing.T) { | |
} | ||
|
||
s3conn := s3.New(session.New(&aws.Config{ | ||
Credentials: credentials.NewEnvCredentials(), | ||
Credentials: creds, | ||
Endpoint: aws.String(endpoint), | ||
Region: aws.String(region), | ||
})) | ||
|
@@ -78,9 +80,9 @@ func TestS3Backend(t *testing.T) { | |
logger := logformat.NewVaultLogger(log.LevelTrace) | ||
|
||
b, err := NewBackend("s3", logger, map[string]string{ | ||
"access_key": creds.AccessKeyID, | ||
"secret_key": creds.SecretAccessKey, | ||
"session_token": creds.SessionToken, | ||
"access_key": credValue.AccessKeyID, | ||
"secret_key": credValue.SecretAccessKey, | ||
"session_token": credValue.SessionToken, | ||
"bucket": bucket, | ||
}) | ||
if err != nil { | ||
|
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.