Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions coco/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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

Expand Down Expand Up @@ -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",
}
Expand Down
14 changes: 7 additions & 7 deletions coco/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
CocoForward,
RequestForwarder,
)
from .result import Result
from .state import State
from .util import Host, PersistentState, str2total_seconds

Expand Down Expand Up @@ -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, "/<endpoint>", methods=["GET", "POST"]
)
Expand Down Expand Up @@ -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),
}

Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}

Expand Down