class Hako::EnvProviders::S3

Constants

VERSION

Public Class Methods

new(_root_path, options) click to toggle source
# File lib/hako/env_providers/s3.rb, line 12
def initialize(_root_path, options)
  %w(bucket_name object_path region).each do |k|
    unless options[k]
      validation_error!("required option #{k} must be specified")
    end
    aws_opts = {
      region: options.fetch('region')
    }
    if options.has_key?('profile')
      aws_opts.merge!(profile: options['profile'])
    end
    
    Aws.config.merge!(aws_opts)
    bucket_name = options.fetch('bucket_name')
    object_path = options.fetch('object_path')
    bucket = Aws::S3::Bucket.new(bucket_name)
    object = bucket.object(object_path)
    
    unless object.exists?
      validation_error!("#{bucket_name}/#{object_path} does not exist or is not readable")
    end
    
    @data = JSON.parse(object.body.read)
  end
end

Public Instance Methods

ask(variables) click to toggle source
# File lib/hako/env_providers/s3.rb, line 38
def ask(variables)
  env = {}
  variables.each do |k|
    env[k] = @data.fetch(k, nil)
  end
  env
end
ask_keys(variables) click to toggle source
# File lib/hako/env_providers/s3.rb, line 50
def ask_keys(variables)
  @data.select { |k,v| variables.include?(k) }
end
can_ask_keys?() click to toggle source
# File lib/hako/env_providers/s3.rb, line 46
def can_ask_keys?
  true
end

Private Instance Methods

validation_error!(message) click to toggle source
# File lib/hako/env_providers/s3.rb, line 56
def validation_error!(message)
  raise ValidationError.new(message)
end