lib/mongo/auth/x509/conversation.rb in mongo-2.4.3 vs lib/mongo/auth/x509/conversation.rb in mongo-2.5.0.beta

- old
+ new

@@ -25,11 +25,11 @@ # The login message. # # @since 2.0.0 LOGIN = { authenticate: 1 }.freeze - # @return [ Protocol::Reply ] reply The current reply in the + # @return [ Protocol::Message ] reply The current reply in the # conversation. attr_reader :reply # @return [ User ] user The user for the conversation. attr_reader :user @@ -38,11 +38,11 @@ # the provided reply indicates the conversation is finished. # # @example Finalize the conversation. # conversation.finalize(reply) # - # @param [ Protocol::Reply ] reply The reply of the previous + # @param [ Protocol::Message ] reply The reply of the previous # message. # # @return [ Protocol::Query ] The next message to send. # # @since 2.0.0 @@ -54,21 +54,31 @@ # needs to be send to the server. # # @example Start the conversation. # conversation.start # + # @param [ Mongo::Server::Connection ] connection The connection being authenticated. + # # @return [ Protocol::Query ] The first x.509 conversation message. # # @since 2.0.0 - def start + def start(connection = nil) login = LOGIN.merge(mechanism: X509::MECHANISM) login[:user] = user.name if user.name - Protocol::Query.new( - Auth::EXTERNAL, - Database::COMMAND, - login, - limit: -1 - ) + if connection && connection.features.op_msg_enabled? + selector = login + selector[Protocol::Msg::DATABASE_IDENTIFIER] = user.auth_source + cluster_time = connection.mongos? && connection.cluster_time + selector[Operation::CLUSTER_TIME] = cluster_time if cluster_time + Protocol::Msg.new([:none], {}, selector) + else + Protocol::Query.new( + Auth::EXTERNAL, + Database::COMMAND, + login, + limit: -1 + ) + end end # Create the new conversation. # # @example Create the new conversation.