How to use the kazoo.exceptions.AuthFailedError function in kazoo

To help you get started, we’ve selected a few kazoo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github python-zk / kazoo / kazoo / protocol / connection.py View on Github external
except puresasl.SASLError as err:
                six.reraise(
                    SASLException,
                    SASLException('library error: %s' % err.message),
                    sys.exc_info()[2]
                )
            except puresasl.SASLProtocolException as err:
                six.reraise(
                    AuthFailedError,
                    AuthFailedError('protocol error: %s' % err.message),
                    sys.exc_info()[2]
                )
            except Exception as err:
                six.reraise(
                    AuthFailedError,
                    AuthFailedError('Unknown error: %s' % err),
                    sys.exc_info()[2]
                )

            if sasl_cli.complete and not response:
                break
            elif response is None:
                response = b''

            xid = (xid % 2147483647) + 1

            request = SASL(response)
            self._submit(request, timeout, xid)

            try:
                header, buffer, offset = self._read_header(timeout)
            except ConnectionDropped:
github python-zk / kazoo / kazoo / protocol / connection.py View on Github external
break
            elif response is None:
                response = b''

            xid = (xid % 2147483647) + 1

            request = SASL(response)
            self._submit(request, timeout, xid)

            try:
                header, buffer, offset = self._read_header(timeout)
            except ConnectionDropped:
                # Zookeeper simply drops connections with failed authentication
                six.reraise(
                    AuthFailedError,
                    AuthFailedError('Connection dropped in SASL'),
                    sys.exc_info()[2]
                )

            if header.xid != xid:
                raise RuntimeError('xids do not match, expected %r '
                                   'received %r', xid, header.xid)

            if header.zxid > 0:
                self.client.last_zxid = header.zxid

            if header.err:
                callback_exception = EXCEPTIONS[header.err]()
                self.logger.debug(
                    'Received error(xid=%s) %r', xid, callback_exception)
                raise callback_exception
github python-zk / kazoo / kazoo / protocol / connection.py View on Github external
while True:
            if sasl_cli.complete:
                break

            try:
                response = sasl_cli.process(challenge=challenge)
            except puresasl.SASLError as err:
                six.reraise(
                    SASLException,
                    SASLException('library error: %s' % err.message),
                    sys.exc_info()[2]
                )
            except puresasl.SASLProtocolException as err:
                six.reraise(
                    AuthFailedError,
                    AuthFailedError('protocol error: %s' % err.message),
                    sys.exc_info()[2]
                )
            except Exception as err:
                six.reraise(
                    AuthFailedError,
                    AuthFailedError('Unknown error: %s' % err),
                    sys.exc_info()[2]
                )

            if sasl_cli.complete and not response:
                break
            elif response is None:
                response = b''

            xid = (xid % 2147483647) + 1
github python-zk / kazoo / kazoo / client.py View on Github external
def _notify_pending(self, state):
        """Used to clear a pending response queue and request queue
        during connection drops."""
        if state == KeeperState.AUTH_FAILED:
            exc = AuthFailedError()
        elif state == KeeperState.EXPIRED_SESSION:
            exc = SessionExpiredError()
        else:
            exc = ConnectionLoss()

        while True:
            try:
                request, async_object, xid = self._pending.popleft()
                if async_object:
                    async_object.set_exception(exc)
            except IndexError:
                break

        while True:
            try:
                request, async_object = self._queue.popleft()
github python-zk / kazoo / kazoo / protocol / connection.py View on Github external
def _read_socket(self, read_timeout):
        """Called when there's something to read on the socket"""
        client = self.client

        header, buffer, offset = self._read_header(read_timeout)
        if header.xid == PING_XID:
            self.logger.log(BLATHER, 'Received Ping')
            self.ping_outstanding.clear()
        elif header.xid == AUTH_XID:
            self.logger.log(BLATHER, 'Received AUTH')

            request, async_object, xid = client._pending.popleft()
            if header.err:
                async_object.set_exception(AuthFailedError())
                client._session_callback(KeeperState.AUTH_FAILED)
            else:
                async_object.set(True)
        elif header.xid == WATCH_XID:
            self._read_watch_event(buffer, offset)
        else:
            self.logger.log(BLATHER, 'Reading for header %r', header)

            return self._read_response(header, buffer, offset)
github apache / incubator-retired-slider / slider-agent / src / main / python / kazoo / protocol / connection.py View on Github external
def _read_socket(self, read_timeout):
        """Called when there's something to read on the socket"""
        client = self.client

        header, buffer, offset = self._read_header(read_timeout)
        if header.xid == PING_XID:
            self.logger.log(BLATHER, 'Received Ping')
            self.ping_outstanding.clear()
        elif header.xid == AUTH_XID:
            self.logger.log(BLATHER, 'Received AUTH')

            request, async_object, xid = client._pending.popleft()
            if header.err:
                async_object.set_exception(AuthFailedError())
                client._session_callback(KeeperState.AUTH_FAILED)
            else:
                async_object.set(True)
        elif header.xid == WATCH_XID:
            self._read_watch_event(buffer, offset)
        else:
            self.logger.log(BLATHER, 'Reading for header %r', header)

            return self._read_response(header, buffer, offset)
github apache / incubator-retired-slider / slider-agent / src / main / python / kazoo / client.py View on Github external
def _call(self, request, async_object):
        """Ensure there's an active connection and put the request in
        the queue if there is.

        Returns False if the call short circuits due to AUTH_FAILED,
        CLOSED, EXPIRED_SESSION or CONNECTING state.

        """

        if self._state == KeeperState.AUTH_FAILED:
            async_object.set_exception(AuthFailedError())
            return False
        elif self._state == KeeperState.CLOSED:
            async_object.set_exception(ConnectionClosedError(
                "Connection has been closed"))
            return False
        elif self._state in (KeeperState.EXPIRED_SESSION,
                             KeeperState.CONNECTING):
            async_object.set_exception(SessionExpiredError())
            return False

        self._queue.append((request, async_object))

        # wake the connection, guarding against a race with close()
        write_pipe = self._connection._write_pipe
        if write_pipe is None:
            async_object.set_exception(ConnectionClosedError(