Skip to content

Commit

Permalink
add check
Browse files Browse the repository at this point in the history
  • Loading branch information
panh99 committed Jan 22, 2025
1 parent 48ac493 commit 7b5222e
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/py/flwr/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,20 +238,21 @@ def try_obtain_cli_auth_plugin(

config_path = get_user_auth_config_path(root_dir, federation)

# Load the config file if it exists
json_file: dict[str, Any] = {}
if config_path.exists():
with config_path.open("r", encoding="utf-8") as file:
json_file = json.load(file)
# This is the case when the user auth is not enabled
elif auth_type is None:
return None

# Get the auth type from the config if not provided
# auth_type will be None for all CLI commands except login
if auth_type is None:
if AUTH_TYPE not in json_file:
return None
auth_type = json_file[AUTH_TYPE]
try:
with config_path.open("r", encoding="utf-8") as file:
json_file = json.load(file)
auth_type = json_file[AUTH_TYPE]
except (FileNotFoundError, KeyError):
typer.secho(
"❌ Missing or invalid credentials for user authentication. "
"Please run `flwr login` to authenticate.",
fg=typer.colors.RED,
bold=True,
)
raise typer.Exit(code=1) from None

# Retrieve auth plugin class and instantiate it
try:
Expand Down

0 comments on commit 7b5222e

Please sign in to comment.