def main(): try: custom_settings = json.load(open(options.config, 'r')) except IOError: logger.warning("Application started without configuration file.\n" "This is normal only during development") custom_settings = {} ioloop_instance = tornado.ioloop.IOLoop.instance() settings = dict( cookie_secret=custom_settings.get("cookie_secret", "bad secret"), login_url="/auth", template_path=os.path.join(os.path.dirname(__file__), os.path.join("web/frontend", "templates")), static_path=os.path.join(os.path.dirname(__file__), os.path.join("web/frontend", "static")), xsrf_cookies=True, autoescape="xhtml_escape", debug=options.debug, options=options, config=custom_settings) handlers = create_application_handlers() try: app = Application(handlers=handlers, **settings) server = tornado.httpserver.HTTPServer(app) server.listen(options.port) except Exception as e: return stop_running(str(e)) # create references to application from SockJS handlers AdminSocketHandler.application = app Client.application = app app.initialize() # summarize run configuration writing it into logger logger.info("Tornado port: {0}".format(options.port)) # finally, let's go try: ioloop_instance.start() except KeyboardInterrupt: logger.info('interrupted') finally: # clean if hasattr(app, 'pub_stream'): app.pub_stream.close() if hasattr(app, 'sub_stream'): app.sub_stream.stop_on_recv() app.sub_stream.close()
def setUp(self): self.application = Application() self.pubsub = BasePubSub(self.application) self.project_id = 'test' self.namespace = 'test' self.channel = 'test'
def setUp(self): self.application = Application() self.pubsub = ZmqPubSub(self.application) self.pubsub.sub_stream = FakeSocket() self.project_id = 'test' self.namespace = 'test' self.channel = 'test'
def setUp(self): super(ClientTest, self).setUp() self.client = TestClient(FakeSock(), {}) self.client.is_authenticated = True self.client.project_id = "test_project" self.client.uid = "test_uid" self.client.user = "******" self.client.channels = {} self.client.presence_ping = FakePeriodic() self.client.application = Application() self.client.application.pubsub = BasePubSub(self.client.application) self.client.application.state = FakeState()
def setUp(self): super(MemoryEngineTest, self).setUp() self.application = Application(**{'options': Options}) self.engine = MemoryEngine(self.application) self.engine.initialize() self.engine.history_size = 2 self.engine.presence_timeout = 1 self.project_id = "project_id" self.channel = "channel" self.uid_1 = 'uid-1' self.uid_2 = 'uid-2' self.user_id = 'user_id' self.user_id_extra = 'user_id_extra' self.user_info = "{}" self.message_1 = json.dumps('test message 1') self.message_2 = json.dumps('test message 2') self.message_3 = json.dumps('test message 3')
def main(): try: custom_settings = json.load(open(options.config, 'r')) except IOError: logger.warning( "Application started without configuration file.\n" "This is normal only during development" ) custom_settings = {} ioloop_instance = tornado.ioloop.IOLoop.instance() settings = dict( cookie_secret=custom_settings.get("cookie_secret", "bad secret"), login_url="/auth", template_path=os.path.join( os.path.dirname(__file__), os.path.join("web/frontend", "templates") ), static_path=os.path.join( os.path.dirname(__file__), os.path.join("web/frontend", "static") ), xsrf_cookies=True, autoescape="xhtml_escape", debug=options.debug, options=options, config=custom_settings ) handlers = create_application_handlers() try: app = Application(handlers=handlers, **settings) server = tornado.httpserver.HTTPServer(app) server.listen(options.port) except Exception as e: return stop_running(str(e)) # create references to application from SockJS handlers AdminSocketHandler.application = app Client.application = app app.initialize() # summarize run configuration writing it into logger logger.info("Tornado port: {0}".format(options.port)) # finally, let's go try: ioloop_instance.start() except KeyboardInterrupt: logger.info('interrupted') finally: # clean if hasattr(app, 'pub_stream'): app.pub_stream.close() if hasattr(app, 'sub_stream'): app.sub_stream.stop_on_recv() app.sub_stream.close()
def create_centrifuge_application(): try: custom_settings = json.load(open(options.config, 'r')) except IOError: return stop_running("No configuration file found.") # override security related options using environment variable # value if exists for option_name in ["password", "cookie_secret", "api_secret"]: environment_var_name = "CENTRIFUGE_{0}".format(option_name.upper()) environment_value = os.environ.get(environment_var_name) if environment_value: logger.debug("using {0} environment variable for {1} option value".format( environment_var_name, option_name )) custom_settings[option_name] = environment_value if os.environ.get("CENTRIFUGE_INSECURE") == "1": custom_settings["insecure"] = True settings = dict( cookie_secret=custom_settings.get("cookie_secret", "bad secret"), template_path=os.path.join( os.path.dirname(__file__), os.path.join("web/frontend", "templates") ), static_path=os.path.join( os.path.dirname(__file__), os.path.join("web/frontend", "static") ), xsrf_cookies=False, autoescape="xhtml_escape", debug=options.debug, options=options, config=custom_settings ) sockjs_settings = custom_settings.get("sockjs_settings", {}) if not sockjs_settings or not sockjs_settings.get("sockjs_url"): # SockJS CDN will be retired # see https://github.com/sockjs/sockjs-client/issues/198 # if no explicit SockJS url provided in configuration file # then we use jsdelivr CDN instead of default cdn.sockjs.org # this can be fixed directly in SockJS-Tornado soon sockjs_settings["sockjs_url"] = "https://cdn.jsdelivr.net/sockjs/1.0/sockjs.min.js" handlers = create_application_handlers(sockjs_settings) # custom settings to configure the tornado HTTPServer tornado_settings = custom_settings.get("tornado_settings", {}) logger.debug("tornado_settings: %s", tornado_settings) if 'io_loop' in tornado_settings: stop_running( "The io_loop in tornado_settings is not supported for now." ) try: app = Application(handlers=handlers, **settings) server = tornado.httpserver.HTTPServer(app, **tornado_settings) server.listen(options.port, address=options.address) except Exception as e: return stop_running(str(e)) logger.info("Engine class: {0}".format(engine_class_path)) app.engine = engine_class(app) # create reference to application from Client Client.application = app app.initialize() logger.info("Tornado port: {0}, address: {1}".format(options.port, options.address)) return app
def main(): try: custom_settings = json.load(open(options.config, 'r')) except IOError: logger.warning("Application started without configuration file.\n" "This is normal only during development") custom_settings = {} ioloop_instance = tornado.ioloop.IOLoop.instance() settings = dict( cookie_secret=custom_settings.get("cookie_secret", "bad secret"), login_url="/auth", template_path=os.path.join(os.path.dirname(__file__), os.path.join("web/frontend", "templates")), static_path=os.path.join(os.path.dirname(__file__), os.path.join("web/frontend", "static")), xsrf_cookies=True, autoescape="xhtml_escape", debug=options.debug, options=options, config=custom_settings) sockjs_settings = custom_settings.get("sockjs_settings", {}) handlers = create_application_handlers(sockjs_settings) try: app = Application(handlers=handlers, **settings) server = tornado.httpserver.HTTPServer(app) server.listen(options.port) except Exception as e: return stop_running(str(e)) logger.info("Engine class: {0}".format(engine_class_path)) app.engine = engine_class(app) logger.info("Storage class: {0}".format(storage_class_path)) app.storage = storage_class(options) # create references to application from SockJS handlers AdminSocketHandler.application = app Client.application = app app.initialize() max_channel_length = custom_settings.get('max_channel_length') if max_channel_length: app.MAX_CHANNEL_LENGTH = max_channel_length admin_api_message_limit = custom_settings.get('admin_api_message_limit') if admin_api_message_limit: app.ADMIN_API_MESSAGE_LIMIT = admin_api_message_limit client_api_message_limit = custom_settings.get('client_api_message_limit') if client_api_message_limit: app.CLIENT_API_MESSAGE_LIMIT = client_api_message_limit owner_api_project_id = custom_settings.get('owner_api_project_id') if owner_api_project_id: app.OWNER_API_PROJECT_ID = owner_api_project_id owner_api_project_param = custom_settings.get('owner_api_project_param') if owner_api_project_param: app.OWNER_API_PROJECT_PARAM = owner_api_project_param connection_expire_check = custom_settings.get('connection_expire_check', True) if connection_expire_check: app.CONNECTION_EXPIRE_CHECK = connection_expire_check connection_expire_collect_interval = custom_settings.get( 'connection_expire_collect_interval') if connection_expire_collect_interval: app.CONNECTION_EXPIRE_COLLECT_INTERVAL = connection_expire_collect_interval connection_expire_check_interval = custom_settings.get( 'connection_expire_check_interval') if connection_expire_check_interval: app.CONNECTION_EXPIRE_CHECK_INTERVAL = connection_expire_check_interval logger.info("Tornado port: {0}".format(options.port)) # finally, let's go try: ioloop_instance.start() except KeyboardInterrupt: logger.info('interrupted') finally: # cleaning if hasattr(app.engine, 'clean'): app.engine.clean()
def main(): # load settings from configuration file try: custom_settings = json.load(open(options.config, 'r')) except IOError: logger.warning( "Application started without configuration file.\n" "This is normal only during development" ) custom_settings = {} ioloop_instance = tornado.ioloop.IOLoop.instance() settings = dict( cookie_secret=custom_settings.get("cookie_secret", "bad secret"), login_url="/auth", template_path=os.path.join( os.path.dirname(__file__), os.path.join("web/frontend", "templates") ), static_path=os.path.join( os.path.dirname(__file__), os.path.join("web/frontend", "static") ), xsrf_cookies=True, autoescape="xhtml_escape", debug=options.debug, options=options, config=custom_settings ) handlers = create_application_handlers() try: app = Application(handlers=handlers, **settings) server = tornado.httpserver.HTTPServer(app) server.listen(options.port) except Exception as e: return stop_running(str(e)) # create references to application from SockJS handlers AdminSocketHandler.application = app Client.application = app # choose PUB/SUB mechanism if options.base: from centrifuge.pubsub.base import BasePubSub as PubSub elif options.redis: from centrifuge.pubsub.redis import PubSub else: from centrifuge.pubsub.zeromq import PubSub app.pubsub = PubSub(app) app.initialize() magic_project_id = custom_settings.get('magic_project_id') if magic_project_id: app.MAGIC_PROJECT_ID = magic_project_id magic_project_param = custom_settings.get('magic_project_param') if magic_project_param: app.MAGIC_PROJECT_PARAM = magic_project_param logger.info("Tornado port: {0}".format(options.port)) # finally, let's go try: ioloop_instance.start() except KeyboardInterrupt: logger.info('interrupted') finally: # cleaning if hasattr(app.pubsub, 'clean'): app.pubsub.clean()
def create_centrifuge_application(): try: custom_settings = json.load(open(options.config, 'r')) except IOError: logger.warning("No configuration file found. " "In production make sure security settings provided") custom_settings = {} # override security related options using environment variable # value if exists for option_name in ["password", "cookie_secret", "api_secret"]: environment_var_name = "CENTRIFUGE_{0}".format(option_name.upper()) environment_value = os.environ.get(environment_var_name) if environment_value: logger.debug( "using {0} environment variable for {1} option value".format( environment_var_name, option_name)) custom_settings[option_name] = environment_value if os.environ.get("CENTRIFUGE_INSECURE") == "1": custom_settings["insecure"] = True settings = dict( cookie_secret=custom_settings.get("cookie_secret", "bad secret"), login_url="/auth", template_path=os.path.join(os.path.dirname(__file__), os.path.join("web/frontend", "templates")), static_path=os.path.join(os.path.dirname(__file__), os.path.join("web/frontend", "static")), xsrf_cookies=True, autoescape="xhtml_escape", debug=options.debug, options=options, config=custom_settings) sockjs_settings = custom_settings.get("sockjs_settings", {}) if not sockjs_settings or not sockjs_settings.get("sockjs_url"): # SockJS CDN will be retired # see https://github.com/sockjs/sockjs-client/issues/198 # if no explicit SockJS url provided in configuration file # then we use jsdelivr CDN instead of default cdn.sockjs.org # this can be fixed directly in SockJS-Tornado soon sockjs_settings[ "sockjs_url"] = "https://cdn.jsdelivr.net/sockjs/0.3/sockjs.min.js" handlers = create_application_handlers(sockjs_settings) # custom settings to configure the tornado HTTPServer tornado_settings = custom_settings.get("tornado_settings", {}) logger.debug("tornado_settings: %s", tornado_settings) if 'io_loop' in tornado_settings: stop_running( "The io_loop in tornado_settings is not supported for now.") try: app = Application(handlers=handlers, **settings) server = tornado.httpserver.HTTPServer(app, **tornado_settings) server.listen(options.port, address=options.address) except Exception as e: return stop_running(str(e)) logger.info("Engine class: {0}".format(engine_class_path)) app.engine = engine_class(app) logger.info("Storage class: {0}".format(storage_class_path)) app.storage = storage_class(options) # create reference to application from SockJS handlers AdminSocketHandler.application = app # create reference to application from Client Client.application = app app.initialize() logger.info("Tornado port: {0}, address: {1}".format( options.port, options.address)) return app
def setUp(self): super(BaseEngineTest, self).setUp() self.application = Application(**{'options': Options}) self.engine = BaseEngine(self.application)
def main(): try: custom_settings = json.load(open(options.config, 'r')) except IOError: logger.warning( "Application started without configuration file.\n" "This is normal only during development" ) custom_settings = {} ioloop_instance = tornado.ioloop.IOLoop.instance() settings = dict( cookie_secret=custom_settings.get("cookie_secret", "bad secret"), login_url="/auth", template_path=os.path.join( os.path.dirname(__file__), os.path.join("web/frontend", "templates") ), static_path=os.path.join( os.path.dirname(__file__), os.path.join("web/frontend", "static") ), xsrf_cookies=True, autoescape="xhtml_escape", debug=options.debug, options=options, config=custom_settings ) sockjs_settings = custom_settings.get("sockjs_settings", {}) handlers = create_application_handlers(sockjs_settings) try: app = Application(handlers=handlers, **settings) server = tornado.httpserver.HTTPServer(app) server.listen(options.port) except Exception as e: return stop_running(str(e)) logger.info("Engine class: {0}".format(engine_class_path)) app.engine = engine_class(app) logger.info("Storage class: {0}".format(storage_class_path)) app.storage = storage_class(options) # create references to application from SockJS handlers AdminSocketHandler.application = app Client.application = app app.initialize() max_channel_length = custom_settings.get('max_channel_length') if max_channel_length: app.MAX_CHANNEL_LENGTH = max_channel_length admin_api_message_limit = custom_settings.get('admin_api_message_limit') if admin_api_message_limit: app.ADMIN_API_MESSAGE_LIMIT = admin_api_message_limit client_api_message_limit = custom_settings.get('client_api_message_limit') if client_api_message_limit: app.CLIENT_API_MESSAGE_LIMIT = client_api_message_limit owner_api_project_id = custom_settings.get('owner_api_project_id') if owner_api_project_id: app.OWNER_API_PROJECT_ID = owner_api_project_id owner_api_project_param = custom_settings.get('owner_api_project_param') if owner_api_project_param: app.OWNER_API_PROJECT_PARAM = owner_api_project_param connection_expire_check = custom_settings.get('connection_expire_check', True) if connection_expire_check: app.CONNECTION_EXPIRE_CHECK = connection_expire_check connection_expire_collect_interval = custom_settings.get('connection_expire_collect_interval') if connection_expire_collect_interval: app.CONNECTION_EXPIRE_COLLECT_INTERVAL = connection_expire_collect_interval connection_expire_check_interval = custom_settings.get('connection_expire_check_interval') if connection_expire_check_interval: app.CONNECTION_EXPIRE_CHECK_INTERVAL = connection_expire_check_interval logger.info("Tornado port: {0}".format(options.port)) # finally, let's go try: ioloop_instance.start() except KeyboardInterrupt: logger.info('interrupted') finally: # cleaning if hasattr(app.engine, 'clean'): app.engine.clean()
def main(): # load settings from configuration file try: custom_settings = json.load(open(options.config, 'r')) except IOError: logger.warning("Application started without configuration file.\n" "This is normal only during development") custom_settings = {} ioloop_instance = tornado.ioloop.IOLoop.instance() settings = dict( cookie_secret=custom_settings.get("cookie_secret", "bad secret"), login_url="/auth", template_path=os.path.join(os.path.dirname(__file__), os.path.join("web/frontend", "templates")), static_path=os.path.join(os.path.dirname(__file__), os.path.join("web/frontend", "static")), xsrf_cookies=True, autoescape="xhtml_escape", debug=options.debug, options=options, config=custom_settings) handlers = create_application_handlers() try: app = Application(handlers=handlers, **settings) server = tornado.httpserver.HTTPServer(app) server.listen(options.port) except Exception as e: return stop_running(str(e)) # create references to application from SockJS handlers AdminSocketHandler.application = app Client.application = app # choose PUB/SUB mechanism if options.base: from centrifuge.pubsub.base import BasePubSub as PubSub elif options.redis: from centrifuge.pubsub.redis import PubSub else: from centrifuge.pubsub.zeromq import PubSub app.pubsub = PubSub(app) app.initialize() magic_project_id = custom_settings.get('magic_project_id') if magic_project_id: app.MAGIC_PROJECT_ID = magic_project_id magic_project_param = custom_settings.get('magic_project_param') if magic_project_param: app.MAGIC_PROJECT_PARAM = magic_project_param logger.info("Tornado port: {0}".format(options.port)) # finally, let's go try: ioloop_instance.start() except KeyboardInterrupt: logger.info('interrupted') finally: # cleaning if hasattr(app.pubsub, 'clean'): app.pubsub.clean()