Sha256: 17c4bb9b38548e814a3a7f5da31cec3f346f9fdf672eaa429ac0665b1ffbdca5

Contents?: true

Size: 1.5 KB

Versions: 62

Compression:

Stored size: 1.5 KB

Contents

module Workarea
  module Configuration
    class S3
      class << self
        def internal
          @dragonfly ||= new(:s3)
        end

        def integration
          @integration ||= new(:s3_integration)
        end

        delegate_missing_to :internal
      end

      def initialize(slug)
        @slug = slug
        @config = config.presence || secrets.presence || credentials.presence || {}
      end

      def region
        ENV["#{prefix}_REGION"].presence || @config[:region].presence || 'us-east-1'
      end

      def bucket
        configured_bucket.presence || 'test'
      end

      def access_key_id
        ENV["#{prefix}_ACCESS_KEY_ID"].presence || @config[:access_key_id]
      end

      def secret_access_key
        ENV["#{prefix}_SECRET_ACCESS_KEY"].presence || @config[:secret_access_key]
      end

      def use_iam_profile?
        access_key_id.blank? && secret_access_key.blank?
      end

      def configured?
        configured_bucket.present?
      end

      private

      def prefix
        @prefix ||= "WORKAREA_#{@slug.to_s.underscore.upcase}"
      end

      def config
        Workarea.config.send(@slug).to_h.with_indifferent_access
      end

      def secrets
        Rails.application.secrets.send(@slug).to_h.with_indifferent_access
      end

      def credentials
        Rails.application.credentials.send(@slug).to_h.with_indifferent_access
      end

      def configured_bucket
        ENV["#{prefix}_BUCKET_NAME"].presence || @config[:bucket_name]
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 lib/workarea/configuration/s3.rb
workarea-core-3.5.26 lib/workarea/configuration/s3.rb
workarea-core-3.4.45 lib/workarea/configuration/s3.rb
workarea-core-3.5.25 lib/workarea/configuration/s3.rb
workarea-core-3.5.23 lib/workarea/configuration/s3.rb
workarea-core-3.4.44 lib/workarea/configuration/s3.rb
workarea-core-3.5.22 lib/workarea/configuration/s3.rb
workarea-core-3.4.43 lib/workarea/configuration/s3.rb
workarea-core-3.5.21 lib/workarea/configuration/s3.rb
workarea-core-3.4.42 lib/workarea/configuration/s3.rb
workarea-core-3.5.20 lib/workarea/configuration/s3.rb
workarea-core-3.4.41 lib/workarea/configuration/s3.rb
workarea-core-3.5.19 lib/workarea/configuration/s3.rb
workarea-core-3.4.40 lib/workarea/configuration/s3.rb
workarea-core-3.5.18 lib/workarea/configuration/s3.rb
workarea-core-3.4.39 lib/workarea/configuration/s3.rb
workarea-core-3.5.17 lib/workarea/configuration/s3.rb
workarea-core-3.4.38 lib/workarea/configuration/s3.rb
workarea-core-3.5.16 lib/workarea/configuration/s3.rb
workarea-core-3.4.37 lib/workarea/configuration/s3.rb