class Tina::S3Client

Constants

ClientError

Public Class Methods

new(s3, shell) click to toggle source
# File lib/tina/s3_client.rb, line 7
def initialize(s3, shell)
  @s3 = s3
  @shell = shell
end

Public Instance Methods

list_bucket_prefixes(prefix_uris) click to toggle source
# File lib/tina/s3_client.rb, line 12
def list_bucket_prefixes(prefix_uris)
  bucket_prefixes = prefix_uris.map do |prefix_uri|
    uri = URI.parse(prefix_uri)
    raise ClientError, "Invalid S3 URI: #{uri}" unless uri.scheme == 's3'
    [uri.host, uri.path.sub(%r[^/], '')]
  end
  bucket_prefixes.flat_map do |(bucket,prefix)|
    @shell.say "Listing prefix #{bucket}/#{prefix}..."
    objects = []
    marker = nil
    loop do
      listing = @s3.list_objects(bucket: bucket, prefix: prefix, marker: marker)
      listing.contents.each do |object|
        objects << S3Object.new(bucket, object.key, object.size)
        marker = object.key
      end
      break unless listing.is_truncated
    end
    objects
  end
end
restore_object(object, keep_days) click to toggle source
# File lib/tina/s3_client.rb, line 34
def restore_object(object, keep_days)
  @s3.restore_object(bucket: object.bucket, key: object.key, restore_request: { days: keep_days })
end