Class: Forger::S3::Bucket
- Inherits:
-
Object
- Object
- Forger::S3::Bucket
- Extended by:
- AwsServices
- Includes:
- AwsServices
- Defined in:
- lib/forger/s3/bucket.rb
Constant Summary collapse
- STACK_NAME =
ENV['FORGER_STACK_NAME'] || "forger"
- @@name =
nil
Class Method Summary collapse
Instance Method Summary collapse
- #bucket_name ⇒ Object
-
#create ⇒ Object
Launches a cloudformation to create an s3 bucket.
- #delete ⇒ Object
- #deploy ⇒ Object
- #exist? ⇒ Boolean
- #find_stack ⇒ Object
-
#initialize(options = {}) ⇒ Bucket
constructor
A new instance of Bucket.
- #show ⇒ Object
- #update ⇒ Object
Methods included from AwsServices
Constructor Details
#initialize(options = {}) ⇒ Bucket
Returns a new instance of Bucket.
29 30 31 |
# File 'lib/forger/s3/bucket.rb', line 29 def initialize(={}) @options = end |
Class Method Details
.ensure_exists! ⇒ Object
22 23 24 25 26 |
# File 'lib/forger/s3/bucket.rb', line 22 def ensure_exists! bucket = new return if bucket.exist? bucket.create end |
.name ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/forger/s3/bucket.rb', line 11 def name return @@name if @@name # only memoize once bucket has been created stack = new.find_stack return unless stack resp = cfn.describe_stack_resources(stack_name: STACK_NAME) bucket = resp.stack_resources.find { |r| r.logical_resource_id == "Bucket" } @@name = bucket.physical_resource_id # actual bucket name end |
Instance Method Details
#bucket_name ⇒ Object
46 47 48 |
# File 'lib/forger/s3/bucket.rb', line 46 def bucket_name self.class.name end |
#create ⇒ Object
Launches a cloudformation to create an s3 bucket
59 60 61 62 63 64 |
# File 'lib/forger/s3/bucket.rb', line 59 def create puts "Creating #{STACK_NAME} stack with the s3 bucket" cfn.create_stack(stack_name: STACK_NAME, template_body: template_body) status = CfnStatus.new(STACK_NAME) status.wait end |
#delete ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/forger/s3/bucket.rb', line 73 def delete are_you_sure? puts "Deleting #{STACK_NAME} stack with the s3 bucket" empty_bucket! cfn.delete_stack(stack_name: STACK_NAME) end |
#deploy ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/forger/s3/bucket.rb', line 33 def deploy stack = find_stack if stack update else create end end |
#exist? ⇒ Boolean
42 43 44 |
# File 'lib/forger/s3/bucket.rb', line 42 def exist? !!bucket_name end |
#find_stack ⇒ Object
81 82 83 84 85 86 |
# File 'lib/forger/s3/bucket.rb', line 81 def find_stack resp = cfn.describe_stacks(stack_name: STACK_NAME) resp.stacks.first rescue Aws::CloudFormation::Errors::ValidationError nil end |
#show ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/forger/s3/bucket.rb', line 50 def show if bucket_name puts "Forger bucket name: #{bucket_name}" else puts "Forger bucket does not exist yet." end end |
#update ⇒ Object
66 67 68 69 70 71 |
# File 'lib/forger/s3/bucket.rb', line 66 def update puts "Updating #{STACK_NAME} stack with the s3 bucket" cfn.update_stack(stack_name: STACK_NAME, template_body: template_body) rescue Aws::CloudFormation::Errors::ValidationError => e raise unless e..include?("No updates are to be performed") end |