class Deploy::S3::Configuration
Public Class Methods
new(config_bucket_name)
click to toggle source
# File lib/deploy/s3/configuration.rb, line 5 def initialize(config_bucket_name) @config_bucket_name = config_bucket_name end
Public Instance Methods
apps()
click to toggle source
# File lib/deploy/s3/configuration.rb, line 17 def apps fail "Asked for app list without verifying. It will be wrong." if !@verified @apps ||= app_names end
config_bucket_for(name)
click to toggle source
# File lib/deploy/s3/configuration.rb, line 26 def config_bucket_for(name) app_buckets.detect { |app| app.key == name + '/' } end
created_folders()
click to toggle source
# File lib/deploy/s3/configuration.rb, line 22 def created_folders @created_folders ||= [] end
verify!()
click to toggle source
# File lib/deploy/s3/configuration.rb, line 9 def verify! unless config_bucket.exists? && objects.count > 0 fail "Configuration bucket #{@config_bucket_name} not found or empty." end enforce_valid_app_paths! @verified = true end
Private Instance Methods
app_buckets()
click to toggle source
# File lib/deploy/s3/configuration.rb, line 84 def app_buckets @app_buckets ||= app_buckets_list end
app_buckets_list()
click to toggle source
# File lib/deploy/s3/configuration.rb, line 88 def app_buckets_list ErrorHandler.with_error_handling do objects.select do |o| !o.key.empty? && o.key.end_with?('/') && o.key.count('/') == 1 end end end
app_names()
click to toggle source
# File lib/deploy/s3/configuration.rb, line 98 def app_names app_buckets.map{|o| o.key.sub('/', '') } end
client()
click to toggle source
# File lib/deploy/s3/configuration.rb, line 41 def client @client ||= ErrorHandler.with_error_handling { Aws::S3::Client.new } end
config_bucket()
click to toggle source
# File lib/deploy/s3/configuration.rb, line 32 def config_bucket @config_bucket ||= ErrorHandler.with_error_handling { Aws::S3::Bucket.new(@config_bucket_name) } end
create_folder!(folder)
click to toggle source
# File lib/deploy/s3/configuration.rb, line 67 def create_folder!(folder) ErrorHandler.with_error_handling do client.put_object( acl: 'private', body: nil, bucket: config_bucket.name, key: folder ) end end
enforce_valid_app_paths!()
click to toggle source
# File lib/deploy/s3/configuration.rb, line 45 def enforce_valid_app_paths! # check folders in our config bucket, recreate any missing folders object_names = objects.map(&:key) file_names = object_names.select { |name| !name.end_with?('/') } max_depth = object_names.map { |name| name.count('/') }.max possible_object_names = (1..max_depth).reduce([]) { |list, depth| list += object_names.map { |name| name.split('/').first(depth).join('/') } } folder_names = possible_object_names.uniq - file_names path_names = folder_names.map { |folder| folder + '/' } # Make the folder if needed folders_to_create = path_names. sort_by { |name| name.count('/') }. select{|folder| ! folder_exists?(folder) } folders_to_create.each do |folder| create_folder!(folder) end @created_folders = folders_to_create end
folder_exists?(folder)
click to toggle source
# File lib/deploy/s3/configuration.rb, line 78 def folder_exists?(folder) ErrorHandler.with_error_handling do config_bucket.object(folder).exists? end end
objects()
click to toggle source
# File lib/deploy/s3/configuration.rb, line 37 def objects @objects ||= ErrorHandler.with_error_handling { config_bucket.objects } end