Sha256: 3d3da04b0669c9fd4e702a13f7d25197f1242881b4e2f1564a7c55620bffcc53

Contents?: true

Size: 810 Bytes

Versions: 4

Compression:

Stored size: 810 Bytes

Contents

# frozen_string_literal: true
require 'proxy_rb/password_fetchers/basic_password_fetcher'
require 'proxy_rb/user_passwords/environment_user_password'

module ProxyRb
  # Fetch password for user...
  module PasswordFetchers
    # ... process environment
    class EnvironmentPasswordFetcher < BasicPasswordFetcher
      include Contracts::Core
      include Contracts::Builtin

      protected

      attr_reader :prefix

      public

      # Prefix of key in Environment
      def initialize(prefix:)
        @prefix = prefix
      end

      # @param [String] user_name
      #   Look up user name
      Contract String => String
      def call(user_name)
        UserPasswords::EnvironmentUserPassword.new(
          ENV[format('%s_%s', prefix, user_name.upcase)]
        ).to_s
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
proxy_rb-0.4.0 lib/proxy_rb/password_fetchers/environment_password_fetcher.rb
proxy_rb-0.3.0 lib/proxy_rb/password_fetchers/environment_password_fetcher.rb
proxy_rb-0.2.1 lib/proxy_rb/password_fetchers/environment_password_fetcher.rb
proxy_rb-0.2.0 lib/proxy_rb/password_fetchers/environment_password_fetcher.rb