Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if session is None:
# detach all sessions from router
for session in list(self._session_id_to_session.values()):
self._detach(session)
detached_session_ids.append(session._session_id)
else:
# detach single session from router
self._detach(session)
detached_session_ids.append(session._session_id)
self.log.info('detached session {session} from realm "{realm}" (authid="{authid}", authrole="{authrole}", detached {detached_session_ids} sessions total) {func}',
func=hltype(self.detach),
session=hlid(session._session_id) if session else '',
authid=hlid(session._authid),
authrole=hlid(session._authrole),
detached_session_ids=hlval(len(detached_session_ids)),
realm=hlid(session._realm))
return detached_session_ids
"""
Stop a service on a Web transport.
:param transport_id: The ID of the transport to stop the Web transport service on.
:type transport_id: str
:param path: The path (absolute URL, eg "/myservice1") of the service to stop.
:type path: str
:param details: Call details.
:type details: :class:`autobahn.wamp.types.CallDetails`
"""
self.log.info('{func}(transport_id={transport_id}, path="{path}")',
func=hltype(self.stop_web_transport_service),
transport_id=hlid(transport_id),
path=hlval(path))
transport = self.transports.get(transport_id, None)
if not transport or \
not isinstance(transport, self.personality.RouterWebTransport) or \
transport.state != self.personality.RouterTransport.STATE_STARTED:
emsg = "Cannot stop service on Web transport: no transport with ID '{}' or transport is not a Web transport".format(transport_id)
self.log.error(emsg)
raise ApplicationError('crossbar.error.not_running', emsg)
if path not in transport.root:
emsg = "Cannot stop service on Web transport {}: no service running on path '{}'".format(transport_id, path)
self.log.error(emsg)
raise ApplicationError('crossbar.error.not_running', emsg)
caller = details.caller if details else None
self.publish(self._uri_prefix + '.on_web_transport_service_stopping',
def restart_component():
# Think: if this below start_component() fails,
# we'll still schedule *exactly one* new re-start
# attempt for it, right?
self.log.info('{func}: now restarting previously closed component {component_id} automatically .. [restart_mode={restart_mode}, was_clean={was_clean}]',
func=hltype(_component_closed),
component_id=hlid(component_id),
restart_mode=hlval(self._restart_mode),
was_clean=hlval(was_clean))
return self.start_component(
component_id, config,
reload_modules=reload_modules,
details=details,
)
def has_realm(self, realm: str) -> bool:
"""
Check if a route to a realm with the given name is currently running.
:param realm: Realm name (_not_ ID).
:type realm: str
:returns: True if a route to the realm exists.
:rtype: bool
"""
result = realm in self._routes
self.log.info('{func}(realm="{realm}") -> {result}', func=hltype(ProxyController.has_realm),
realm=hlid(realm), result=hlval(result))
return result
def has_realm(self, realm: str) -> bool:
"""
Check if a realm with the given name is currently running.
:param realm: Realm name (_not_ ID).
:type realm: str
:returns: True if realm is running.
:rtype: bool
"""
result = realm in self.realm_to_id and self.realm_to_id[realm] in self.realms
self.log.debug('{func}(realm="{realm}") -> {result}', func=hltype(RouterController.has_realm),
realm=hlid(realm), result=hlval(result))
return result
def get_web_transport_service(self, transport_id, path, details=None):
self.log.debug('{func}(transport_id={transport_id}, path="{path}")',
func=hltype(self.get_web_transport_service),
transport_id=hlid(transport_id),
path=hlval(path))
transport = self.transports.get(transport_id, None)
if not transport or \
not isinstance(transport, self.personality.RouterWebTransport) or \
transport.state != self.personality.RouterTransport.STATE_STARTED:
emsg = "No transport with ID '{}' or transport is not a Web transport".format(transport_id)
self.log.debug(emsg)
raise ApplicationError('crossbar.error.not_running', emsg)
if path not in transport.root:
emsg = "Web transport {}: no service running on path '{}'".format(transport_id, path)
self.log.debug(emsg)
raise ApplicationError('crossbar.error.not_running', emsg)
return transport.marshal()
:param path: The path (absolute URL, eg "/myservice1") on which to start the service.
:type path: str
:param config: The Web service configuration.
:type config: dict
:param details: Call details.
:type details: :class:`autobahn.wamp.types.CallDetails`
"""
if not isinstance(config, dict) or 'type' not in config:
raise ApplicationError('crossbar.invalid_argument', 'config parameter must be dict with type attribute')
self.log.info('Starting "{service_type}" Web service on path "{path}" of transport "{transport_id}" {func}',
service_type=hlval(config.get('type', 'unknown')),
path=hlval(path),
transport_id=hlid(transport_id),
func=hltype(self.start_web_transport_service))
transport = self.transports.get(transport_id, None)
if not transport:
emsg = 'Cannot start service on transport: no transport with ID "{}"'.format(transport_id)
self.log.error(emsg)
raise ApplicationError('crossbar.error.not_running', emsg)
if not isinstance(transport, self.personality.RouterWebTransport):
emsg = 'Cannot start service on transport: transport is not a Web transport (transport_type={})'.format(hltype(transport.__class__))
self.log.error(emsg)
raise ApplicationError('crossbar.error.not_running', emsg)
if transport.state != self.personality.RouterTransport.STATE_STARTED:
emsg = 'Cannot start service on Web transport service: transport is not running (transport_state={})'.format(
def restart_component():
# Think: if this below start_component() fails,
# we'll still schedule *exactly one* new re-start
# attempt for it, right?
self.log.info('{func}: now restarting previously closed component {component_id} automatically .. [restart_mode={restart_mode}, was_clean={was_clean}]',
func=hltype(_component_closed),
component_id=hlid(component_id),
restart_mode=hlval(self._restart_mode),
was_clean=hlval(was_clean))
return self.start_component(
component_id, config,
reload_modules=reload_modules,
details=details,
)