spec = ( SpecBuilder() .add_spec(path.join(current_dir, "swagger/api.yml")) .add_spec(path.join(web_dir, "common/swagger/definitions.yml")) .add_spec(path.join(web_dir, "common/swagger/parameters.yml")) .add_spec(path.join(web_dir, "common/swagger/responses.yml")) ) validator_map = {"body": BalrogRequestBodyValidator} connexion_app = connexion.App(__name__, debug=False, options={"swagger_ui": False}) connexion_app.add_api(spec, validator_map=validator_map, strict_validation=True) connexion_app.add_api(path.join(current_dir, "swagger", "api_v2.yml"), base_path="/v2", strict_validation=True, validate_responses=True) app = connexion_app.app create_dockerflow_endpoints(app) # When running under uwsgi, paths will not get decoded before hitting the app. # We need to handle this ourselves in certain fields, and adding converters # for them is the best way to do this. class UnquotingMiddleware(object): def __init__(self, app): self.app = app def __call__(self, environ, start_response): environ["PATH_INFO"] = unquote(environ["PATH_INFO"]) return self.app(environ, start_response) app.wsgi_app = UnquotingMiddleware(app.wsgi_app)
AUS = AUS() sentry = Sentry() from auslib.web.views.client import ClientRequestView from auslib.errors import BadDataError def heartbeat_database_function(dbo): # web has only a read access to the database. That's why we don't use # the default database function. # Counting the rules should be a trivial enough operation that it won't # cause notable load, but will verify that the database works. return dbo.rules.countRules() create_dockerflow_endpoints(app, heartbeat_database_function) @app.errorhandler(404) def fourohfour(error): """We don't return 404s in AUS. Instead, we return empty XML files""" response = make_response('<?xml version="1.0"?>\n<updates>\n</updates>') response.mimetype = 'text/xml' return response @app.errorhandler(Exception) def generic(error): """Deals with any unhandled exceptions. If the exception is not a BadDataError, it will be sent to Sentry, and a 400 will be returned, because BadDataErrors are considered to be the client's fault.
.add_spec(path.join(web_dir, 'common/swagger/definitions.yml'))\ .add_spec(path.join(web_dir, 'common/swagger/parameters.yml'))\ .add_spec(path.join(web_dir, 'common/swagger/responses.yml')) validator_map = { 'body': BalrogRequestBodyValidator } connexion_app = connexion.App(__name__, validator_map=validator_map, debug=False) connexion_app.add_api(spec, strict_validation=True) app = connexion_app.app sentry = Sentry() from auslib.dockerflow import create_dockerflow_endpoints create_dockerflow_endpoints(app) # When running under uwsgi, paths will not get decoded before hitting the app. # We need to handle this ourselves in certain fields, and adding converters # for them is the best way to do this. class UnquotingMiddleware(object): def __init__(self, app): self.app = app def __call__(self, environ, start_response): environ["PATH_INFO"] = unquote(environ["PATH_INFO"]) return self.app(environ, start_response) app.wsgi_app = UnquotingMiddleware(app.wsgi_app)
AUS = AUS() sentry = Sentry() from auslib.web.views.client import ClientRequestView from auslib.errors import BadDataError def heartbeat_database_function(dbo): # web has only a read access to the database. That's why we don't use # the default database function. # Counting the rules should be a trivial enough operation that it won't # cause notable load, but will verify that the database works. return dbo.rules.countRules() create_dockerflow_endpoints(app, heartbeat_database_function) @app.errorhandler(404) def fourohfour(error): """We don't return 404s in AUS. Instead, we return empty XML files""" response = make_response('<?xml version="1.0"?>\n<updates>\n</updates>') response.mimetype = "text/xml" return response @app.errorhandler(Exception) def generic(error): """Deals with any unhandled exceptions. If the exception is not a BadDataError, it will be sent to Sentry. Regardless of the exception, a 200 response with no updates is returned, because that's what the client