Method: OpenC3::AwsBucket#list_objects

Defined in:
lib/openc3/utilities/aws_bucket.rb

#list_objects(bucket:, prefix: nil, max_request: 1000, max_total: 100_000) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/openc3/utilities/aws_bucket.rb', line 110

def list_objects(bucket:, prefix: nil, max_request: 1000, max_total: 100_000)
  token = nil
  result = []
  while true
    resp = @client.list_objects_v2({
      bucket: bucket,
      max_keys: max_request,
      prefix: prefix,
      continuation_token: token
    })
    result.concat(resp.contents)
    break if result.length >= max_total
    break unless resp.is_truncated
    token = resp.next_continuation_token
  end
  # Array of objects with key and size methods
  result
rescue Aws::S3::Errors::NoSuchBucket
  raise NotFound, "Bucket '#{bucket}' does not exist."
end