Sha256: a1ed190998ed5ed0da4cc7772484588ebe90bd26efbd05f8efd97b38f9e5fe47

Contents?: true

Size: 1.82 KB

Versions: 4

Compression:

Stored size: 1.82 KB

Contents

require "httpi/auth/ssl"

module HTTPI
  module Auth

    # = HTTPI::Auth::Config
    #
    # Manages HTTP and SSL auth configuration. Currently supports HTTP basic/digest
    # and SSL client authentication.
    class Config

      # Supported authentication types.
      TYPES = [:basic, :digest, :ssl]

      # Accessor for the HTTP basic auth credentials.
      def basic(*args)
        return @basic if args.empty?

        self.type = :basic
        @basic = args.flatten.compact
      end

      # Returns whether to use HTTP basic auth.
      def basic?
        type == :basic
      end

      # Accessor for the HTTP digest auth credentials.
      def digest(*args)
        return @digest if args.empty?

        self.type = :digest
        @digest = args.flatten.compact
      end

      # Returns whether to use HTTP digest auth.
      def digest?
        type == :digest
      end

      # Returns whether to use HTTP basic or dihest auth.
      def http?
        type == :basic || type == :digest
      end

      # Only available with the httpi-ntlm gem.
      def ntlm(*args)
        raise "Install the httpi-ntlm gem for experimental NTLM support"
      end

      # Only available with the httpi-ntlm gem.
      def ntlm?
        raise "Install the httpi-ntlm gem for experimental NTLM support"
      end

      # Returns the <tt>HTTPI::Auth::SSL</tt> object.
      def ssl
        @ssl ||= SSL.new
      end

      # Returns whether to use SSL client auth.
      def ssl?
        ssl.present?
      end

      # Shortcut method for returning the credentials for the authentication specified.
      # Returns +nil+ unless any authentication credentials were specified.
      def credentials
        return unless type
        send type
      end

      # Accessor for the authentication type in use.
      attr_accessor :type

    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/gems/httpi-0.9.7/lib/httpi/auth/config.rb
httpi-0.9.7 lib/httpi/auth/config.rb
httpi-0.9.6 lib/httpi/auth/config.rb
httpi-0.9.5 lib/httpi/auth/config.rb