class CfnGuardian::S3

Attributes

bucket[R]
path[R]

Public Class Methods

new(bucket,path='') click to toggle source
# File lib/cfnguardian/s3.rb, line 9
def initialize(bucket,path='')
  @bucket = set_bucket_name(bucket)
  @path = path
end

Public Instance Methods

create_bucket_if_not_exists() click to toggle source
# File lib/cfnguardian/s3.rb, line 23
def create_bucket_if_not_exists()
  s3 = Aws::S3::Client.new
  begin
    s3.head_bucket(bucket: @bucket)
    logger.info("Found bucket #{@bucket}")
  rescue
    logger.info("Creating bucket #{@bucket}")
    s3.create_bucket(bucket: @bucket)
  end
  return bucket
end
set_bucket_name(bucket) click to toggle source
# File lib/cfnguardian/s3.rb, line 14
def set_bucket_name(bucket)
  if bucket.nil?
    sts = Aws::STS::Client.new
    account_id = sts.get_caller_identity().account
    return "#{account_id}.#{Aws.config[:region]}.guardian.templates"
  end
  return bucket
end