MCPcopy
hub / github.com/sa7mon/S3Scanner / enumerateListObjectsV2

Function enumerateListObjectsV2

provider/providers.go:117–154  ·  view source on GitHub ↗

* enumerateListObjectsV2 will enumerate all objects stored in b using the ListObjectsV2 API endpoint. The endpoint will be called until the IsTruncated field is false */

(client *s3.Client, b *bucket.Bucket)

Source from the content-addressed store, hash-verified

115be called until the IsTruncated field is false
116*/
117func enumerateListObjectsV2(client *s3.Client, b *bucket.Bucket) error {
118 var continuationToken *string
119 continuationToken = nil
120 page := 0
121
122 for {
123 log.WithFields(log.Fields{
124 "bucket_name": b.Name,
125 "method": "providers.enumerateListObjectsV2()",
126 }).Debugf("requesting objects page %d", page)
127 output, err := client.ListObjectsV2(context.TODO(), &s3.ListObjectsV2Input{
128 Bucket: &b.Name,
129 ContinuationToken: continuationToken,
130 EncodingType: types.EncodingTypeUrl,
131 },
132 )
133 if err != nil {
134 return err
135 }
136
137 for _, obj := range output.Contents {
138 b.Objects = append(b.Objects, bucket.Object{Key: *obj.Key, Size: uint64(*obj.Size)})
139 b.BucketSize += uint64(*obj.Size)
140 }
141
142 if !*output.IsTruncated {
143 b.ObjectsEnumerated = true
144 break
145 }
146 continuationToken = output.NextContinuationToken
147 page++
148 if page >= 5000 { // TODO: Should this limit be lowered?
149 return errors.New("more than 5000 pages of objects found. Skipping for now")
150 }
151 }
152 b.NumObjects = int32(len(b.Objects))
153 return nil
154}
155
156func checkPermissions(client *s3.Client, b *bucket.Bucket, doDestructiveChecks bool) error {
157 /*

Callers 9

EnumerateMethod · 0.85
EnumerateMethod · 0.85
EnumerateMethod · 0.85
EnumerateMethod · 0.85
EnumerateMethod · 0.85
EnumerateMethod · 0.85
EnumerateMethod · 0.85

Calls

no outgoing calls