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.15 lib/workarea/configuration/s3.rb
workarea-core-3.4.36 lib/workarea/configuration/s3.rb
workarea-core-3.5.14 lib/workarea/configuration/s3.rb
workarea-core-3.4.35 lib/workarea/configuration/s3.rb
workarea-core-3.5.13 lib/workarea/configuration/s3.rb
workarea-core-3.4.34 lib/workarea/configuration/s3.rb
workarea-core-3.5.12 lib/workarea/configuration/s3.rb
workarea-core-3.4.33 lib/workarea/configuration/s3.rb
workarea-core-3.5.11 lib/workarea/configuration/s3.rb
workarea-core-3.5.10 lib/workarea/configuration/s3.rb
workarea-core-3.4.32 lib/workarea/configuration/s3.rb
workarea-core-3.5.9 lib/workarea/configuration/s3.rb
workarea-core-3.4.31 lib/workarea/configuration/s3.rb
workarea-core-3.5.8 lib/workarea/configuration/s3.rb
workarea-core-3.4.30 lib/workarea/configuration/s3.rb
workarea-core-3.5.7 lib/workarea/configuration/s3.rb
workarea-core-3.4.29 lib/workarea/configuration/s3.rb
workarea-core-3.5.6 lib/workarea/configuration/s3.rb
workarea-core-3.4.28 lib/workarea/configuration/s3.rb
workarea-core-3.5.5 lib/workarea/configuration/s3.rb