class Renv::Connection

Public Class Methods

new(app: nil, bucket: bucket) click to toggle source
Calls superclass method
# File lib/renv/connection.rb, line 8
def initialize(app: nil, bucket: bucket)
  @_app     = app
  @_bucket  = bucket

  connection = Fog::Storage.new(
    provider:              'AWS',
    aws_access_key_id:     ENV.fetch("RENV_AWS_KEY_#{_app}"),
    aws_secret_access_key: ENV.fetch("RENV_AWS_SECRET_#{_app}"),
    region:                ENV.fetch("RENV_AWS_REGION_#{_app}", 'eu-west-1')
  )

  if connection.nil?
    $stderr.puts "Failed to connect to AWS, please check your key and secret."
    exit 1
  end

  bucket = connection.directories.get(_bucket).tap do |b|
    if b.nil?
      $stderr.puts "Bucket '#{_bucket}' does not seem to exist"
      exit 1
    end
  end

  super bucket

rescue Excon::Errors::Forbidden
  $stderr.puts "Credentials rejected by AWS, please check your settings."
  exit 1
end

Public Instance Methods

app_name() click to toggle source
# File lib/renv/connection.rb, line 39
def app_name ; _app ; end

Private Instance Methods

_app() click to toggle source
# File lib/renv/connection.rb, line 43
def _app
  @_app ||= ENV.fetch('RENV_APP')
end
_bucket() click to toggle source
# File lib/renv/connection.rb, line 47
def _bucket
  @_bucket ||= ENV.fetch("RENV_BUCKET_#{_app}")
end