Skip to content

Commit

Permalink
fedn config - to see env:s set
Browse files Browse the repository at this point in the history
  • Loading branch information
niklastheman committed Apr 26, 2024
1 parent 1d6f730 commit bf2eaf1
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
1 change: 1 addition & 0 deletions fedn/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .client_cmd import client_cmd # noqa: F401
from .combiner_cmd import combiner_cmd # noqa: F401
from .config_cmd import config_cmd # noqa: F401
from .main import main # noqa: F401
from .model_cmd import model_cmd # noqa: F401
from .package_cmd import package_cmd # noqa: F401
Expand Down
54 changes: 54 additions & 0 deletions fedn/cli/config_cmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import os

import click

from .main import main

envs = [
{
"name": "FEDN_CONTROLLER_PROTOCOL",
"description": "The protocol to use for communication with the controller."
},
{
"name": "FEDN_CONTROLLER_HOST",
"description": "The host to use for communication with the controller."
},
{
"name": "FEDN_CONTROLLER_PORT",
"description": "The port to use for communication with the controller."
},
{
"name": "FEDN_AUTH_TOKEN",
"description": "The authentication token to use for communication with the controller and combiner."
},
{
"name": "FEDN_AUTH_SCHEME",
"description": "The authentication scheme to use for communication with the controller and combiner."
},
{
"name": "FEDN_CONTROLLER_URL",
"description": "The URL of the controller. Overrides FEDN_CONTROLLER_PROTOCOL, FEDN_CONTROLLER_HOST and FEDN_CONTROLLER_PORT."
},
{
"name": "FEDN_PACKAGE_EXTRACT_DIR",
"description": "The directory to extract packages to."
}
]


@main.group('config', invoke_without_command=True)
@click.pass_context
def config_cmd(ctx):
"""
- Configuration commands for the FEDn CLI.
"""
if ctx.invoked_subcommand is None:
click.echo('\n--- FEDn Cli Configuration ---\n')
click.echo('Current configuration:\n')

for env in envs:
name = env['name']
value = os.environ.get(name)
click.echo(f'{name}: {value or "Not set"}')
click.echo(f'{env["description"]}\n')
click.echo('\n')
8 changes: 4 additions & 4 deletions fedn/cli/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ def get_api_url(protocol: str, host: str, port: str, endpoint: str) -> str:
if _url:
return f'{_url}/api/{API_VERSION}/{endpoint}'

_protocol = protocol or os.environ.get('FEDN_PROTOCOL') or CONTROLLER_DEFAULTS['protocol']
_host = host or os.environ.get('FEDN_HOST') or CONTROLLER_DEFAULTS['host']
_port = port or os.environ.get('FEDN_PORT') or CONTROLLER_DEFAULTS['port']
_protocol = protocol or os.environ.get('FEDN_CONTROLLER_PROTOCOL') or CONTROLLER_DEFAULTS['protocol']
_host = host or os.environ.get('FEDN_CONTROLLER_HOST') or CONTROLLER_DEFAULTS['host']
_port = port or os.environ.get('FEDN_CONTROLLER_PORT') or CONTROLLER_DEFAULTS['port']

return f'{_protocol}://{_host}:{_port}/api/{API_VERSION}/{endpoint}'


def get_token(token: str) -> str:
_token = token or os.environ.get("FEDN_TOKEN", None)
_token = token or os.environ.get("FEDN_AUTH_TOKEN", None)

if _token is None:
return None
Expand Down

0 comments on commit bf2eaf1

Please sign in to comment.