Module: Aerospike::Connection::AuthenticateNew

Defined in:
lib/aerospike/connection/authenticate.rb

Constant Summary collapse

INVALID_SESSION_ERR =
[ResultCode::INVALID_CREDENTIAL,
ResultCode::EXPIRED_SESSION]

Class Method Summary collapse

Class Method Details

.call(conn, cluster) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/aerospike/connection/authenticate.rb', line 39

def call(conn, cluster)
  command = LoginCommand.new
  if cluster.session_valid?
    begin
      command.authenticate_via_token(conn, cluster)
    rescue => ae
      # always reset session info on errors to be on the safe side
      cluster.reset_session_info
      if ae.is_a?(Exceptions::Aerospike)
        if INVALID_SESSION_ERR.include?(ae.result_code)
          command.authenticate_new(conn, cluster)
          return true
        end
      end
      raise ae
    end
  else
    command.authenticate_new(conn, cluster)
  end

  true
rescue ::Aerospike::Exceptions::Aerospike
  conn.close if conn
  raise ::Aerospike::Exceptions::InvalidCredentials
end