async def configure_source(self, request): source_name = request.match_info["source"] label = request.match_info["label"] config = await request.json() try: source = BaseSource.load_labeled(f"{label}={source_name}") except EntrypointNotFound as error: self.logger.error( f"/configure/source/ failed to load source: {error}") return web.json_response( {"error": f"source {source_name} not found"}, status=HTTPStatus.NOT_FOUND, ) try: source = source.withconfig(config) except MissingConfig as error: return web.json_response({"error": str(error)}, status=HTTPStatus.BAD_REQUEST) # DFFML objects all follow a double context entry pattern exit_stack = request.app["exit_stack"] source = await exit_stack.enter_async_context(source) request.app["sources"][label] = source sctx = await exit_stack.enter_async_context(source()) request.app["source_contexts"][label] = sctx return web.json_response(OK)
async def list_sources(self, request): return web.json_response( { source.ENTRY_POINT_ORIG_LABEL: source.args({}) for source in BaseSource.load() }, dumps=partial(json.dumps, cls=JSONEncoder), )