Class: CfnGuardian::S3
- Inherits:
-
Object
- Object
- CfnGuardian::S3
- Includes:
- Logging
- Defined in:
- lib/cfnguardian/s3.rb
Instance Attribute Summary collapse
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #create_bucket_if_not_exists ⇒ Object
-
#initialize(bucket, path = '') ⇒ S3
constructor
A new instance of S3.
- #set_bucket_name(bucket) ⇒ Object
Methods included from Logging
colors, included, logger, #logger, logger=
Constructor Details
#initialize(bucket, path = '') ⇒ S3
Returns a new instance of S3.
9 10 11 12 |
# File 'lib/cfnguardian/s3.rb', line 9 def initialize(bucket,path='') @bucket = set_bucket_name(bucket) @path = path end |
Instance Attribute Details
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
7 8 9 |
# File 'lib/cfnguardian/s3.rb', line 7 def bucket @bucket end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/cfnguardian/s3.rb', line 7 def path @path end |
Instance Method Details
#create_bucket_if_not_exists ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# 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) ⇒ Object
14 15 16 17 18 19 20 21 |
# 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 |