def run(self): if self.config['profile']: app.wsgi_app = ProfilerMiddleware( app.wsgi_app, profile_dir=self.config['profile']) wsgi_app = ReverseProxied( ProxyFix(wsgi.WSGIPathInfoDispatcher({'/': app}))) bind_addr = (self.config['listen'], self.config['port']) self.server = wsgi.WSGIServer(bind_addr=bind_addr, wsgi_app=wsgi_app) self.server.ssl_adapter = http_helpers.ssl_adapter( self.config['certificate'], self.config['private_key']) logger.debug( 'WSGIServer starting... uid: %s, listen: %s:%s', os.getuid(), bind_addr[0], bind_addr[1], ) for route in http_helpers.list_routes(app): logger.debug(route) try: self.server.start() except KeyboardInterrupt: logger.warning('Stopping wazo-confd: KeyboardInterrupt') self.server.stop()
def run(self): bind_addr = (self.config['listen'], self.config['port']) wsgi_app = ReverseProxied( ProxyFix(wsgi.WSGIPathInfoDispatcher({'/': app}))) self.server = wsgi.WSGIServer(bind_addr=bind_addr, wsgi_app=wsgi_app) if self.config['certificate'] and self.config['private_key']: logger.warning( 'Using service SSL configuration is deprecated. Please use NGINX instead.' ) self.server.ssl_adapter = http_helpers.ssl_adapter( self.config['certificate'], self.config['private_key']) logger.debug( 'WSGIServer starting... uid: %s, listen: %s:%s', os.getuid(), bind_addr[0], bind_addr[1], ) for route in http_helpers.list_routes(app): logger.debug(route) try: self.server.start() except KeyboardInterrupt: self.server.stop()
def run(self): bind_addr = (self.config['https']['listen'], self.config['https']['port']) wsgi_app = wsgi.WSGIPathInfoDispatcher({'/': app}) self.server = wsgi.WSGIServer( bind_addr=bind_addr, wsgi_app=wsgi_app, numthreads=self.config['max_threads'], ) self.server.ssl_adapter = http_helpers.ssl_adapter( self.config['https']['certificate'], self.config['https']['private_key'] ) logger.debug( 'WSGIServer starting... uid: %s, listen: %s:%s', os.getuid(), bind_addr[0], bind_addr[1], ) for route in http_helpers.list_routes(app): logger.debug(route) try: self.server.start() except KeyboardInterrupt: self.server.stop()
def __init__(self, config, root_worker): self._executor = ThreadPoolExecutor( max_workers=10) # Make it configurable self._xivo_uuid = config.get('uuid') self._listen_addr = config['rest_api']['https']['listen'] self._listen_port = config['rest_api']['https']['port'] self._cors_config = config['rest_api']['cors'] self._ssl_cert_file = config['rest_api']['https']['certificate'] ssl_key_file = config['rest_api']['https']['private_key'] self._consul_config = config['consul'] self._service_discovery_config = config['service_discovery'] self._bus_config = config['bus'] bind_addr = (self._listen_addr, self._listen_port) self._publisher = bus.StatusPublisher.from_config(config) plugin_service = service.PluginService.from_config( config, self._publisher, root_worker, self._executor) flask_app = http.new_app(config, plugin_service=plugin_service) flask_app.after_request(http_helpers.log_request) wsgi.WSGIServer.ssl_adapter = http_helpers.ssl_adapter( self._ssl_cert_file, ssl_key_file) wsgi_app = ReverseProxied( ProxyFix(wsgi.WSGIPathInfoDispatcher({'/': flask_app}))) self._server = wsgi.WSGIServer(bind_addr=bind_addr, wsgi_app=wsgi_app) for route in http_helpers.list_routes(flask_app): logger.debug(route)
def run(self): http_config = self.config['http'] https_config = self.config['https'] wsgi_app = wsgi.WSGIPathInfoDispatcher({'/': self.app}) cherrypy.server.unsubscribe() cherrypy.config.update({'environment': 'production'}) if https_config['enabled']: try: bind_addr_https = (https_config['listen'], https_config['port']) server_https = wsgi.WSGIServer(bind_addr=bind_addr_https, wsgi_app=wsgi_app) server_https.ssl_adapter = http_helpers.ssl_adapter( https_config['certificate'], https_config['private_key']) ServerAdapter(cherrypy.engine, server_https).subscribe() logger.debug( 'WSGIServer starting... uid: %s, listen: %s:%s', os.getuid(), bind_addr_https[0], bind_addr_https[1], ) except IOError as e: logger.warning("HTTPS server won't start: %s", e) else: logger.debug('HTTPS server is disabled') if http_config['enabled']: bind_addr_http = (http_config['listen'], http_config['port']) server_http = wsgi.WSGIServer(bind_addr=bind_addr_http, wsgi_app=wsgi_app) ServerAdapter(cherrypy.engine, server_http).subscribe() logger.debug( 'WSGIServer starting... uid: %s, listen: %s:%s', os.getuid(), bind_addr_http[0], bind_addr_http[1], ) else: logger.debug('HTTP server is disabled') if not http_config['enabled'] and not https_config['enabled']: logger.critical('No HTTP/HTTPS server enabled') exit() list_routes(self.app) try: cherrypy.engine.start() cherrypy.engine.wait(states.EXITING) except KeyboardInterrupt: logger.warning('Stopping wazo-phoned: KeyboardInterrupt') cherrypy.engine.exit()
def run(self): wsgi_app_https = ReverseProxied( ProxyFix(wsgi.WSGIPathInfoDispatcher({'/': app}))) wsgi_app_http = ReverseProxied( ProxyFix(wsgi.WSGIPathInfoDispatcher({'/': adapter_app}))) cherrypy.server.unsubscribe() cherrypy.config.update({'environment': 'production'}) bind_addr = (self.config['listen'], self.config['port']) server_https = wsgi.WSGIServer(bind_addr=bind_addr, wsgi_app=wsgi_app_https) server_https.ssl_adapter = http_helpers.ssl_adapter( self.config['certificate'], self.config['private_key']) ServerAdapter(cherrypy.engine, server_https).subscribe() logger.debug('WSGIServer starting... uid: %s, listen: %s:%s', os.getuid(), bind_addr[0], bind_addr[1]) for route in http_helpers.list_routes(app): logger.debug(route) if self.adapter_config['enabled']: bind_addr = (self.adapter_config['listen'], self.adapter_config['port']) server_adapter = wsgi.WSGIServer(bind_addr=bind_addr, wsgi_app=wsgi_app_http) ServerAdapter(cherrypy.engine, server_adapter).subscribe() logger.debug('WSGIServer starting... uid: %s, listen: %s:%s', os.getuid(), bind_addr[0], bind_addr[1]) for route in http_helpers.list_routes(adapter_app): logger.debug(route) else: logger.debug('Adapter server is disabled') try: cherrypy.engine.start() cherrypy.engine.wait(states.EXITING) except KeyboardInterrupt: logger.warning('Stopping xivo-ctid-ng: KeyboardInterrupt') cherrypy.engine.exit()
def __init__(self, config, main_thread_proxy): app = Flask('xivo_ctid') http_helpers.add_logger(app, logger) app.after_request(http_helpers.log_request) app.secret_key = os.urandom(24) self.load_cors(app, config) api = Api(app, prefix='/{}'.format(self.VERSION)) self._add_resources(api, main_thread_proxy) bind_addr = (config['http']['listen'], config['http']['port']) wsgi_app = wsgi.WSGIPathInfoDispatcher({'/': app}) self._server = wsgi.WSGIServer(bind_addr=bind_addr, wsgi_app=wsgi_app)
def setup_server(cls): def hello(environ, start_response): status = '200 OK' response_headers = [('Content-type', 'text/plain'), ('Content-Length', '11')] start_response(status, response_headers) return [ntob('Hello world')] def foo(environ, start_response): status = '200 OK' response_headers = [('Content-type', 'text/plain')] start_response(status, response_headers) # This should fail according to the WSGI spec. start_response(status, response_headers) return [ntob('Hello world')] def bar(environ, start_response): status = '200 OK' response_headers = [('Content-type', 'text/plain'), ('Content-Length', '3')] write = start_response(status, response_headers) write(ntob('boo')) # This should fail according to the WSGI spec. try: noname except NameError: start_response(status, response_headers, sys.exc_info()) return [ntob('Hello world')] def baz(environ, start_response): status = 200 response_headers = [('Content-type', 'text/plain')] # This should fail because status is not a str start_response(status, response_headers) return [ntob('Hello world')] def qoph(environ, start_response): status = '200 OK' response_headers = [('Content-type', 5)] # This should fail because the response header value is not a str start_response(status, response_headers) return [ntob('Hello world')] cls.httpserver.wsgi_app = wsgi.WSGIPathInfoDispatcher({ '/foo': foo, '/bar': bar, '/baz': baz, '/qoph': qoph, '/hello': hello, })
def run(self): self.api.init_app(self.app) https_config = self.config['https'] bind_addr = (https_config['listen'], https_config['port']) wsgi_app = ReverseProxied( ProxyFix(wsgi.WSGIPathInfoDispatcher({'/': self.app}))) server = wsgi.WSGIServer(bind_addr=bind_addr, wsgi_app=wsgi_app) server.ssl_adapter = http_helpers.ssl_adapter( https_config['certificate'], https_config['private_key']) logger.debug('WSGIServer starting... uid: %s, listen: %s:%s', os.getuid(), bind_addr[0], bind_addr[1]) for route in http_helpers.list_routes(self.app): logger.debug(route) try: server.start() finally: server.stop()
def setup_server(cls): import os curdir = os.path.join(os.getcwd(), os.path.dirname(__file__)) def test_app(environ, start_response): status = '200 OK' response_headers = [('Content-type', 'text/plain')] start_response(status, response_headers) output = [ 'Hello, world!\n', 'This is a wsgi app running within Cheroot!\n\n' ] keys = list(environ.keys()) keys.sort() for k in keys: output.append('%s: %s\n' % (k, environ[k])) return [ntob(x, 'utf-8') for x in output] def test_empty_string_app(environ, start_response): status = '200 OK' response_headers = [('Content-type', 'text/plain')] start_response(status, response_headers) return [ ntob('Hello'), ntob(''), ntob(' '), ntob(''), ntob('world') ] class WSGIResponse(object): def __init__(self, appresults): self.appresults = appresults self.iter = iter(appresults) def __iter__(self): return self def next(self): return self.iter.next() def __next__(self): return next(self.iter) def close(self): if hasattr(self.appresults, "close"): self.appresults.close() class ReversingMiddleware(object): def __init__(self, app): self.app = app def __call__(self, environ, start_response): results = self.app(environ, start_response) class Reverser(WSGIResponse): def next(this): line = list(this.iter.next()) line.reverse() return "".join(line) def __next__(this): line = list(next(this.iter)) line.reverse() return bytes(line) return Reverser(results) class Root(helper.Controller): def normal(self, req, resp): return "I'm a regular Cheroot page handler!" cls.httpserver.wsgi_app = wsgi.WSGIPathInfoDispatcher({ '/': Root(), '/hosted/app1': test_app, '/hosted/app3': test_empty_string_app, '/hosted/app2': ReversingMiddleware(Root()), })
host = config.get('service', 'host') port = config.get('service', 'port') url = config.get('service', 'url') #-----------------DataBase--------------------- dbhost = config.get('database', 'host') dbport = config.get('database', 'port') dbuser = config.get('database', 'user') dbpassword = config.get('database', 'pass') dbname = config.get('database', 'name') #----------------logging----------------------- logEnable = config.get('logging', 'logEnable') pathLog = config.get('logging', 'fileLog') #----------------params------------------------ app = Flask(__name__) d = wsgi.WSGIPathInfoDispatcher({'/': app.wsgi_app}) server = wsgi.Server((host, int(port)), d) @app.route('/termos', methods=["POST","GET"]) def method(): if request.method == 'GET': return render_template("index.html") if request.method == 'POST': header = str(request.headers).splitlines() data = request.form.to_dict() log(str(data)) data['headers'] = str(header) resp = storagedata(data) if resp != 1: return resp return redirect("https://userintegrity-ui.latallynis.gemalto.com/", code=200)
def __init__(self, clay): self.clay = clay app = RequestLogger(clay.app) self.dispatcher = wsgi.WSGIPathInfoDispatcher({'/': app})