Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _create_resource(self, path_config, nested=True):
"""
Creates child resource to be added to the parent.
:param path_config: Configuration for the new child resource.
:type path_config: dict
:returns: Resource -- the new child resource
"""
# WAMP-WebSocket resource
#
if path_config['type'] == 'websocket':
ws_factory = WampWebSocketServerFactory(self._router_session_factory, self.config.extra.cbdir, path_config, self._templates)
# FIXME: Site.start/stopFactory should start/stop factories wrapped as Resources
ws_factory.startFactory()
return WebSocketResource(ws_factory)
# Static file hierarchy resource
#
elif path_config['type'] == 'static':
static_options = path_config.get('options', {})
if 'directory' in path_config:
static_dir = os.path.abspath(os.path.join(self.config.extra.cbdir, path_config['directory']))
raise ApplicationError(u"crossbar.error.invalid_configuration", emsg)
else:
self.log.debug("Starting {ttype}-transport on router.", ttype=config['type'])
# standalone WAMP-RawSocket transport
#
if config['type'] == 'rawsocket':
transport_factory = WampRawSocketServerFactory(self._router_session_factory, config)
transport_factory.noisy = False
# standalone WAMP-WebSocket transport
#
elif config['type'] == 'websocket':
transport_factory = WampWebSocketServerFactory(self._router_session_factory, self.config.extra.cbdir, config, self._templates)
transport_factory.noisy = False
# Flash-policy file server pseudo transport
#
elif config['type'] == 'flashpolicy':
transport_factory = FlashPolicyFactory(config.get('allowed_domain', None), config.get('allowed_ports', None))
# WebSocket testee pseudo transport
#
elif config['type'] == 'websocket.testee':
transport_factory = WebSocketTesteeServerFactory(config, self._templates)
# Stream testee pseudo transport
#
rawsocket_factory.noisy = False
else:
rawsocket_factory = None
if 'mqtt' in self._config:
mqtt_factory = WampMQTTServerFactory(
self._worker._router_session_factory, self._config['mqtt'], self._worker._reactor)
mqtt_factory.noisy = False
else:
mqtt_factory = None
if 'websocket' in self._config:
assert (self._templates)
websocket_factory_map = {}
for websocket_url_first_component, websocket_config in self._config['websocket'].items():
websocket_transport_factory = WampWebSocketServerFactory(self._worker._router_session_factory, self._cbdir,
websocket_config, self._templates)
websocket_transport_factory.noisy = False
websocket_factory_map[websocket_url_first_component] = websocket_transport_factory
self.log.debug('hooked up websocket factory on request URI {request_uri}',
request_uri=websocket_url_first_component)
else:
websocket_factory_map = None
transport_factory = UniSocketServerFactory(web_factory,
websocket_factory_map,
rawsocket_factory,
mqtt_factory)
# this is to allow subclasses to reuse this method
elif self._config['type'] in ignore:
pass
rawsocket_factory.noisy = False
else:
rawsocket_factory = None
if 'mqtt' in self._config:
mqtt_factory = WampMQTTServerFactory(
self._worker.router_session_factory, self._config['mqtt'], self._worker._reactor)
mqtt_factory.noisy = False
else:
mqtt_factory = None
if 'websocket' in self._config:
assert (self._templates)
websocket_factory_map = {}
for websocket_url_first_component, websocket_config in self._config['websocket'].items():
websocket_transport_factory = WampWebSocketServerFactory(self._worker.router_session_factory, self._cbdir,
websocket_config, self._templates)
websocket_transport_factory.noisy = False
websocket_factory_map[websocket_url_first_component] = websocket_transport_factory
self.log.debug('hooked up websocket factory on request URI {request_uri}',
request_uri=websocket_url_first_component)
else:
websocket_factory_map = None
transport_factory = UniSocketServerFactory(web_factory,
websocket_factory_map,
rawsocket_factory,
mqtt_factory)
# this is to allow subclasses to reuse this method
elif self._config['type'] in ignore:
pass
_router_session_factory, node, nested=True, ignore=[]):
"""
Creates child resource to be added to the parent.
:param path_config: Configuration for the new child resource.
:type path_config: dict
:returns: Resource -- the new child resource
"""
assert templates is not None
# WAMP-WebSocket resource
#
if path_config['type'] == 'websocket':
ws_factory = WampWebSocketServerFactory(_router_session_factory, cbdir, path_config, templates)
# FIXME: Site.start/stopFactory should start/stop factories wrapped as Resources
ws_factory.startFactory()
return WebSocketResource(ws_factory)
# Reverse WebSocket resource
#
elif path_config['type'] == 'websocket-reverseproxy':
ws_rproxy_factory = WebSocketReverseProxyServerFactory(reactor, path_config)
ws_rproxy_factory.startFactory()
return WebSocketResource(ws_rproxy_factory)
# Static file hierarchy resource
#
# Root Web service: only set (down below) when running a Web transport or
# a Universal transport with Web support
root_webservice = None
# standalone WAMP-RawSocket transport
#
if self._config['type'] == 'rawsocket':
transport_factory = WampRawSocketServerFactory(self._worker._router_session_factory, self._config)
transport_factory.noisy = False
# standalone WAMP-WebSocket transport
#
elif self._config['type'] == 'websocket':
assert (self._templates)
transport_factory = WampWebSocketServerFactory(self._worker._router_session_factory, self._cbdir, self._config,
self._templates)
transport_factory.noisy = False
# Flash-policy file server pseudo transport
#
elif self._config['type'] == 'flashpolicy':
transport_factory = FlashPolicyFactory(self._config.get('allowed_domain', None),
self._config.get('allowed_ports', None))
# WebSocket testee pseudo transport
#
elif self._config['type'] == 'websocket.testee':
assert (self._templates)
transport_factory = WebSocketTesteeServerFactory(self._config, self._templates)
# Stream testee pseudo transport
# Root Web service: only set (down below) when running a Web transport or
# a Universal transport with Web support
root_webservice = None
# standalone WAMP-RawSocket transport
#
if self._config['type'] == 'rawsocket':
transport_factory = WampRawSocketServerFactory(self._worker.router_session_factory, self._config)
transport_factory.noisy = False
# standalone WAMP-WebSocket transport
#
elif self._config['type'] == 'websocket':
assert (self._templates)
transport_factory = WampWebSocketServerFactory(self._worker.router_session_factory, self._cbdir, self._config,
self._templates)
transport_factory.noisy = False
# Flash-policy file server pseudo transport
#
elif self._config['type'] == 'flashpolicy':
transport_factory = FlashPolicyFactory(self._config.get('allowed_domain', None),
self._config.get('allowed_ports', None))
# WebSocket testee pseudo transport
#
elif self._config['type'] == 'websocket.testee':
assert (self._templates)
transport_factory = WebSocketTesteeServerFactory(self._config, self._templates)
# Stream testee pseudo transport