Method: S3Secure::Encryption::Enable#run

Defined in:
lib/s3_secure/encryption/enable.rb

#runObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/s3_secure/encryption/enable.rb', line 3

def run
  show = Show.new(@options)

  if show.enabled?
    # check rules to see if encryption is already set of some sort
    say "Bucket #{@bucket} already has encryption rules:"
  else
    # Set encryption rules
    # Ruby docs: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Client.html#put_bucket_encryption-instance_method
    # API docs: https://docs.aws.amazon.com/AmazonS3/latest/API/API_ServerSideEncryptionByDefault.html
    #
    #    put_bucket_encryption returns #<struct Aws::EmptyStructure>
    #
    s3.put_bucket_encryption(
      bucket: @bucket,
      server_side_encryption_configuration: {
        rules: [rule]})
    say "Encyption enabled on bucket #{@bucket} with rules:"
  end
end