Class: Bukelatta::Driver

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

Instance Method Summary collapse

Methods included from Logger::Helper

#log

Methods included from Utils::Helper

#diff, #matched?

Constructor Details

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

Returns a new instance of Driver.



5
6
7
8
9
# File 'lib/bukelatta/driver.rb', line 5

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

Instance Method Details

#create_policy(bucket_name, policy) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bukelatta/driver.rb', line 11

def create_policy(bucket_name, policy)
  log(:info, "Create Bucket `#{bucket_name}` Policy", color: :cyan)

  unless @options[:dry_run]
    bucket = @resource.bucket(bucket_name)

    bucket.auto_redirect do |b|
      b.policy.put(policy: JSON.dump(policy))
    end
  end
end

#delete_policy(bucket_name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bukelatta/driver.rb', line 23

def delete_policy(bucket_name)
  log(:info, "Delete Bucket `#{bucket_name}` Policy", color: :red)

  unless @options[:dry_run]
    bucket = @resource.bucket(bucket_name)

    bucket.auto_redirect do |b|
      b.policy.delete
    end
  end
end

#update_policy(bucket_name, policy, old_policy) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/bukelatta/driver.rb', line 35

def update_policy(bucket_name, policy, old_policy)
  log(:info, "Update Bucket `#{bucket_name}` Policy", color: :green)
  log(:info, diff(old_policy, policy, color: @options[:color]), color: false)

  unless @options[:dry_run]
    bucket = @resource.bucket(bucket_name)

    bucket.auto_redirect do |b|
      b.policy.put(policy: JSON.dump(policy))
    end
  end
end