From 5c2b934a61b41847294de64fc93fa63105997138 Mon Sep 17 00:00:00 2001 From: KatHellg Date: Wed, 27 Nov 2024 21:07:42 +0100 Subject: [PATCH] define host + protocol in cmd args --- fedn/cli/login_cmd.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/fedn/cli/login_cmd.py b/fedn/cli/login_cmd.py index e40012eb4..d2ce8ac90 100644 --- a/fedn/cli/login_cmd.py +++ b/fedn/cli/login_cmd.py @@ -10,8 +10,6 @@ # Replace this with the platform's actual login endpoint home_dir = os.path.expanduser("~") -DEFAULT_URL = "https://fedn.scaleoutsystems.com" - @main.group("studio") @click.pass_context @@ -21,18 +19,15 @@ def login_cmd(ctx): @login_cmd.command("login") +@click.option("-p", "--protocol", required=False, default="https", help="Communication protocol") +@click.option("-H", "--host", required=False, default="fedn.scaleoutsystems.com", help="Hostname of controller (api)") @click.pass_context -def login_cmd(ctx): +def login_cmd(ctx, protocol: str, host: str): """Logging into FEDn Studio""" # Step 1: Display welcome message click.secho("Welcome to Scaleout FEDn!", fg="green") - # Step 2: Prompt for domain - domain = input("Please enter your domain or press enter to use default domain: ").strip() - if domain: - URL = f"https//:{domain}/api/token/" - else: - URL = f"{DEFAULT_URL}/api/token/" + url = f"{protocol}://{host}/api/token/" # Step 3: Prompt for username and password username = input("Please enter your username: ") @@ -40,7 +35,7 @@ def login_cmd(ctx): # Call the authentication API try: - response = requests.post(URL, json={"username": username, "password": password}, headers={"Content-Type": "application/json"}) + response = requests.post(url, json={"username": username, "password": password}, headers={"Content-Type": "application/json"}) response.raise_for_status() # Raise an error for HTTP codes 4xx/5xx except requests.exceptions.RequestException as e: click.secho("Error connecting to the platform. Please try again.", fg="red")