diff --git a/coco/client.py b/coco/client.py index 855087f..2ac1571 100644 --- a/coco/client.py +++ b/coco/client.py @@ -418,7 +418,7 @@ def _init_coco(self, ctx: click.Context) -> None: # Get the coco config from the daemon try: conn = http.client.HTTPConnection(host, port, timeout=2) - conn.request("GET", "/get-coco-config", headers={"Host": host}) + conn.request("GET", "/config", headers={"Host": host}) res = conn.getresponse() except TimeoutError as e: raise click.ClickException( @@ -445,12 +445,10 @@ def _init_coco(self, ctx: click.Context) -> None: # Decode try: - data = json.loads(data) + coco_config = json.loads(data) except json.JSONDecodeError as e: raise click.ClickError(f"Failure parsing config from server: {e}") from e - coco_config = data["coco-config"]["http://coco/"]["reply"] - # Record it ctx.obj["coco_config"] = coco_config @@ -1068,7 +1066,7 @@ def get_config(ctx): + ctx.obj["coco_config"]["host"] + ":" + str(ctx.obj["coco_config"]["port"]) - + "/get-coco-config" + + "/config" ), "method": "GET", } diff --git a/coco/core.py b/coco/core.py index 02641bf..da78060 100644 --- a/coco/core.py +++ b/coco/core.py @@ -32,7 +32,6 @@ CocoForward, RequestForwarder, ) -from .result import Result from .state import State from .util import Host, PersistentState, str2total_seconds @@ -284,6 +283,8 @@ async def stop_slack_log(*_): self.sanic_app.register_listener(start_slack_log, "before_server_start") self.sanic_app.register_listener(stop_slack_log, "after_server_stop") + self.sanic_app.add_route(self._get_config, "/config", methods=["GET"]) + self.sanic_app.add_route( self.external_endpoint, "/", methods=["GET", "POST"] ) @@ -450,7 +451,6 @@ def _local_endpoints(self): "reset-state": ("POST", self.state.reset_state), "save-state": ("POST", self.state.save_state), "load-state": ("POST", self.state.load_state), - "get-coco-config": ("GET", self._get_config), "wait": ("POST", wait.process_post), } @@ -459,11 +459,11 @@ def _local_endpoints(self): self.forwarder.add_endpoint(name, self.endpoints[name]) async def _get_config(self, _): - return Result( - "coco-config", - result={Host("coco"): (self.config, 200)}, - type_="FULL", - ) + """Sanic handler for the /config route. + + Returns the coco config. + """ + return response.json(self.config) def _check_endpoint_links(self): def check(e): diff --git a/tests/test_client.py b/tests/test_client.py index 4c1c762..6564f5b 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -111,7 +111,7 @@ def test_show_call(coco_runner): coco_runner.client("--show-call-only", "--json", "config", "get").output ) assert result == { - "endpoint": f"http://127.0.0.1:{coco_runner.port}/get-coco-config", + "endpoint": f"http://127.0.0.1:{coco_runner.port}/config", "method": "GET", }