From b5ddc105852b63651916f322ce855baf61d129d0 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 18 Nov 2020 08:47:37 +0200 Subject: feat! change client config to take a base URL instead of host, port --- subplot/client.py | 6 ++---- subplot/server.py | 12 +++++------- 2 files changed, 7 insertions(+), 11 deletions(-) (limited to 'subplot') diff --git a/subplot/client.py b/subplot/client.py index f159e74..7556986 100644 --- a/subplot/client.py +++ b/subplot/client.py @@ -14,13 +14,11 @@ def install_obnam(ctx): def configure_client(ctx, filename=None): get_file = globals()["get_file"] - assert ctx.get("server_name") is not None - assert ctx.get("server_port") is not None + assert ctx.get("server_url") is not None config = get_file(filename) config = yaml.safe_load(config) - config["server_name"] = ctx["server_name"] - config["server_port"] = ctx["server_port"] + config["server_url"] = ctx["server_url"] with open(filename, "w") as f: yaml.safe_dump(config, stream=f) diff --git a/subplot/server.py b/subplot/server.py index c159798..5952cb2 100644 --- a/subplot/server.py +++ b/subplot/server.py @@ -33,9 +33,7 @@ def start_chunk_server(ctx): logging.debug(f"Picked randomly port for obnam-server: {config['port']}") ctx["config"] = config - ctx["server_name"] = "localhost" - ctx["server_port"] = port - ctx["url"] = f"http://localhost:{port}" + ctx["server_url"] = f"http://localhost:{port}/chunks" start_daemon( ctx, @@ -55,7 +53,7 @@ def stop_chunk_server(ctx): def post_file(ctx, filename=None, path=None, header=None, json=None): - url = f"{ctx['url']}/chunks" + url = f"{ctx['server_url']}" headers = {header: json} data = open(filename, "rb").read() _request(ctx, requests.post, url, headers=headers, data=data) @@ -67,12 +65,12 @@ def get_chunk_via_var(ctx, var=None): def get_chunk_by_id(ctx, chunk_id=None): - url = f"{ctx['url']}/chunks/{chunk_id}" + url = f"{ctx['server_url']}/{chunk_id}" _request(ctx, requests.get, url) def find_chunks_with_sha(ctx, sha=None): - url = f"{ctx['url']}/chunks?sha256={sha}" + url = f"{ctx['server_url']}?sha256={sha}" _request(ctx, requests.get, url) @@ -82,7 +80,7 @@ def delete_chunk_via_var(ctx, var=None): def delete_chunk_by_id(ctx, chunk_id=None): - url = f"{ctx['url']}/chunks/{chunk_id}" + url = f"{ctx['server_url']}/{chunk_id}" _request(ctx, requests.delete, url) -- cgit v1.2.1