class Bukelatta::Exporter

Public Class Methods

new(client, options = {}) click to toggle source
# File lib/bukelatta/exporter.rb, line 4
def initialize(client, options = {})
  @client = client
  @options = options
  @resource = Aws::S3::Resource.new(client: @client)
end

Public Instance Methods

export() click to toggle source
# File lib/bukelatta/exporter.rb, line 10
def export
  export_buckets
end

Private Instance Methods

export_bucket_policy(bucket) click to toggle source
# File lib/bukelatta/exporter.rb, line 31
def export_bucket_policy(bucket)
  bucket.auto_redirect do |b|
    JSON.parse(b.policy.policy.string)
  end
rescue Aws::S3::Errors::NoSuchBucketPolicy
  nil
end
export_buckets() click to toggle source
# File lib/bukelatta/exporter.rb, line 16
def export_buckets
  result = {}
  buckets = @resource.buckets
  concurrency = @options[:request_concurrency]

  Parallel.each(buckets, in_threads: concurrency) do |bucket|
    next unless matched?(bucket.name)

    policy = export_bucket_policy(bucket)
    result[bucket.name] = policy
  end

  result.sort_array!
end