def make_app(controller_klass, environ={}, with_errors=False): """Creates a ``TestApp`` instance.""" # The basic middleware: app = ControllerWrap(controller_klass) app = SetupCacheGlobal(app, environ, setup_cache=True, setup_session=True) if with_errors: app = ErrorHandler(app, {}, debug=False) app = StatusCodeRedirect(app, [403, 404, 500]) app = RegistryManager(app) app = SessionMiddleware(app, {}, data_dir=session_dir) app = CacheMiddleware(app, {}, data_dir=os.path.join(data_dir, 'cache')) # We're not going to use groups or permissions-related predicates here: groups_adapters = None permissions_adapters = None # Setting repoze.who up: cookie = AuthTktCookiePlugin('secret', 'authtkt') identifiers = [('cookie', cookie)] app = setup_auth(app, groups_adapters, permissions_adapters, identifiers=identifiers, authenticators=[], challengers=[], skip_authentication=True) app = httpexceptions.make_middleware(app) return TestApp(app)
def wsgiapp_wrapper(*args): # we get 3 args when this is a method, two when it is # a function :( if len(args) == 3: environ = args[1] start_response = args[2] args = [args[0]] else: environ, start_response = args args = [] def application(environ, start_response): form = wsgilib.parse_formvars(environ, include_get_vars=True) headers = response.HeaderDict( {'content-type': 'text/html', 'status': '200 OK'}) form['environ'] = environ form['headers'] = headers res = func(*args, **form.mixed()) status = headers.pop('status') start_response(status, headers.headeritems()) return [res] app = httpexceptions.make_middleware(application) app = simplecatcher(app) return app(environ, start_response)
def wrap_in_middleware( app, global_conf, **local_conf ): conf = global_conf.copy() conf.update(local_conf) debug = asbool( conf.get( 'debug', False ) ) app = beaker.middleware.SessionMiddleware( app, conf ) app = GetSessionMiddleware( app, conf ) #from paste.translogger import TransLogger #app = TransLogger( app, conf ) from paste import httpexceptions app = httpexceptions.make_middleware( app, conf ) if debug: from paste.debug import prints app = prints.PrintDebugMiddleware( app, conf ) if debug and asbool( conf.get( 'use_interactive', False ) ): # Interactive exception debugging, scary dangerous if publicly # accessible, if not enabled we'll use the regular error printing # middleware. from weberror import evalexception app = evalexception.EvalException( app, conf ) LOG.debug( "Enabling 'eval exceptions' middleware" ) else: # Not in interactive debug mode, just use the regular error middleware from paste.exceptions import errormiddleware app = errormiddleware.ErrorMiddleware( app, conf ) LOG.debug( "Enabling 'error' middleware" ) return app
def make_app(controller_klass, environ={}): """Creates a ``TestApp`` instance.""" # The basic middleware: app = ControllerWrap(controller_klass) app = SetupCacheGlobal(app, environ, setup_cache=True, setup_session=True) app = RegistryManager(app) app = SessionMiddleware(app, {}, data_dir=session_dir) app = CacheMiddleware(app, {}, data_dir=os.path.join(data_dir, "cache")) # We're not going to use groups or permissions-related predicates here: groups_adapters = None permissions_adapters = None # Setting repoze.who up: cookie = AuthTktCookiePlugin("secret", "authtkt") identifiers = [("cookie", cookie)] app = setup_auth( app, groups_adapters, permissions_adapters, identifiers=identifiers, authenticators=[], challengers=[], skip_authentication=True, ) app = httpexceptions.make_middleware(app) return TestApp(app)
def make_app(global_conf, full_stack=True, **app_conf): """Create a WSGI application and return it global_conf is a dict representing the Paste configuration options, the paste.deploy.converters should be used when parsing Paste config options to ensure they're treated properly. """ # Setup the Paste CONFIG object CONFIG.push_process_config({'app_conf': app_conf, 'global_conf': global_conf}) # Load our Pylons configuration defaults config = load_environment(global_conf, app_conf) config.init_app(global_conf, app_conf, package='olpctag') # Load our default Pylons WSGI app and make g available app = pylons.wsgiapp.PylonsApp(config, helpers=olpctag.lib.helpers, g=app_globals.Globals) g = app.globals app = GroupMiddleware(app) app = ConfigMiddleware(app, {'app_conf':app_conf, 'global_conf':global_conf}) # YOUR MIDDLEWARE # Put your own middleware here, so that any problems are caught by the error # handling middleware underneath # If errror handling and exception catching will be handled by middleware # for multiple apps, you will want to set full_stack = False in your config # file so that it can catch the problems. if asbool(full_stack): # Change HTTPExceptions to HTTP responses app = httpexceptions.make_middleware(app, global_conf) # Error Handling app = ErrorHandler(app, global_conf, error_template=error_template, **config.errorware) # Display error documents for 401, 403, 404 status codes (if debug is disabled also # intercepts 500) #app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf) # Establish the Registry for this application app = RegistryManager(app) static_app = StaticURLParser(config.paths['static_files']) print static_app javascripts_app = StaticJavascripts() app = Cascade([static_app, javascripts_app, app]) return app
def make_app(controller_klass=None, environ=None): """Creates a `TestApp` instance.""" if environ is None: environ = {} environ['pylons.routes_dict'] = {} environ['pylons.routes_dict']['action'] = "routes_placeholder" if controller_klass is None: controller_klass = TGController app = ControllerWrap(controller_klass) app = SetupCacheGlobal(app, environ, setup_cache=True, setup_session=True) app = RegistryManager(app) app = beaker.middleware.SessionMiddleware(app, {}, data_dir=session_dir) app = CacheMiddleware(app, {}, data_dir=os.path.join(data_dir, 'cache')) app = httpexceptions.make_middleware(app) return TestApp(app)
def make_app(global_conf, **app_conf): if not 'nsBindings' in globals(): global nsBindings, litProps, resProps, ontGraph, ruleSet, \ definingOntology, builtinTemplateGraph, defaultDerivedPreds nsBindings = {u'owl' :OWLNS, u'rdf' :RDF.RDFNS, u'rdfs':RDFS.RDFSNS} litProps = set() resProps = set() ontGraph = Graph() ruleSet = set() builtinTemplateGraph = Graph() definingOntology = Graph() defaultDerivedPreds = [] setup_dry_config(global_conf, nsBindings, litProps, resProps, ontGraph, ruleSet, definingOntology, builtinTemplateGraph, defaultDerivedPreds) # @@@ Core Application @@@ app = WsgiApplication(global_conf, nsBindings, defaultDerivedPreds, litProps, resProps, definingOntology, ontGraph, ruleSet, builtinTemplateGraph) # @@@ Expose config variables to other plugins @@@ app = ConfigMiddleware(app, {'app_conf':app_conf, 'global_conf':global_conf}) # @@@ Caching support from Beaker @@@ app = CacheMiddleware(app, global_conf) # @@@ Change HTTPExceptions to HTTP responses @@@ app = httpexceptions.make_middleware(app, global_conf) global ticketLookup ticketLookup = {} return app
def make_app(global_conf, full_stack=True, **app_conf): """Create a WSGI application and return it global_conf is a dict representing the Paste configuration options, the paste.deploy.converters should be used when parsing Paste config options to ensure they're treated properly. """ load_environment(global_conf, app_conf) # Pull the other engine and put a new one up first config.template_engines.pop() kidopts = {'kid.assume_encoding':'utf-8', 'kid.encoding':'utf-8'} pylons.config.add_template_engine('kid', 'projectname.kidtemplates', kidopts) # Load our default Pylons WSGI app and make g available app = pylons.wsgiapp.PylonsApp(helpers=projectname.lib.helpers, g=app_globals.Globals) app = ConfigMiddleware(app, config._current_obj()) # If errror handling and exception catching will be handled by middleware # for multiple apps, you will want to set full_stack = False in your config # file so that it can catch the problems. if asbool(full_stack): # Change HTTPExceptions to HTTP responses app = httpexceptions.make_middleware(app, global_conf) # Error Handling app = ErrorHandler(app, global_conf, error_template=error_template, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (if debug is disabled also # intercepts 500) app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf) # Establish the Registry for this application app = RegistryManager(app) static_app = StaticURLParser(config['pylons.paths']['static_files']) javascripts_app = StaticJavascripts() app = Cascade([static_app, javascripts_app, app]) return app
def make_app(controller_klass=None, environ=None): """Creates a `TestApp` instance.""" if environ is None: environ = {} environ['pylons.routes_dict'] = {} environ['pylons.routes_dict']['action'] = "routes_placeholder" if controller_klass is None: controller_klass = TGController app = ControllerWrap(controller_klass) app = SetupCacheGlobal(app, environ, setup_cache=True, setup_session=True) app = RegistryManager(app) app = beaker.middleware.SessionMiddleware(app, {}, data_dir=session_dir) app = CacheMiddleware(app, {}, data_dir=os.path.join(data_dir, 'cache')) # ToscaWidgets Middleware # host_framework = PylonsHostFramework(default_view="genshi") # app = TGWidgetsMiddleware(app, host_framework) # Identity Middleware app = make_who_middleware(app, config, User, User.user_name, 'user_id', Session) app = httpexceptions.make_middleware(app) return TestApp(app)
def make_app(controller_klass, environ={}): """Creates a `TestApp` instance.""" app = ControllerWrap(controller_klass) app = SetupCacheGlobal(app, environ, setup_cache=True, setup_session=True) app = RegistryManager(app) app = SessionMiddleware(app, {}, data_dir=session_dir) app = CacheMiddleware(app, {}, data_dir=os.path.join(data_dir, 'cache')) # Setting up the source adapters: groups_adapters = {'my_groups': FakeGroupSourceAdapter()} permissions_adapters = {'my_permissions': FakePermissionSourceAdapter()} # Setting up repoze.who: cookie = AuthTktCookiePlugin('secret', 'authtkt') identifiers = [('cookie', cookie)] app = setup_auth(app, groups_adapters, permissions_adapters, identifiers=identifiers, authenticators=[], challengers=[], skip_authentication=True) app = httpexceptions.make_middleware(app) return TestApp(app)
def make_app(global_conf, **app_conf): """Create a WSGI application and return it global_conf is a dict representing the Paste configuration options, the paste.deploy.converters should be used when parsing Paste config options to ensure they're treated properly. """ # Load our Pylons configuration defaults from tasktracker.config.environment import load_environment load_environment(global_conf, app_conf) # Load our default Pylons WSGI app and make g available app = pylons.wsgiapp.PylonsApp() app = ConfigMiddleware(app, {'app_conf':app_conf, 'global_conf':global_conf}) # YOUR MIDDLEWARE # Put your own middleware here, so that any problems are caught by the error # handling middleware underneath app = SupervisorErrorMiddleware(app) # @@@ Change HTTPExceptions to HTTP responses @@@ app = httpexceptions.make_middleware(app, global_conf) # @@@ Error Handling @@@ app = ErrorHandler(app, global_conf, error_template=error_template, **config['pylons.errorware']) # @@@ Static Files in public directory @@@ static_app = StaticURLParser(config['pylons.paths']['static_files']) # @@@ WebHelper's static javascript files @@@ javascripts_app = StaticJavascripts() # @@@ Cascade @@@ app = Cascade([static_app, javascripts_app, app]) # @@@ Display error documents for 401, 403, 404 status codes (if debug is disabled also # intercepts 500) @@@ app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf) # @@@ Establish the Registry for this application @@@ app = RegistryManager(app) app = cabochon_to_tt_middleware(app) try: openplans_wrapper = app_conf['openplans_wrapper'] except KeyError: raise ValueError('No openplans_wrapper specified in [app:tasktracker] configuration') openplans_wrapper = load_object(openplans_wrapper) app = openplans_wrapper(app, app_conf) #handle cabochon messages login_file = app_conf.get('cabochon_password_file') if login_file: username, password = file(login_file).read().strip().split(":") if username: app = WSSEAuthMiddleware(app, {username : password}, required=False) app = translate_environ_middleware(app, global_conf, app_conf) app = fill_environ_middleware(app, global_conf, app_conf) return app
def wrap_in_middleware( app, global_conf, **local_conf ): """ Based on the configuration wrap `app` in a set of common and useful middleware. """ # Merge the global and local configurations conf = global_conf.copy() conf.update(local_conf) debug = asbool( conf.get( 'debug', False ) ) # First put into place httpexceptions, which must be most closely # wrapped around the application (it can interact poorly with # other middleware): app = httpexceptions.make_middleware( app, conf ) log.debug( "Enabling 'httpexceptions' middleware" ) # If we're using remote_user authentication, add middleware that # protects Galaxy from improperly configured authentication in the # upstream server if asbool(conf.get( 'use_remote_user', False )): from galaxy.web.framework.middleware.remoteuser import RemoteUser app = RemoteUser( app, maildomain = conf.get( 'remote_user_maildomain', None ), display_servers = util.listify( conf.get( 'display_servers', '' ) ), admin_users = conf.get( 'admin_users', '' ).split( ',' ) ) log.debug( "Enabling 'remote user' middleware" ) # The recursive middleware allows for including requests in other # requests or forwarding of requests, all on the server side. if asbool(conf.get('use_recursive', True)): from paste import recursive app = recursive.RecursiveMiddleware( app, conf ) log.debug( "Enabling 'recursive' middleware" ) # Various debug middleware that can only be turned on if the debug # flag is set, either because they are insecure or greatly hurt # performance if debug: # Middleware to check for WSGI compliance if asbool( conf.get( 'use_lint', False ) ): from paste import lint app = lint.make_middleware( app, conf ) log.debug( "Enabling 'lint' middleware" ) # Middleware to run the python profiler on each request if asbool( conf.get( 'use_profile', False ) ): from paste.debug import profile app = profile.ProfileMiddleware( app, conf ) log.debug( "Enabling 'profile' middleware" ) # Middleware that intercepts print statements and shows them on the # returned page if asbool( conf.get( 'use_printdebug', True ) ): from paste.debug import prints app = prints.PrintDebugMiddleware( app, conf ) log.debug( "Enabling 'print debug' middleware" ) if debug and asbool( conf.get( 'use_interactive', False ) ): # Interactive exception debugging, scary dangerous if publicly # accessible, if not enabled we'll use the regular error printing # middleware. pkg_resources.require( "WebError" ) from weberror import evalexception app = evalexception.EvalException( app, conf, templating_formatters=build_template_error_formatters() ) log.debug( "Enabling 'eval exceptions' middleware" ) else: # Not in interactive debug mode, just use the regular error middleware if sys.version_info[:2] >= ( 2, 6 ): warnings.filterwarnings( 'ignore', '.*', DeprecationWarning, '.*serial_number_generator', 11, True ) from paste.exceptions import errormiddleware warnings.filters.pop() else: from paste.exceptions import errormiddleware app = errormiddleware.ErrorMiddleware( app, conf ) log.debug( "Enabling 'error' middleware" ) # Transaction logging (apache access.log style) if asbool( conf.get( 'use_translogger', True ) ): from framework.middleware.translogger import TransLogger app = TransLogger( app ) log.debug( "Enabling 'trans logger' middleware" ) # Config middleware just stores the paste config along with the request, # not sure we need this but useful from paste.deploy.config import ConfigMiddleware app = ConfigMiddleware( app, conf ) log.debug( "Enabling 'config' middleware" ) # X-Forwarded-Host handling from galaxy.web.framework.middleware.xforwardedhost import XForwardedHostMiddleware app = XForwardedHostMiddleware( app ) log.debug( "Enabling 'x-forwarded-host' middleware" ) return app
def wrap_in_middleware( app, global_conf, **local_conf ): """Based on the configuration wrap `app` in a set of common and useful middleware.""" # Merge the global and local configurations conf = global_conf.copy() conf.update(local_conf) debug = asbool( conf.get( 'debug', False ) ) # First put into place httpexceptions, which must be most closely # wrapped around the application (it can interact poorly with # other middleware): app = httpexceptions.make_middleware( app, conf ) log.debug( "Enabling 'httpexceptions' middleware" ) # The recursive middleware allows for including requests in other # requests or forwarding of requests, all on the server side. if asbool(conf.get('use_recursive', True)): from paste import recursive app = recursive.RecursiveMiddleware( app, conf ) log.debug( "Enabling 'recursive' middleware" ) # Various debug middleware that can only be turned on if the debug # flag is set, either because they are insecure or greatly hurt # performance if debug: # Middleware to check for WSGI compliance if asbool( conf.get( 'use_lint', True ) ): from paste import lint app = lint.make_middleware( app, conf ) log.debug( "Enabling 'lint' middleware" ) # Middleware to run the python profiler on each request if asbool( conf.get( 'use_profile', False ) ): import profile app = profile.ProfileMiddleware( app, conf ) log.debug( "Enabling 'profile' middleware" ) # Middleware that intercepts print statements and shows them on the # returned page if asbool( conf.get( 'use_printdebug', True ) ): from paste.debug import prints app = prints.PrintDebugMiddleware( app, conf ) log.debug( "Enabling 'print debug' middleware" ) if debug and asbool( conf.get( 'use_interactive', False ) ) and not process_is_uwsgi: # Interactive exception debugging, scary dangerous if publicly # accessible, if not enabled we'll use the regular error printing # middleware. from weberror import evalexception app = evalexception.EvalException( app, conf, templating_formatters=build_template_error_formatters() ) log.debug( "Enabling 'eval exceptions' middleware" ) else: if debug and asbool( conf.get( 'use_interactive', False ) ) and process_is_uwsgi: log.error("Interactive debugging middleware is enabled in your configuration " "but this is a uwsgi process. Refusing to wrap in interactive error middleware.") # Not in interactive debug mode, just use the regular error middleware from paste.exceptions import errormiddleware app = errormiddleware.ErrorMiddleware( app, conf ) log.debug( "Enabling 'error' middleware" ) # Transaction logging (apache access.log style) if asbool( conf.get( 'use_translogger', True ) ): from paste.translogger import TransLogger app = TransLogger( app ) log.debug( "Enabling 'trans logger' middleware" ) # X-Forwarded-Host handling from galaxy.web.framework.middleware.xforwardedhost import XForwardedHostMiddleware app = XForwardedHostMiddleware( app ) log.debug( "Enabling 'x-forwarded-host' middleware" ) return app
def wrap_in_middleware( app, global_conf, **local_conf ): """ Based on the configuration wrap `app` in a set of common and useful middleware. """ # Merge the global and local configurations conf = global_conf.copy() conf.update(local_conf) debug = asbool( conf.get( 'debug', False ) ) # First put into place httpexceptions, which must be most closely # wrapped around the application (it can interact poorly with # other middleware): app = httpexceptions.make_middleware( app, conf ) log.debug( "Enabling 'httpexceptions' middleware" ) # If we're using remote_user authentication, add middleware that # protects Galaxy from improperly configured authentication in the # upstream server if asbool(conf.get( 'use_remote_user', False )): from galaxy.web.framework.middleware.remoteuser import RemoteUser app = RemoteUser( app, maildomain=conf.get( 'remote_user_maildomain', None ), display_servers=util.listify( conf.get( 'display_servers', '' ) ), admin_users=conf.get( 'admin_users', '' ).split( ',' ), remote_user_header=conf.get( 'remote_user_header', 'HTTP_REMOTE_USER' ), remote_user_secret_header=conf.get('remote_user_secret', None), normalize_remote_user_email=conf.get('normalize_remote_user_email', False)) # The recursive middleware allows for including requests in other # requests or forwarding of requests, all on the server side. if asbool(conf.get('use_recursive', True)): from paste import recursive app = recursive.RecursiveMiddleware( app, conf ) log.debug( "Enabling 'recursive' middleware" ) # If sentry logging is enabled, log here before propogating up to # the error middleware sentry_dsn = conf.get( 'sentry_dsn', None ) if sentry_dsn: from galaxy.web.framework.middleware.sentry import Sentry app = Sentry( app, sentry_dsn ) # Various debug middleware that can only be turned on if the debug # flag is set, either because they are insecure or greatly hurt # performance if debug: # Middleware to check for WSGI compliance if asbool( conf.get( 'use_lint', False ) ): from paste import lint app = lint.make_middleware( app, conf ) log.debug( "Enabling 'lint' middleware" ) # Middleware to run the python profiler on each request if asbool( conf.get( 'use_profile', False ) ): from paste.debug import profile app = profile.ProfileMiddleware( app, conf ) log.debug( "Enabling 'profile' middleware" ) if debug and asbool( conf.get( 'use_interactive', False ) ) and not process_is_uwsgi: # Interactive exception debugging, scary dangerous if publicly # accessible, if not enabled we'll use the regular error printing # middleware. from weberror import evalexception app = evalexception.EvalException( app, conf, templating_formatters=build_template_error_formatters() ) log.debug( "Enabling 'eval exceptions' middleware" ) else: if debug and asbool( conf.get( 'use_interactive', False ) ) and process_is_uwsgi: log.error("Interactive debugging middleware is enabled in your configuration " "but this is a uwsgi process. Refusing to wrap in interactive error middleware.") # Not in interactive debug mode, just use the regular error middleware import galaxy.web.framework.middleware.error app = galaxy.web.framework.middleware.error.ErrorMiddleware( app, conf ) log.debug( "Enabling 'error' middleware" ) # Transaction logging (apache access.log style) if asbool( conf.get( 'use_translogger', True ) ): from galaxy.web.framework.middleware.translogger import TransLogger app = TransLogger( app ) log.debug( "Enabling 'trans logger' middleware" ) # Statsd request timing and profiling statsd_host = conf.get('statsd_host', None) if statsd_host: from galaxy.web.framework.middleware.statsd import StatsdMiddleware app = StatsdMiddleware( app, statsd_host, conf.get('statsd_port')) log.debug( "Enabling 'statsd' middleware" ) # X-Forwarded-Host handling from galaxy.web.framework.middleware.xforwardedhost import XForwardedHostMiddleware app = XForwardedHostMiddleware( app ) log.debug( "Enabling 'x-forwarded-host' middleware" ) # Request ID middleware from galaxy.web.framework.middleware.request_id import RequestIDMiddleware app = RequestIDMiddleware( app ) log.debug( "Enabling 'Request ID' middleware" ) return app
start_response('200 OK', [('Content-type','text/html')]) return ['Access granted to /attribute_test'] attribute_test.permission = UserIn(users=['james']) if __name__ == '__main__': from paste.httpserver import serve from authkit.authenticate import middleware def valid(environ, username, password): """ Sample, very insecure validation function """ return username == password app = httpexceptions.make_middleware(AuthorizeExampleApp()) app = middleware( app, setup_method='basic', basic_realm='Test Realm', basic_authenticate_function=valid ) print """ Clear the HTTP authentication first by closing your browser if you have been testing other basic authentication examples on the same port. You will be able to sign in as any user as long as the password is the same as the username, but all users apart from `james' will be denied access to the resources. """
def wrap_in_middleware(app, global_conf, **local_conf): """Based on the configuration wrap `app` in a set of common and useful middleware.""" # Merge the global and local configurations conf = global_conf.copy() conf.update(local_conf) debug = asbool(conf.get('debug', False)) # First put into place httpexceptions, which must be most closely # wrapped around the application (it can interact poorly with # other middleware): app = httpexceptions.make_middleware(app, conf) log.debug("Enabling 'httpexceptions' middleware") # The recursive middleware allows for including requests in other # requests or forwarding of requests, all on the server side. if asbool(conf.get('use_recursive', True)): from paste import recursive app = recursive.RecursiveMiddleware(app, conf) log.debug("Enabling 'recursive' middleware") # Various debug middleware that can only be turned on if the debug # flag is set, either because they are insecure or greatly hurt # performance if debug: # Middleware to check for WSGI compliance if asbool(conf.get('use_lint', True)): from paste import lint app = lint.make_middleware(app, conf) log.debug("Enabling 'lint' middleware") # Middleware to run the python profiler on each request if asbool(conf.get('use_profile', False)): import profile app = profile.ProfileMiddleware(app, conf) log.debug("Enabling 'profile' middleware") # Middleware that intercepts print statements and shows them on the # returned page if asbool(conf.get('use_printdebug', True)): from paste.debug import prints app = prints.PrintDebugMiddleware(app, conf) log.debug("Enabling 'print debug' middleware") if debug and asbool(conf.get('use_interactive', False)): # Interactive exception debugging, scary dangerous if publicly # accessible, if not enabled we'll use the regular error printing # middleware. pkg_resources.require("WebError") from weberror import evalexception app = evalexception.EvalException(app, conf, templating_formatters=build_template_error_formatters()) log.debug("Enabling 'eval exceptions' middleware") else: # Not in interactive debug mode, just use the regular error middleware from paste.exceptions import errormiddleware app = errormiddleware.ErrorMiddleware(app, conf, show_exceptions_in_wsgi_errors=True, error_log=log) log.debug("Enabling 'error' middleware") # Transaction logging (apache access.log style) if asbool(conf.get('use_translogger', True)): from paste.translogger import TransLogger app = TransLogger(app) log.debug("Enabling 'trans logger' middleware") # Config middleware just stores the paste config along with the request, # not sure we need this but useful from paste.deploy.config import ConfigMiddleware app = ConfigMiddleware(app, conf) log.debug("Enabling 'config' middleware") # X-Forwarded-Host handling from cm.framework.middleware.xforwardedhost import XForwardedHostMiddleware app = XForwardedHostMiddleware(app) log.debug("Enabling 'x-forwarded-host' middleware") # Paste digest authentication ud = misc.load_yaml_file(paths.USER_DATA_FILE) if ud.get('password', ''): from paste.auth.basic import AuthBasicHandler app = AuthBasicHandler(app, 'CM Administration', cm_authfunc) return app
def make_middleware( app, global_conf, **local_conf ): """ Based on the configuration wrap `app` in a set of common and useful middleware. """ # Merge the global and local configurations conf = global_conf.copy() conf.update(local_conf) debug = asbool( conf.get( 'debug', False ) ) # First put into place httpexceptions, which must be most closely # wrapped around the application (it can interact poorly with # other middleware): app = httpexceptions.make_middleware( app, conf ) log.debug( "Enabling 'httpexceptions' middleware" ) # The recursive middleware allows for including requests in other # requests or forwarding of requests, all on the server side. if asbool(conf.get('use_recursive', True)): from paste import recursive app = recursive.RecursiveMiddleware( app, conf ) log.debug( "Enabling 'recursive' middleware" ) # Session middleware puts a session factory into the environment if asbool( conf.get( 'use_session', True ) ): store = flup_session.MemorySessionStore() app = flup_session.SessionMiddleware( store, app ) log.debug( "Enabling 'flup session' middleware" ) # Beaker session middleware if asbool( conf.get( 'use_beaker_session', False ) ): pkg_resources.require( "Beaker" ) import beaker.session app = beaker.session.SessionMiddleware( app, conf ) log.debug( "Enabling 'beaker session' middleware" ) # Various debug middleware that can only be turned on if the debug # flag is set, either because they are insecure or greatly hurt # performance if debug: # Middleware to check for WSGI compliance if asbool( conf.get( 'use_lint', True ) ): from paste import lint app = lint.make_middleware( app, conf ) log.debug( "Enabling 'lint' middleware" ) # Middleware to run the python profiler on each request if asbool( conf.get( 'use_profile', False ) ): from paste.debug import profile app = profile.ProfileMiddleware( app, conf ) log.debug( "Enabling 'profile' middleware" ) # Interactive exception debugging, scary dangerous if publicly # accessible, if not enabled we'll use the regular error printing # middleware. if asbool( conf.get( 'use_interactive', False ) ): from paste import evalexception app = evalexception.EvalException( app, conf ) log.debug( "Enabling 'eval exceptions' middleware" ) else: from paste.exceptions import errormiddleware app = errormiddleware.ErrorMiddleware( app, conf ) log.debug( "Enabling 'error' middleware" ) # Middleware that intercepts print statements and shows them on the # returned page if asbool( conf.get( 'use_printdebug', True ) ): from paste.debug import prints app = prints.PrintDebugMiddleware( app, conf ) log.debug( "Enabling 'print debug' middleware" ) else: # Not in debug mode, just use the regular error middleware from paste.exceptions import errormiddleware app = errormiddleware.ErrorMiddleware( app, conf ) log.debug( "Enabling 'error' middleware" ) # Transaction logging (apache access.log style) if asbool( conf.get( 'use_translogger', True ) ): from paste.translogger import TransLogger app = TransLogger( app ) log.debug( "Enabling 'trans logger' middleware" ) # Config middleware just stores the paste config along with the request, # not sure we need this but useful from paste.deploy.config import ConfigMiddleware app = ConfigMiddleware( app, conf ) log.debug( "Enabling 'config' middleware" ) # X-Forwarded-Host handling app = XForwardedHostMiddleware( app ) log.debug( "Enabling 'x-forwarded-host' middleware" ) return app
def wrap_in_middleware(app, global_conf, **local_conf): """ Based on the configuration wrap `app` in a set of common and useful middleware. """ webapp = app # Merge the global and local configurations conf = global_conf.copy() conf.update(local_conf) debug = asbool(conf.get('debug', False)) # First put into place httpexceptions, which must be most closely # wrapped around the application (it can interact poorly with # other middleware): app = httpexceptions.make_middleware(app, conf) log.debug("Enabling 'httpexceptions' middleware") # Statsd request timing and profiling statsd_host = conf.get('statsd_host', None) if statsd_host: from galaxy.web.framework.middleware.statsd import StatsdMiddleware app = StatsdMiddleware(app, statsd_host, conf.get('statsd_port', 8125), conf.get('statsd_prefix', 'galaxy')) log.debug("Enabling 'statsd' middleware") # If we're using remote_user authentication, add middleware that # protects Galaxy from improperly configured authentication in the # upstream server single_user = conf.get('single_user', None) use_remote_user = asbool(conf.get('use_remote_user', False)) or single_user if use_remote_user: from galaxy.web.framework.middleware.remoteuser import RemoteUser app = RemoteUser( app, maildomain=conf.get('remote_user_maildomain', None), display_servers=util.listify(conf.get('display_servers', '')), single_user=single_user, admin_users=conf.get('admin_users', '').split(','), remote_user_header=conf.get('remote_user_header', 'HTTP_REMOTE_USER'), remote_user_secret_header=conf.get('remote_user_secret', None), normalize_remote_user_email=conf.get('normalize_remote_user_email', False)) # The recursive middleware allows for including requests in other # requests or forwarding of requests, all on the server side. if asbool(conf.get('use_recursive', True)): from paste import recursive app = recursive.RecursiveMiddleware(app, conf) log.debug("Enabling 'recursive' middleware") # If sentry logging is enabled, log here before propogating up to # the error middleware sentry_dsn = conf.get('sentry_dsn', None) if sentry_dsn: from galaxy.web.framework.middleware.sentry import Sentry app = Sentry(app, sentry_dsn) # Various debug middleware that can only be turned on if the debug # flag is set, either because they are insecure or greatly hurt # performance if debug: # Middleware to check for WSGI compliance if asbool(conf.get('use_lint', False)): from paste import lint app = lint.make_middleware(app, conf) log.debug("Enabling 'lint' middleware") # Middleware to run the python profiler on each request if asbool(conf.get('use_profile', False)): from paste.debug import profile app = profile.ProfileMiddleware(app, conf) log.debug("Enabling 'profile' middleware") if debug and asbool(conf.get('use_interactive', False)) and not process_is_uwsgi: # Interactive exception debugging, scary dangerous if publicly # accessible, if not enabled we'll use the regular error printing # middleware. from weberror import evalexception app = evalexception.EvalException( app, conf, templating_formatters=build_template_error_formatters()) log.debug("Enabling 'eval exceptions' middleware") else: if debug and asbool(conf.get('use_interactive', False)) and process_is_uwsgi: log.error( "Interactive debugging middleware is enabled in your configuration " "but this is a uwsgi process. Refusing to wrap in interactive error middleware." ) # Not in interactive debug mode, just use the regular error middleware import galaxy.web.framework.middleware.error app = galaxy.web.framework.middleware.error.ErrorMiddleware(app, conf) log.debug("Enabling 'error' middleware") # Transaction logging (apache access.log style) if asbool(conf.get('use_translogger', True)): from galaxy.web.framework.middleware.translogger import TransLogger app = TransLogger(app) log.debug("Enabling 'trans logger' middleware") # X-Forwarded-Host handling from galaxy.web.framework.middleware.xforwardedhost import XForwardedHostMiddleware app = XForwardedHostMiddleware(app) log.debug("Enabling 'x-forwarded-host' middleware") # Request ID middleware from galaxy.web.framework.middleware.request_id import RequestIDMiddleware app = RequestIDMiddleware(app) log.debug("Enabling 'Request ID' middleware") # api batch call processing middleware from galaxy.web.framework.middleware.batch import BatchMiddleware app = BatchMiddleware(webapp, app, {}) log.debug("Enabling 'Batch' middleware") return app
def wrap_in_middleware(app, global_conf, **local_conf): """Based on the configuration wrap `app` in a set of common and useful middleware.""" # Merge the global and local configurations conf = global_conf.copy() conf.update(local_conf) debug = asbool(conf.get('debug', False)) # First put into place httpexceptions, which must be most closely # wrapped around the application (it can interact poorly with # other middleware): app = httpexceptions.make_middleware(app, conf) log.debug("Enabling 'httpexceptions' middleware") # If we're using remote_user authentication, add middleware that # protects Galaxy from improperly configured authentication in the # upstream server if asbool(conf.get('use_remote_user', False)): from galaxy.webapps.tool_shed.framework.middleware.remoteuser import RemoteUser app = RemoteUser( app, maildomain=conf.get('remote_user_maildomain', None), display_servers=util.listify(conf.get('display_servers', '')), admin_users=conf.get('admin_users', '').split(','), remote_user_secret_header=conf.get('remote_user_secret', None)) log.debug("Enabling 'remote user' middleware") # The recursive middleware allows for including requests in other # requests or forwarding of requests, all on the server side. if asbool(conf.get('use_recursive', True)): from paste import recursive app = recursive.RecursiveMiddleware(app, conf) log.debug("Enabling 'recursive' middleware") # Various debug middleware that can only be turned on if the debug # flag is set, either because they are insecure or greatly hurt # performance if debug: # Middleware to check for WSGI compliance if asbool(conf.get('use_lint', True)): from paste import lint app = lint.make_middleware(app, conf) log.debug("Enabling 'lint' middleware") # Middleware to run the python profiler on each request if asbool(conf.get('use_profile', False)): import profile app = profile.ProfileMiddleware(app, conf) log.debug("Enabling 'profile' middleware") # Middleware that intercepts print statements and shows them on the # returned page if asbool(conf.get('use_printdebug', True)): from paste.debug import prints app = prints.PrintDebugMiddleware(app, conf) log.debug("Enabling 'print debug' middleware") if debug and asbool(conf.get('use_interactive', False)): # Interactive exception debugging, scary dangerous if publicly # accessible, if not enabled we'll use the regular error printing # middleware. pkg_resources.require("WebError") from weberror import evalexception app = evalexception.EvalException( app, conf, templating_formatters=build_template_error_formatters()) log.debug("Enabling 'eval exceptions' middleware") else: # Not in interactive debug mode, just use the regular error middleware import galaxy.web.framework.middleware.error app = galaxy.web.framework.middleware.error.ErrorMiddleware(app, conf) log.debug("Enabling 'error' middleware") # Transaction logging (apache access.log style) if asbool(conf.get('use_translogger', True)): from paste.translogger import TransLogger app = TransLogger(app) log.debug("Enabling 'trans logger' middleware") # If sentry logging is enabled, log here before propogating up to # the error middleware # TODO sentry config is duplicated between tool_shed/galaxy, refactor this. sentry_dsn = conf.get('sentry_dsn', None) if sentry_dsn: from galaxy.web.framework.middleware.sentry import Sentry log.debug("Enabling 'sentry' middleware") app = Sentry(app, sentry_dsn) # X-Forwarded-Host handling from galaxy.web.framework.middleware.xforwardedhost import XForwardedHostMiddleware app = XForwardedHostMiddleware(app) log.debug("Enabling 'x-forwarded-host' middleware") app = hg.Hg(app, conf) log.debug("Enabling hg middleware") return app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) app = httpexceptions.make_middleware(app, global_conf) # Routing/Session Middleware app = RoutesMiddleware(app, config["routes.map"], singleton=False) app = SessionMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) # This is our Crowd authentication layer - see who.ini for # configuration details app = make_who_with_config( app, global_conf, app_conf["who.config_file"], app_conf["who.log_file"], app_conf["who.log_level"] ) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config["pylons.errorware"]) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config["debug"]): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config["pylons.paths"]["static_files"]) app = Cascade([static_app, app]) app.config = config return app
def make_app(global_conf, full_stack=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether or not this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Load our Pylons configuration defaults load_environment(global_conf, app_conf) # initialize list of subscribers subscriber_list_filename = config.get('subscriber_list_filename') if subscriber_list_filename is not None: try: f = open(subscriber_list_filename) for line in f: line = line.strip() splitline = line.split() event, subscriber = splitline[:2] if len(splitline) == 3: critical = asbool(splitline[2]) else: critical = None assert subscriber.startswith("http"), "Subscriber url must start with http: '%s'" % subscriber subscribe_by_name(event, subscriber, critical) except IOError: pass # Load our default Pylons WSGI app and make g available app = pylons.wsgiapp.PylonsApp() try: f = open(config["password_file"]) config['username'], config['password'] = f.read().strip().split(":") f.close() except IOError: pass from cabochon.lib.event_queue import init_sender_threads app.globals.event_sender = init_sender_threads() # YOUR MIDDLEWARE # Put your own middleware here, so that any problems are caught by the error # handling middleware underneath if 'topp_admin_info_filename' in config: app = BasicAuthMiddleware(app, config) #optional security username = config.get('username', None) password = config.get('password', None) if username: #If there is no administrative info, the only means of #authentication is WSSE required = not 'topp_admin_info_filename' in config app = WSSEAuthMiddleware(app, {username : password}, required=required) app = SupervisorErrorMiddleware(app) # If errror handling and exception catching will be handled by middleware # for multiple apps, you will want to set full_stack = False in your config # file so that it can catch the problems. if asbool(full_stack): # Change HTTPExceptions to HTTP responses app = httpexceptions.make_middleware(app, global_conf) # Error Handling app = ErrorHandler(app, global_conf, error_template=error_template, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (if debug is disabled also # intercepts 500) #app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf) # Establish the Registry for this application app = RegistryManager(app) static_app = StaticURLParser(config['pylons.paths']['static_files']) javascripts_app = StaticJavascripts() app = Cascade([static_app, javascripts_app, app]) return app
def wrap_in_middleware( app, global_conf, **local_conf ): """ Based on the configuration wrap `app` in a set of common and useful middleware. """ # Merge the global and local configurations conf = global_conf.copy() conf.update(local_conf) debug = asbool( conf.get( 'debug', False ) ) # First put into place httpexceptions, which must be most closely # wrapped around the application (it can interact poorly with # other middleware): app = httpexceptions.make_middleware( app, conf ) log.debug( "Enabling 'httpexceptions' middleware" ) # If we're using remote_user authentication, add middleware that # protects Galaxy from improperly configured authentication in the # upstream server if asbool(conf.get( 'use_remote_user', False )): from galaxy.web.framework.middleware.remoteuser import RemoteUser app = RemoteUser( app, maildomain=conf.get( 'remote_user_maildomain', None ), ucsc_display_sites=conf.get( 'ucsc_display_sites', [] ) ) log.debug( "Enabling 'remote user' middleware" ) # The recursive middleware allows for including requests in other # requests or forwarding of requests, all on the server side. if asbool(conf.get('use_recursive', True)): from paste import recursive app = recursive.RecursiveMiddleware( app, conf ) log.debug( "Enabling 'recursive' middleware" ) # Various debug middleware that can only be turned on if the debug # flag is set, either because they are insecure or greatly hurt # performance if debug: # Middleware to check for WSGI compliance if asbool( conf.get( 'use_lint', True ) ): from paste import lint app = lint.make_middleware( app, conf ) log.debug( "Enabling 'lint' middleware" ) # Middleware to run the python profiler on each request if asbool( conf.get( 'use_profile', False ) ): import profile app = profile.ProfileMiddleware( app, conf ) log.debug( "Enabling 'profile' middleware" ) # Middleware that intercepts print statements and shows them on the # returned page if asbool( conf.get( 'use_printdebug', True ) ): from paste.debug import prints app = prints.PrintDebugMiddleware( app, conf ) log.debug( "Enabling 'print debug' middleware" ) if debug and asbool( conf.get( 'use_interactive', False ) ): # Interactive exception debugging, scary dangerous if publicly # accessible, if not enabled we'll use the regular error printing # middleware. pkg_resources.require( "WebError" ) from weberror import evalexception app = evalexception.EvalException( app, conf, templating_formatters=build_template_error_formatters() ) log.debug( "Enabling 'eval exceptions' middleware" ) else: # Not in interactive debug mode, just use the regular error middleware if sys.version_info[:2] >= ( 2, 6 ): warnings.filterwarnings( 'ignore', '.*', DeprecationWarning, '.*serial_number_generator', 11, True ) from paste.exceptions import errormiddleware warnings.filters.pop() else: from paste.exceptions import errormiddleware app = errormiddleware.ErrorMiddleware( app, conf ) log.debug( "Enabling 'error' middleware" ) # Transaction logging (apache access.log style) if asbool( conf.get( 'use_translogger', True ) ): from paste.translogger import TransLogger app = TransLogger( app ) log.debug( "Enabling 'trans logger' middleware" ) # Config middleware just stores the paste config along with the request, # not sure we need this but useful from paste.deploy.config import ConfigMiddleware app = ConfigMiddleware( app, conf ) log.debug( "Enabling 'config' middleware" ) # X-Forwarded-Host handling from galaxy.web.framework.middleware.xforwardedhost import XForwardedHostMiddleware app = XForwardedHostMiddleware( app ) log.debug( "Enabling 'x-forwarded-host' middleware" ) return app
def wrap_in_middleware( app, global_conf, **local_conf ): """Based on the configuration wrap `app` in a set of common and useful middleware.""" # Merge the global and local configurations conf = global_conf.copy() conf.update( local_conf ) debug = asbool( conf.get( 'debug', False ) ) # First put into place httpexceptions, which must be most closely # wrapped around the application (it can interact poorly with # other middleware): app = httpexceptions.make_middleware( app, conf ) log.debug( "Enabling 'httpexceptions' middleware" ) # If we're using remote_user authentication, add middleware that # protects Galaxy from improperly configured authentication in the # upstream server if asbool(conf.get( 'use_remote_user', False )): from galaxy.webapps.tool_shed.framework.middleware.remoteuser import RemoteUser app = RemoteUser( app, maildomain = conf.get( 'remote_user_maildomain', None ), display_servers = util.listify( conf.get( 'display_servers', '' ) ), admin_users = conf.get( 'admin_users', '' ).split( ',' ), remote_user_secret_header = conf.get('remote_user_secret', None) ) log.debug( "Enabling 'remote user' middleware" ) # The recursive middleware allows for including requests in other # requests or forwarding of requests, all on the server side. if asbool(conf.get('use_recursive', True)): from paste import recursive app = recursive.RecursiveMiddleware( app, conf ) log.debug( "Enabling 'recursive' middleware" ) # Various debug middleware that can only be turned on if the debug # flag is set, either because they are insecure or greatly hurt # performance if debug: # Middleware to check for WSGI compliance if asbool( conf.get( 'use_lint', True ) ): from paste import lint app = lint.make_middleware( app, conf ) log.debug( "Enabling 'lint' middleware" ) # Middleware to run the python profiler on each request if asbool( conf.get( 'use_profile', False ) ): import profile app = profile.ProfileMiddleware( app, conf ) log.debug( "Enabling 'profile' middleware" ) # Middleware that intercepts print statements and shows them on the # returned page if asbool( conf.get( 'use_printdebug', True ) ): from paste.debug import prints app = prints.PrintDebugMiddleware( app, conf ) log.debug( "Enabling 'print debug' middleware" ) if debug and asbool( conf.get( 'use_interactive', False ) ): # Interactive exception debugging, scary dangerous if publicly # accessible, if not enabled we'll use the regular error printing # middleware. pkg_resources.require( "WebError" ) from weberror import evalexception app = evalexception.EvalException( app, conf, templating_formatters=build_template_error_formatters() ) log.debug( "Enabling 'eval exceptions' middleware" ) else: # Not in interactive debug mode, just use the regular error middleware import galaxy.web.framework.middleware.error app = galaxy.web.framework.middleware.error.ErrorMiddleware( app, conf ) log.debug( "Enabling 'error' middleware" ) # Transaction logging (apache access.log style) if asbool( conf.get( 'use_translogger', True ) ): from paste.translogger import TransLogger app = TransLogger( app ) log.debug( "Enabling 'trans logger' middleware" ) # If sentry logging is enabled, log here before propogating up to # the error middleware # TODO sentry config is duplicated between tool_shed/galaxy, refactor this. sentry_dsn = conf.get( 'sentry_dsn', None ) if sentry_dsn: from galaxy.web.framework.middleware.sentry import Sentry log.debug( "Enabling 'sentry' middleware" ) app = Sentry( app, sentry_dsn ) # X-Forwarded-Host handling from galaxy.web.framework.middleware.xforwardedhost import XForwardedHostMiddleware app = XForwardedHostMiddleware( app ) log.debug( "Enabling 'x-forwarded-host' middleware" ) app = hg.Hg( app, conf ) log.debug( "Enabling hg middleware" ) return app