def process(self, response=None, error=None): if error: logging.debug("Error during authentication: %r", error) self._error(AuthenticationError(error)) return if self._state == "start": self._state = "nonce" logging.debug("Sending nonce") msg = message.query(0, "%s.$cmd" % self.pool._dbname, 0, 1, SON({'getnonce': 1}), SON({})) self.connection._send_message(msg, self.process) elif self._state == "nonce": # this is the nonce response self._state = "finish" try: nonce = response['data'][0]['nonce'] logging.debug("Nonce received: %r", nonce) key = helpers._auth_key(nonce, self.dbuser, self.dbpass) except Exception, e: self._error(AuthenticationError(e)) return msg = message.query( 0, "%s.$cmd" % self.pool._dbname, 0, 1, SON([('authenticate', 1), ('user', self.dbuser), ('nonce', nonce), ('key', key)]), SON({})) self.connection._send_message(msg, self.process)
def _start_authentication(self, response, error=None): # this is the nonce response if error: logging.error(error) logging.error(response) raise AuthenticationError(error) nonce = response['data'][0]['nonce'] key = helpers._auth_key(nonce, self.__dbuser, self.__dbpass) self.__callback = self._finish_authentication self._send_message( message.query( 0, "%s.$cmd" % self.__pool._dbname, 0, 1, SON([('authenticate', 1), ('user', self.__dbuser), ('nonce', nonce), ('key', key)]), SON({})))
def process(self, response=None, error=None): if error: logging.debug(error) logging.debug(response) raise AuthenticationError(error) if self._state == "start": self._state = "nonce" logging.debug("Sending nonce") msg = message.query( 0, "%s.$cmd" % self.pool._dbname, 0, 1, SON({'getnonce': 1}), SON({}) ) self.connection._send_message(msg, self.process) elif self._state == "nonce": # this is the nonce response self._state = "finish" nonce = response['data'][0]['nonce'] logging.debug("Nonce received: %r", nonce) key = helpers._auth_key(nonce, self.dbuser, self.dbpass) msg = message.query( 0, "%s.$cmd" % self.pool._dbname, 0, 1, SON([('authenticate', 1), ('user', self.dbuser), ('nonce', nonce), ('key', key)]), SON({}) ) self.connection._send_message(msg, self.process) elif self._state == "finish": self._state = "done" assert response['number_returned'] == 1 response = response['data'][0] if response['ok'] != 1: logging.debug('Failed authentication %s' % response['errmsg']) raise AuthenticationError(response['errmsg']) self.connection._next_job() else: raise ValueError("Unexpected state: %s" % self._state)
def _start_authentication(self, response, error=None): # this is the nonce response if error: logging.error(error) logging.error(response) raise AuthenticationError(error) nonce = response['data'][0]['nonce'] key = helpers._auth_key(nonce, self.__dbuser, self.__dbpass) self.__callback = self._finish_authentication self._send_message( message.query(0, "%s.$cmd" % self.__pool._dbname, 0, 1, SON([('authenticate', 1), ('user' , self.__dbuser), ('nonce' , nonce), ('key' , key)]), SON({})))
def process(self, response=None, error=None): if error: logging.debug("Error during authentication: %r", error) self._error(AuthenticationError(error)) return if self._state == "start": self._state = "nonce" logging.debug("Sending nonce") msg = message.query( 0, "%s.$cmd" % self.pool._dbname, 0, 1, SON({'getnonce': 1}), SON({}) ) self.connection._send_message(msg, self.process) elif self._state == "nonce": # this is the nonce response self._state = "finish" try: nonce = response['data'][0]['nonce'] logging.debug("Nonce received: %r", nonce) key = helpers._auth_key(nonce, self.dbuser, self.dbpass) except Exception, e: self._error(AuthenticationError(e)) return msg = message.query( 0, "%s.$cmd" % self.pool._dbname, 0, 1, SON([('authenticate', 1), ('user', self.dbuser), ('nonce', nonce), ('key', key)]), SON({}) ) self.connection._send_message(msg, self.process)
def process(self, response=None, error=None): if error: logging.debug(error) logging.debug(response) raise AuthenticationError(error) if self._state == "start": self._state = "nonce" logging.debug("Sending nonce") msg = message.query(0, "%s.$cmd" % self.pool._dbname, 0, 1, SON({"getnonce": 1}), SON({})) self.connection._send_message(msg, self.process) elif self._state == "nonce": # this is the nonce response self._state = "finish" nonce = response["data"][0]["nonce"] logging.debug("Nonce received: %r", nonce) key = helpers._auth_key(nonce, self.dbuser, self.dbpass) msg = message.query( 0, "%s.$cmd" % self.pool._dbname, 0, 1, SON([("authenticate", 1), ("user", self.dbuser), ("nonce", nonce), ("key", key)]), SON({}), ) self.connection._send_message(msg, self.process) elif self._state == "finish": self._state = "done" assert response["number_returned"] == 1 response = response["data"][0] if response["ok"] != 1: logging.debug("Failed authentication %s" % response["errmsg"]) raise AuthenticationError(response["errmsg"]) self.connection._next_job() else: raise ValueError("Unexpected state: %s" % self._state)