Skip to content

Commit

Permalink
added login functionality + fixed misspelling in dist file
Browse files Browse the repository at this point in the history
  • Loading branch information
KatHellg committed Nov 25, 2024
1 parent 334edf8 commit 4fdce80
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
2 changes: 2 additions & 0 deletions fedn/.fedn/context.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
access: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzM1MTQ3MDkwLCJpYXQiOjE3MzI1NTUwOTAsImp0aSI6Ijg2NzQzYjk3MDBjZDQ1MTNhYTk1NDMxMjdjNDhiNWQ1IiwidXNlcl9pZCI6MzQ3LCJjcmVhdG9yIjoiS2F0amFIIiwicm9sZSI6bnVsbCwicHJvamVjdF9zbHVnIjoiIn0.s0NAjUBGGv6Iwv-iDBdW13zMLigB4sgfKSL245lUKks
refresh: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTc0MDMzMTA5MCwiaWF0IjoxNzMyNTU1MDkwLCJqdGkiOiJjODQ3MjYwY2YwNmY0Yjk0YjBlODdkMDJlZDEyYzI5NCIsInVzZXJfaWQiOjM0NywiY3JlYXRvciI6IkthdGphSCIsInJvbGUiOm51bGwsInByb2plY3Rfc2x1ZyI6IiJ9.W5G8WBIZyHX7ym3GpBjalfAM9HIAKQIp5A5ZPwRK918
1 change: 1 addition & 0 deletions fedn/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
from .status_cmd import status_cmd # noqa: F401
from .validation_cmd import validation_cmd # noqa: F401
from .controller_cmd import controller_cmd # noqa: F401
from .login_cmd import login_cmd # noqa: F401
62 changes: 62 additions & 0 deletions fedn/cli/login_cmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import uuid
import json
import yaml
import os

import click
import requests

from .main import main
from getpass import getpass

# Replace this with the platform's actual login endpoint
URL = "https://fedn.scaleoutsystems.com/api/token/"
context_file_path = "../fedn/fedn/.fedn/context.yaml"

@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 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')
try:
with open(context_file_path, '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')
2 changes: 1 addition & 1 deletion fedn/utils/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import fedn


def get_version(pacakge):
def get_version(package):
# Dynamically get the version of the package
try:
version = importlib.metadata.version("fedn")
Expand Down

0 comments on commit 4fdce80

Please sign in to comment.