def create_cdx_server_app(passed_config): """ Create a cdx server api-only app For each collection, create a /<coll>-cdx access point which follows the cdx api """ defaults = load_yaml_config(DEFAULT_CONFIG) config = DictChain(passed_config, defaults) collections = config.get('collections', {}) static_routes = {} # collections based on file system if config.get('enable_auto_colls', True): colls_loader_cls = config.get('colls_loader_cls', DirectoryCollsLoader) dir_loader = colls_loader_cls(config, static_routes, collections) dir_loader() #collections.update(dir_loader()) routes = [] for name, value in six.iteritems(collections): route_config = init_route_config(value, config) query_handler = init_collection(route_config) cdx_api_suffix = route_config.get('enable_cdx_api', True) add_cdx_api_handler(name, cdx_api_suffix, routes, query_handler) return ArchivalRouter(routes)
def create_live_rewriter_app(config={}): routes = [ Route('rewrite', RewriteHandler(config)), Route('static/__pywb', StaticHandler('pywb/static/')) ] return ArchivalRouter(routes, hostpaths=['http://localhost:8080'])
def _test_route_req(route, env, abs_path=False): matcher, coll = route.is_handling(env['REL_REQUEST_URI']) if not matcher: return the_router = ArchivalRouter([route], abs_path=abs_path) req = the_router.parse_request(route, env, matcher, coll, env['REL_REQUEST_URI'], abs_path) varlist = vars(req) the_dict = dict((k, varlist[k]) for k in ('request_uri', 'wb_prefix', 'wb_url', 'coll')) pprint.pprint(the_dict)
def create_perms_checker_app(config): """ Create permissions checker standalone app Running under the '/check-access' route """ port = config.get('port') perms_policy = config.get('perms_policy') canonicalizer = UrlCanonicalizer(config.get('surt_ordered', True)) handler = PermsHandler(perms_policy, canonicalizer) routes = [Route('check-access', handler)] return ArchivalRouter(routes, port=port)
def create_cdx_server_app(passed_config): """ Create a cdx server api-only app For each collection, create a /<coll>-cdx access point which follows the cdx api """ config = DictChain(passed_config, DEFAULTS) collections = config.get('collections') routes = [] for name, value in collections.iteritems(): route_config = init_route_config(value, config) query_handler = init_collection(route_config) cdx_api_suffix = route_config.get('enable_cdx_api', True) add_cdx_api_handler(name, cdx_api_suffix, routes, query_handler) return ArchivalRouter(routes)
def _test_redir(match_host, request_uri, referrer, script_name='', coll='coll'): env = { 'REL_REQUEST_URI': request_uri, 'HTTP_REFERER': referrer, 'SCRIPT_NAME': script_name } env['HTTP_HOST'] = urlsplit(match_host).netloc routes = [Route(coll, WbUrlHandler())] the_router = ArchivalRouter(routes) redir = ReferRedirect() #req = WbRequest.from_uri(request_uri, env) rep = redir(env, the_router) if not rep: return False return rep.status_headers.get_header('Location')