Class: Bukelatta::Driver
- Inherits:
-
Object
- Object
- Bukelatta::Driver
- Includes:
- Logger::Helper, Utils::Helper
- Defined in:
- lib/bukelatta/driver.rb
Instance Method Summary collapse
- #create_policy(bucket_name, policy) ⇒ Object
- #delete_policy(bucket_name) ⇒ Object
-
#initialize(client, options = {}) ⇒ Driver
constructor
A new instance of Driver.
- #update_policy(bucket_name, policy, old_policy) ⇒ Object
Methods included from Logger::Helper
Methods included from Utils::Helper
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, = {}) @client = client @resource = Aws::S3::Resource.new(client: @client) = 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 [: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 [: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: [:color]), color: false) unless [:dry_run] bucket = @resource.bucket(bucket_name) bucket.auto_redirect do |b| b.policy.put(policy: JSON.dump(policy)) end end end |