Sha256: 90dfbb0100e24ab9e3588fe32b844ee2d0d1426b3561ec9eeb0b847952aca017

Contents?: true

Size: 1021 Bytes

Versions: 5

Compression:

Stored size: 1021 Bytes

Contents

module SecretEnv
  module Storage
    class << self
      def setup(config)
        if config
          klass(config.fetch('type')).new(namespace: config['namespace'])
        else
          Storage::Plain.new
        end
      end

      private

      def klass(type)
        case type
        when 'plain'
          Storage::Plain
        when 'credstash'
          Storage::CredStash
        else
          raise "Unknown storage type: #{type}"
        end
      end
    end

    class Base
      attr_reader :namespace

      def initialize(namespace: '')
        @namespace = namespace
      end

      def retrieve(secret_key)
        raise NotImplemedError
      end

      private

      def full_key(secret_key)
        "#{namespace}#{secret_key}"
      end
    end

    class Plain < Base
      def retrieve(secret_key)
        "#\{#{full_key(secret_key)}\}"
      end
    end

    class CredStash < Base
      def retrieve(secret_key)
        ::CredStash.get(full_key(secret_key))
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
secret_env-0.4.0 lib/secret_env/storage.rb
secret_env-0.3.2 lib/secret_env/storage.rb
secret_env-0.3.1 lib/secret_env/storage.rb
secret_env-0.3.0 lib/secret_env/storage.rb
secret_env-0.2.0 lib/secret_env/storage.rb