Skip to content

Commit

Permalink
Swith s3 ListObjects api to ListObjectsV2 (gomods#2006)
Browse files Browse the repository at this point in the history
Switch the ListObjects API used in s3 storage to ListObjectsV2
  • Loading branch information
yatesliang authored Nov 26, 2024
1 parent bf38a47 commit 8f0ee5e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions pkg/storage/s3/cataloger.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ func (s *Storage) Catalog(ctx context.Context, token string, pageSize int) ([]pa
res := make([]paths.AllPathParams, 0)
count := pageSize
for count > 0 {
lsParams := &s3.ListObjectsInput{
Bucket: aws.String(s.bucket),
Marker: &queryToken,
lsParams := &s3.ListObjectsV2Input{
Bucket: aws.String(s.bucket),
StartAfter: &queryToken,
}

loo, err := s.s3API.ListObjects(ctx, lsParams)
loo, err := s.s3API.ListObjectsV2(ctx, lsParams)
if err != nil {
return nil, "", errors.E(op, err)
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/storage/s3/lister.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ func (s *Storage) List(ctx context.Context, module string) ([]string, error) {
defer span.End()

modulePrefix := strings.TrimSuffix(module, "/") + "/@v"
lsParams := &s3.ListObjectsInput{

lsParams := &s3.ListObjectsV2Input{
Bucket: aws.String(s.bucket),
Prefix: aws.String(modulePrefix),
}

loo, err := s.s3API.ListObjects(ctx, lsParams)
loo, err := s.s3API.ListObjectsV2(ctx, lsParams)
if err != nil {
return nil, errors.E(op, err, errors.M(module))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/s3/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (s *Storage) clear() error {
ctx, cancel := context.WithTimeout(context.Background(), s.timeout)
defer cancel()

objects, err := s.s3API.ListObjects(ctx, &s3.ListObjectsInput{Bucket: aws.String(s.bucket)})
objects, err := s.s3API.ListObjectsV2(ctx, &s3.ListObjectsV2Input{Bucket: aws.String(s.bucket)})
if err != nil {
return err
}
Expand Down

0 comments on commit 8f0ee5e

Please sign in to comment.