def wrapper(request, *args, **kw): auth_candidates = [] for auth in PluginManager().get_hook_callables('auth'): if auth.trigger(request): _log.debug( '{0} believes it is capable of authenticating this request.' .format(auth)) auth_candidates.append(auth) # If we can't find any authentication methods, we should not let them # pass. if not auth_candidates: raise Forbidden() # For now, just select the first one in the list auth = auth_candidates[0] _log.debug('Using {0} to authorize request {1}'.format( auth, request.url)) if not auth(request, *args, **kw): if getattr(auth, 'errors', []): return json_response({'status': 403, 'errors': auth.errors}) raise Forbidden() return controller(request, *args, **kw)
def get_url_map(): add_route('index', '/', 'mediagoblin.views:root_view') mount('/auth', auth_routes) mount('/a', admin_routes) import mediagoblin.submit.routing import mediagoblin.user_pages.routing import mediagoblin.edit.routing import mediagoblin.webfinger.routing import mediagoblin.listings.routing import mediagoblin.notifications.routing import mediagoblin.oauth.routing for route in PluginManager().get_routes(): add_route(*route) return url_map
def get_url_map(): add_route('index', '/', 'mediagoblin.views:root_view') add_route('terms_of_service', '/terms_of_service', 'mediagoblin.views:terms_of_service'), mount('/auth', auth_routes) mount('/mod', moderation_routes) import mediagoblin.submit.routing import mediagoblin.user_pages.routing import mediagoblin.edit.routing import mediagoblin.listings.routing import mediagoblin.notifications.routing import mediagoblin.oauth.routing import mediagoblin.federation.routing for route in PluginManager().get_routes(): add_route(*route) return url_map
def __init__(self, config_path, setup_celery=True): """ Initialize the application based on a configuration file. Arguments: - config_path: path to the configuration file we're opening. - setup_celery: whether or not to setup celery during init. (Note: setting 'celery_setup_elsewhere' also disables setting up celery.) """ _log.info("GNU MediaGoblin %s main server starting", __version__) _log.debug("Using config file %s", config_path) ############## # Setup config ############## # Open and setup the config global_config, app_config = setup_global_and_app_config(config_path) media_type_warning() setup_crypto() ########################################## # Setup other connections / useful objects ########################################## # Setup Session Manager, not needed in celery self.session_manager = session.SessionManager() # load all available locales setup_locales() # Set up plugins -- need to do this early so that plugins can # affect startup. _log.info("Setting up plugins.") setup_plugins() # Set up the database self.db = setup_database(app_config['run_migrations']) # Quit app if need to run dbupdate check_db_up_to_date() # Register themes self.theme_registry, self.current_theme = register_themes(app_config) # Get the template environment self.template_loader = get_jinja_loader( app_config.get('local_templates'), self.current_theme, PluginManager().get_template_paths() ) # Check if authentication plugin is enabled and respond accordingly. self.auth = check_auth_enabled() if not self.auth: app_config['allow_comments'] = False # Set up storage systems self.public_store, self.queue_store = setup_storage() # set up routing self.url_map = get_url_map() # set up staticdirector tool self.staticdirector = get_staticdirector(app_config) # Setup celery, if appropriate if setup_celery and not app_config.get('celery_setup_elsewhere'): if os.environ.get('CELERY_ALWAYS_EAGER', 'false').lower() == 'true': setup_celery_from_config( app_config, global_config, force_celery_always_eager=True) else: setup_celery_from_config(app_config, global_config) ####################################################### # Insert appropriate things into mediagoblin.mg_globals # # certain properties need to be accessed globally eg from # validators, etc, which might not access to the request # object. ####################################################### setup_globals(app=self) # Workbench *currently* only used by celery, so this only # matters in always eager mode :) setup_workbench() # instantiate application meddleware self.meddleware = [common.import_component(m)(self) for m in meddleware.ENABLED_MEDDLEWARE]