Sha256: af590ef46ca3c2a1285992fc23be8dfca4f60b5e5ae0ecd31f14e897891ba6c8

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

module ManageIQ
  module API
    class Client
      class Authentication
        attr_reader :user
        attr_reader :password
        attr_reader :token
        attr_reader :miqtoken
        attr_reader :bearer_token
        attr_reader :group

        DEFAULTS = {
          :user     => "admin",
          :password => "smartvm"
        }.freeze

        CUSTOM_INSPECT_EXCLUSIONS = %i[@password @token @miqtoken @bearer_token].freeze
        include CustomInspectMixin

        def initialize(options = {})
          @user, @password = fetch_credentials(options)
          @token, @miqtoken, @bearer_token, @group = options.values_at(:token, :miqtoken, :bearer_token, :group)

          unless token || miqtoken || bearer_token
            raise "Must specify both a user and a password" if user.blank? || password.blank?
          end
        end

        def self.auth_options_specified?(options)
          options.slice(:user, :password, :token, :miqtoken, :bearer_token, :group).present?
        end

        private

        def fetch_credentials(options)
          if options.slice(:user, :password, :token, :miqtoken, :bearer_token).blank?
            [DEFAULTS[:user], DEFAULTS[:password]]
          else
            [options[:user], options[:password]]
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
manageiq-api-client-0.6.0 lib/manageiq/api/client/authentication.rb
manageiq-api-client-0.4.0 lib/manageiq/api/client/authentication.rb