Skip to content

Commit

Permalink
define host + protocol in cmd args
Browse files Browse the repository at this point in the history
  • Loading branch information
KatHellg committed Nov 27, 2024
1 parent 5030a24 commit 5c2b934
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions fedn/cli/login_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,26 +19,23 @@ 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: ")
password = getpass("Please enter your password: ")

# 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")
Expand Down

0 comments on commit 5c2b934

Please sign in to comment.