def create_authenticator(self, connection, debug=False, **kwargs): """Create the AMQP session and the CBS channel with which to negotiate the token. :param connection: The underlying AMQP connection on which to create the session. :type connection: ~uamqp.connection.Connection :param debug: Whether to emit network trace logging events for the CBS session. Default is `False`. Logging events are set at INFO level. :type debug: bool :rtype: uamqp.c_uamqp.CBSTokenAuth """ self._connection = connection self._session = Session(connection, **kwargs) try: self._cbs_auth = c_uamqp.CBSTokenAuth( self.audience, self.token_type, self.token, int(self.expires_at), self._session._session, # pylint: disable=protected-access self.timeout, self._connection.container_id) self._cbs_auth.set_trace(debug) except ValueError: self._session.destroy() raise errors.AMQPConnectionError( "Unable to open authentication session on connection {}.\n" "Please confirm target hostname exists: {}".format( connection.container_id, connection.hostname)) return self._cbs_auth
def create_authenticator(self, connection, debug=False): """Create the AMQP session and the CBS channel with which to negotiate the token. :param connection: The underlying AMQP connection on which to create the session. :type connection: ~uamqp.Connection :param debug: Whether to emit network trace logging events for the CBS session. Default is `False`. Logging events are set at INFO level. :type debug: bool :returns: ~uamqp.c_uamqp.CBSTokenAuth """ self._lock = threading.Lock() self._session = Session( connection, incoming_window=constants.MAX_FRAME_SIZE_BYTES, outgoing_window=constants.MAX_FRAME_SIZE_BYTES) try: self._cbs_auth = c_uamqp.CBSTokenAuth( self.audience, self.token_type, self.token, int(self.expires_at), self._session._session, # pylint: disable=protected-access self.timeout) self._cbs_auth.set_trace(debug) except ValueError: raise errors.AMQPConnectionError( "Unable to open authentication session. " "Please confirm target URI exists.") return self._cbs_auth
async def create_authenticator_async(self, connection, debug=False, loop=None, **kwargs): """Create the async AMQP session and the CBS channel with which to negotiate the token. :param connection: The underlying AMQP connection on which to create the session. :type connection: ~uamqp.async_ops.connection_async.ConnectionAsync :param debug: Whether to emit network trace logging events for the CBS session. Default is `False`. Logging events are set at INFO level. :type debug: bool :param loop: A user specified event loop. :type loop: ~asycnio.AbstractEventLoop :rtype: uamqp.c_uamqp.CBSTokenAuth """ self.loop = loop or get_running_loop() self._connection = connection self._session = SessionAsync(connection, loop=self.loop, **kwargs) if self.token_type == b'jwt': # Async initialize the jwt token await self.update_token() try: self._cbs_auth = c_uamqp.CBSTokenAuth( self.audience, self.token_type, self.token, int(self.expires_at), self._session._session, # pylint: disable=protected-access self.timeout, self._connection.container_id) self._cbs_auth.set_trace(debug) except ValueError: await self._session.destroy_async() raise errors.AMQPConnectionError( "Unable to open authentication session on connection {}.\n" "Please confirm target hostname exists: {}".format( connection.container_id, connection.hostname)) from None return self._cbs_auth
async def create_authenticator_async(self, connection, debug=False, loop=None, **kwargs): """Create the async AMQP session and the CBS channel with which to negotiate the token. :param connection: The underlying AMQP connection on which to create the session. :type connection: ~uamqp.async_ops.connection_async.ConnectionAsync :param debug: Whether to emit network trace logging events for the CBS session. Default is `False`. Logging events are set at INFO level. :type debug: bool :rtype: uamqp.c_uamqp.CBSTokenAuth """ self._internal_kwargs = get_dict_with_loop_if_needed(loop) self._connection = connection kwargs.update(self._internal_kwargs) self._session = SessionAsync(connection, **kwargs) try: self._cbs_auth = c_uamqp.CBSTokenAuth( self.audience, self.token_type, self.token, int(self.expires_at), self._session._session, # pylint: disable=protected-access self.timeout, self._connection.container_id, self._refresh_window) self._cbs_auth.set_trace(debug) except ValueError: await self._session.destroy_async() raise errors.AMQPConnectionError( "Unable to open authentication session on connection {}.\n" "Please confirm target hostname exists: {}".format( connection.container_id, connection.hostname)) from None return self._cbs_auth
async def create_authenticator_async(self, connection, debug=False, loop=None): """Create the async AMQP session and the CBS channel with which to negotiate the token. :param connection: The underlying AMQP connection on which to create the session. :type connection: ~uamqp.async.ConnectionAsync :param debug: Whether to emit network trace logging events for the CBS session. Default is `False`. Logging events are set at INFO level. :type debug: bool :param loop: A user specified event loop. :type loop: ~asycnio.AbstractEventLoop :returns: ~uamqp.c_uamqp.CBSTokenAuth """ self.loop = loop or asyncio.get_event_loop() self._lock = asyncio.Lock(loop=self.loop) self._session = SessionAsync( connection, incoming_window=constants.MAX_FRAME_SIZE_BYTES, outgoing_window=constants.MAX_FRAME_SIZE_BYTES, loop=self.loop) try: self._cbs_auth = c_uamqp.CBSTokenAuth( self.audience, self.token_type, self.token, int(self.expires_at), self._session._session, # pylint: disable=protected-access self.timeout) self._cbs_auth.set_trace(debug) except ValueError: raise errors.AMQPConnectionError( "Unable to open authentication session. " "Please confirm target URI exists.") from None return self._cbs_auth