-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
KatHellg
committed
Nov 26, 2024
1 parent
c9bacbe
commit 4273a00
Showing
4 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
access: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzM1MjEwMjY5LCJpYXQiOjE3MzI2MTgyNjksImp0aSI6ImIxNDY4ODVlMzM4NTRiYWRhM2I3YTExODUyNzJjOTNjIiwidXNlcl9pZCI6MzQ3LCJjcmVhdG9yIjoiS2F0amFIIiwicm9sZSI6bnVsbCwicHJvamVjdF9zbHVnIjoiIn0.aUpJTSQYe_yTi2QiY0yzhdaAjkS9gd07o4V3X5f6LCg | ||
refresh: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTc0MDM5NDI2OSwiaWF0IjoxNzMyNjE4MjY5LCJqdGkiOiI3M2NmNDhhNDE3Mjc0ZTVlYTUwNTA5YWNiZDBlNDI4MyIsInVzZXJfaWQiOjM0NywiY3JlYXRvciI6IkthdGphSCIsInJvbGUiOm51bGwsInByb2plY3Rfc2x1ZyI6IiJ9.Y1sSbRKlI07kLv2p3YlCwP5lEKUBTOH-QqiOhVG9NBo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import os | ||
import yaml | ||
import click | ||
import requests | ||
|
||
from .main import main | ||
from getpass import getpass | ||
|
||
# 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 | ||
def login_cmd(ctx): | ||
""":param ctx:""" | ||
pass | ||
|
||
|
||
@login_cmd.command("login") | ||
@click.pass_context | ||
def login_cmd(ctx): | ||
"""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/" | ||
|
||
# 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.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") | ||
click.secho(str(e), fg="red") | ||
return | ||
|
||
# Handle the response | ||
if response.status_code == 200: | ||
data = response.json() | ||
if data.get("access"): | ||
click.secho("Login successful!", fg="green") | ||
context_path = os.path.join(home_dir, ".fedn") | ||
if not os.path.exists(context_path): | ||
os.makedirs(context_path) | ||
try: | ||
with open(f"{context_path}/context.yaml", "w") as yaml_file: | ||
yaml.dump(data, yaml_file, default_flow_style=False) # Add access and refresh tokens to context yaml file | ||
except Exception as e: | ||
print(f"Error: Failed to write to YAML file. Details: {e}") | ||
else: | ||
click.secho("Login failed. Please check your credentials.", fg="red") | ||
else: | ||
click.secho(f"Unexpected error: {response.text}", fg="red") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters