Class: CfnVpn::S3Bucket

Inherits:
Object
  • Object
show all
Defined in:
lib/cfnvpn/s3_bucket.rb

Instance Method Summary collapse

Constructor Details

#initialize(region, name) ⇒ S3Bucket

Returns a new instance of S3Bucket.



8
9
10
11
# File 'lib/cfnvpn/s3_bucket.rb', line 8

def initialize(region, name)
  @client = Aws::S3::Client.new(region: region)
  @name = name
end

Instance Method Details

#create_bucket(bucket) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cfnvpn/s3_bucket.rb', line 17

def create_bucket(bucket)
  @client.create_bucket({
    bucket: bucket,
    acl: 'private'
  })

  @client.put_public_access_block({
    bucket: bucket,
    public_access_block_configuration: { 
      block_public_acls: true,
      ignore_public_acls: true,
      block_public_policy: true,
      restrict_public_buckets: true,
    }
  })

  @client.put_bucket_encryption({
    bucket: bucket,
    server_side_encryption_configuration: {
      rules: [
        {
          apply_server_side_encryption_by_default: {
            sse_algorithm: "AES256"
          }
        }
      ]
    }
  })
end

#generate_bucket_nameObject



13
14
15
# File 'lib/cfnvpn/s3_bucket.rb', line 13

def generate_bucket_name
  return "cfnvpn-#{@name}-#{SecureRandom.hex}"
end