Sha256: bb3c8829a7cab40739f200c254449d368e39d190a3b31d82490809dd2f4e8cd0

Contents?: true

Size: 1.25 KB

Versions: 34

Compression:

Stored size: 1.25 KB

Contents

require 'fog/aws'

# This module holds the connections for all AWS services used by the gem.
module Dockly::AWS
  extend self

  def service(name, klass)
    define_method name do
      if val = instance_variable_get(:"@#{name}")
        val
      else
        instance = klass.new(creds)
        instance_variable_set(:"@#{name}", instance)
      end
    end
    services << name
  end

  def services
    @services ||= []
  end

  def env_attr(*names)
    names.each do |name|
      define_method name do
        instance_variable_get(:"@#{name}") || ENV[name.to_s.upcase]
      end

      define_method :"#{name}=" do |val|
        reset_cache!
        instance_variable_set(:"@#{name}", val)
      end

      env_attrs << name
    end
  end

  def env_attrs
    @env_attrs ||= []
  end

  def creds
    attrs = Hash[env_attrs.map { |attr| [attr, public_send(attr)] }].reject { |k, v| v.nil? }
    if attrs.empty?
      if ENV['FOG_CREDENTIAL']
        attrs = {} # let Fog use the env var
      else
        attrs = { :use_iam_profile => true }
      end
    end
    attrs
  end

  def reset_cache!
    services.each { |service| instance_variable_set(:"@#{service}", nil) }
  end

  service :s3, Fog::Storage::AWS
  env_attr :aws_access_key_id, :aws_secret_access_key
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
dockly-1.5.8 lib/dockly/aws.rb
dockly-1.5.7 lib/dockly/aws.rb
dockly-1.5.6 lib/dockly/aws.rb
dockly-1.5.5 lib/dockly/aws.rb
dockly-1.5.4 lib/dockly/aws.rb
dockly-1.5.3 lib/dockly/aws.rb
dockly-1.5.2 lib/dockly/aws.rb
dockly-1.5.1 lib/dockly/aws.rb
dockly-1.5.0 lib/dockly/aws.rb
dockly-1.4.9 lib/dockly/aws.rb
dockly-1.4.8 lib/dockly/aws.rb
dockly-1.4.7 lib/dockly/aws.rb
dockly-1.4.6 lib/dockly/aws.rb
dockly-1.4.5 lib/dockly/aws.rb
dockly-1.4.4 lib/dockly/aws.rb
dockly-1.4.3 lib/dockly/aws.rb
dockly-1.4.2 lib/dockly/aws.rb
dockly-1.4.1 lib/dockly/aws.rb
dockly-1.4.0 lib/dockly/aws.rb
dockly-1.3.5 lib/dockly/aws.rb