Class: Bukelatta::Exporter

Inherits:
Object
  • Object
show all
Includes:
Utils::Helper
Defined in:
lib/bukelatta/exporter.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::Helper

#diff, #matched?

Constructor Details

#initialize(client, options = {}) ⇒ Exporter



8
9
10
11
12
# File 'lib/bukelatta/exporter.rb', line 8

def initialize(client, options = {})
  @client = client
  @options = options
  @resource = Aws::S3::Resource.new(client: @client)
end

Class Method Details

.export(client, options = {}) ⇒ Object



4
5
6
# File 'lib/bukelatta/exporter.rb', line 4

def self.export(client, options = {})
  self.new(client, options).export
end

Instance Method Details

#exportObject



14
15
16
# File 'lib/bukelatta/exporter.rb', line 14

def export
  export_buckets
end

#export_bucket_policy(bucket) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/bukelatta/exporter.rb', line 33

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_bucketsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bukelatta/exporter.rb', line 18

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