Merge pull request #22963 from rekahsoft/s3-backend-pagination
Allow s3 backends to contain more then 1000 workspaces
This commit is contained in:
commit
d45a4d33bb
|
@ -18,6 +18,8 @@ import (
|
|||
)
|
||||
|
||||
func (b *Backend) Workspaces() ([]string, error) {
|
||||
const maxKeys = 1000
|
||||
|
||||
prefix := ""
|
||||
|
||||
if b.workspaceKeyPrefix != "" {
|
||||
|
@ -25,24 +27,24 @@ func (b *Backend) Workspaces() ([]string, error) {
|
|||
}
|
||||
|
||||
params := &s3.ListObjectsInput{
|
||||
Bucket: &b.bucketName,
|
||||
Prefix: aws.String(prefix),
|
||||
}
|
||||
|
||||
resp, err := b.s3Client.ListObjects(params)
|
||||
if err != nil {
|
||||
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == s3.ErrCodeNoSuchBucket {
|
||||
return nil, fmt.Errorf(errS3NoSuchBucket, err)
|
||||
}
|
||||
return nil, err
|
||||
Bucket: &b.bucketName,
|
||||
Prefix: aws.String(prefix),
|
||||
MaxKeys: aws.Int64(maxKeys),
|
||||
}
|
||||
|
||||
wss := []string{backend.DefaultStateName}
|
||||
for _, obj := range resp.Contents {
|
||||
ws := b.keyEnv(*obj.Key)
|
||||
if ws != "" {
|
||||
wss = append(wss, ws)
|
||||
err := b.s3Client.ListObjectsPages(params, func(page *s3.ListObjectsOutput, lastPage bool) bool {
|
||||
for _, obj := range page.Contents {
|
||||
ws := b.keyEnv(*obj.Key)
|
||||
if ws != "" {
|
||||
wss = append(wss, ws)
|
||||
}
|
||||
}
|
||||
return !lastPage
|
||||
})
|
||||
|
||||
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == s3.ErrCodeNoSuchBucket {
|
||||
return nil, fmt.Errorf(errS3NoSuchBucket, err)
|
||||
}
|
||||
|
||||
sort.Strings(wss[1:])
|
||||
|
|
Loading…
Reference in New Issue