From 4149c3eefd8336f9c296a07e78ffc32324533123 Mon Sep 17 00:00:00 2001 From: KatHellg Date: Wed, 13 Nov 2024 16:20:20 +0100 Subject: [PATCH] trying to add get_client function again --- fedn/cli/client_cmd.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/fedn/cli/client_cmd.py b/fedn/cli/client_cmd.py index 586b124e..12a19c2e 100644 --- a/fedn/cli/client_cmd.py +++ b/fedn/cli/client_cmd.py @@ -69,6 +69,40 @@ def list_clients(ctx, protocol: str, host: str, port: str, token: str = None, n_ except requests.exceptions.ConnectionError: click.echo(f"Error: Could not connect to {url}") +@click.option("-p", "--protocol", required=False, default=CONTROLLER_DEFAULTS["protocol"], help="Communication protocol of controller (api)") +@click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") +@click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") +@click.option("-t", "--token", required=False, help="Authentication token") +@click.option("-id", "--id", required=True, help="Client ID") +@client_cmd.command("get") +@click.pass_context +def get_client(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None): + """Return: + ------ + - result: client with given id + + """ + url = get_api_url(protocol=protocol, host=host, port=port, endpoint="clients") + headers = {} + + + _token = get_token(token) + + if _token: + headers["Authorization"] = _token + + if id: + url = f"{url}{id}" + + + click.echo(f"\nRetrieving client: {url}\n") + click.echo(f"Headers: {headers}") + try: + response = requests.get(url, headers=headers) + print_response(response, "client", id) + except requests.exceptions.ConnectionError: + click.echo(f"Error: Could not connect to {url}") + @client_cmd.command("start-v1") @click.option("-d", "--discoverhost", required=False, help="Hostname for discovery services(reducer).")