class Deploy::S3::State

Public Class Methods

new(name, app_configs) click to toggle source
# File lib/deploy/s3/state.rb, line 4
def initialize(name, app_configs)
  @name = name
  @app_configs = app_configs
end

Public Instance Methods

exists?() click to toggle source
# File lib/deploy/s3/state.rb, line 9
def exists?
  target_bucket.exists?
end
target() click to toggle source
# File lib/deploy/s3/state.rb, line 17
def target
  target_bucket.name
end
version() click to toggle source
# File lib/deploy/s3/state.rb, line 13
def version
  @version ||= version_select
end

Private Instance Methods

read_version_folders() click to toggle source

The assumed structure of a config folder in S3 is: sealink-config/<app>/config/<version>

# File lib/deploy/s3/state.rb, line 47
def read_version_folders
  ErrorHandler.with_error_handling do
    @app_configs.bucket.objects.select do |o|
      !o.key.empty? &&
        o.key.start_with?("#{@name}/config/") &&
        o.key.end_with?('/') &&
        o.key.count('/') == 3
    end
  end
end
target_bucket() click to toggle source
# File lib/deploy/s3/state.rb, line 23
def target_bucket
  ErrorHandler.with_error_handling do
    Aws::S3::Bucket.new(name: @name)
  end
end
version_folders() click to toggle source
# File lib/deploy/s3/state.rb, line 41
def version_folders
  @version_folders ||= read_version_folders
end
version_select() click to toggle source
# File lib/deploy/s3/state.rb, line 29
def version_select
  # Provide the configuration versions and let user choose
  versions = version_folders.map{|obj| obj.key.split('/').last }

  puts "Found configuration versions:"
  cli = HighLine.new
  cli.choose do |menu|
    menu.prompt =  "Select index of the configuration to use:"
    menu.choices *versions
  end
end