Sha256: 940094f9f6fdf06bf4d4bd1b578712ababdbf6140acd5d0cd08a2d892d969cc2

Contents?: true

Size: 1.13 KB

Versions: 20

Compression:

Stored size: 1.13 KB

Contents

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

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

      protected

      attr_reader :fetchers

      public

      # Prefix of key in Environment
      def initialize(fetchers)
        @fetchers = Array(fetchers)
      end

      # @param [String] user_name
      #   Look up user name
      Contract String => String
      def call(user_name)
        fetch_password_for_user(user_name)
      end

      private

      def fetch_password_for_user(user_name)
        result = nil

        fetchers.each do |f|
          begin
            result = f.call(user_name)
          rescue ArgumentError
            result = nil
          end

          break unless result.nil?
        end

        raise ArgumentError, %(Failed to fetch password for username "#{user_name}") if result.nil?

        result
      end

      # Not needed for this fetcher
      def read(_string); end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
proxy_rb-1.0.0 lib/proxy_rb/password_fetchers/chaining_password_fetcher.rb
proxy_rb-0.10.6 lib/proxy_rb/password_fetchers/chaining_password_fetcher.rb
proxy_rb-0.10.5 lib/proxy_rb/password_fetchers/chaining_password_fetcher.rb
proxy_rb-0.10.4 lib/proxy_rb/password_fetchers/chaining_password_fetcher.rb
proxy_rb-0.10.3 lib/proxy_rb/password_fetchers/chaining_password_fetcher.rb
proxy_rb-0.10.2 lib/proxy_rb/password_fetchers/chaining_password_fetcher.rb
proxy_rb-0.10.1 lib/proxy_rb/password_fetchers/chaining_password_fetcher.rb
proxy_rb-0.10.0 lib/proxy_rb/password_fetchers/chaining_password_fetcher.rb
proxy_rb-0.9.3 lib/proxy_rb/password_fetchers/chaining_password_fetcher.rb
proxy_rb-0.9.2 lib/proxy_rb/password_fetchers/chaining_password_fetcher.rb
proxy_rb-0.9.1 lib/proxy_rb/password_fetchers/chaining_password_fetcher.rb
proxy_rb-0.9.0 lib/proxy_rb/password_fetchers/chaining_password_fetcher.rb
proxy_rb-0.8.3 lib/proxy_rb/password_fetchers/chaining_password_fetcher.rb
proxy_rb-0.8.2 lib/proxy_rb/password_fetchers/chaining_password_fetcher.rb
proxy_rb-0.8.1 lib/proxy_rb/password_fetchers/chaining_password_fetcher.rb
proxy_rb-0.8.0 lib/proxy_rb/password_fetchers/chaining_password_fetcher.rb
proxy_rb-0.7.1 lib/proxy_rb/password_fetchers/chaining_password_fetcher.rb
proxy_rb-0.7.0 lib/proxy_rb/password_fetchers/chaining_password_fetcher.rb
proxy_rb-0.6.0 lib/proxy_rb/password_fetchers/chaining_password_fetcher.rb
proxy_rb-0.5.0 lib/proxy_rb/password_fetchers/chaining_password_fetcher.rb