Sha256: 42bee7cbe3573e333f814b67b64312789b33d6da207af97c5552715e02277cb1

Contents?: true

Size: 1.29 KB

Versions: 33

Compression:

Stored size: 1.29 KB

Contents

require 'fog/aws'

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

  autoload :S3Writer, 'dockly/aws/s3_writer'

  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

33 entries across 33 versions & 1 rubygems

Version Path
dockly-2.7.2 lib/dockly/aws.rb
dockly-2.7.1 lib/dockly/aws.rb
dockly-2.7.0 lib/dockly/aws.rb
dockly-1.13.0 lib/dockly/aws.rb
dockly-2.6.0 lib/dockly/aws.rb
dockly-1.12.3 lib/dockly/aws.rb
dockly-2.5.3 lib/dockly/aws.rb
dockly-1.12.2 lib/dockly/aws.rb
dockly-2.5.2 lib/dockly/aws.rb
dockly-1.12.1 lib/dockly/aws.rb
dockly-2.5.1 lib/dockly/aws.rb
dockly-1.12.0 lib/dockly/aws.rb
dockly-2.5.0 lib/dockly/aws.rb
dockly-1.11.0 lib/dockly/aws.rb
dockly-2.4.0 lib/dockly/aws.rb
dockly-2.3.0 lib/dockly/aws.rb
dockly-1.10.0 lib/dockly/aws.rb
dockly-1.9.0 lib/dockly/aws.rb
dockly-1.8.0 lib/dockly/aws.rb
dockly-2.2.0 lib/dockly/aws.rb