Skip to content

Commit

Permalink
inform user input file has priority over input params
Browse files Browse the repository at this point in the history
  • Loading branch information
niklastheman committed Apr 26, 2024
1 parent bf2eaf1 commit 1507981
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
12 changes: 9 additions & 3 deletions fedn/cli/client_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,19 @@ def client_cmd(ctx, discoverhost, discoverport, token, name, client_id, local_pa
config = {'discover_host': discoverhost, 'discover_port': discoverport, 'token': token, 'name': name,
'client_id': client_id, 'remote_compute_context': remote, 'force_ssl': force_ssl, 'dry_run': dry_run, 'secure': secure,
'preshared_cert': preshared_cert, 'verify': verify, 'preferred_combiner': preferred_combiner,
'validator': validator, 'trainer': trainer, 'init': init, 'logfile': logfile, 'heartbeat_interval': heartbeat_interval,
'validator': validator, 'trainer': trainer, 'logfile': logfile, 'heartbeat_interval': heartbeat_interval,
'reconnect_after_missed_heartbeat': reconnect_after_missed_heartbeat, 'verbosity': verbosity}

if init:
apply_config(config)
apply_config(init, config)
click.echo(f'\nClient configuration loaded from file: {init}')
click.echo('Values set in file override defaults and command line arguments...\n')

validate_client_config(config)
try:
validate_client_config(config)
except InvalidClientConfig as e:
click.echo(f'Error: {e}')
return

client = Client(config)
client.run()
9 changes: 5 additions & 4 deletions fedn/cli/combiner_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ def start_cmd(ctx, discoverhost, discoverport, token, name, host, port, fqdn, se
:param init:
"""
config = {'discover_host': discoverhost, 'discover_port': discoverport, 'token': token, 'host': host,
'port': port, 'fqdn': fqdn, 'name': name, 'secure': secure, 'verify': verify, 'max_clients': max_clients,
'init': init}
'port': port, 'fqdn': fqdn, 'name': name, 'secure': secure, 'verify': verify, 'max_clients': max_clients}

if config['init']:
apply_config(config)
if init:
apply_config(init, config)
click.echo(f'\nCombiner configuration loaded from file: {init}')
click.echo('Values set in file override defaults and command line arguments...\n')

combiner = Combiner(config)
combiner.run()
Expand Down
8 changes: 4 additions & 4 deletions fedn/cli/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
API_VERSION = 'v1'


def apply_config(config):
def apply_config(path: str, config: dict):
"""Parse client config from file.
Override configs from the CLI with settings in config file.
:param config: Client config (dict).
"""
with open(config['init'], 'r') as file:
with open(path, 'r') as file:
try:
settings = dict(yaml.safe_load(file))
except Exception:
Expand All @@ -51,13 +51,13 @@ def get_api_url(protocol: str, host: str, port: str, endpoint: str) -> str:
_url = os.environ.get('FEDN_CONTROLLER_URL')

if _url:
return f'{_url}/api/{API_VERSION}/{endpoint}'
return f'{_url}/api/{API_VERSION}/{endpoint}/'

_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}'
return f'{_protocol}://{_host}:{_port}/api/{API_VERSION}/{endpoint}/'


def get_token(token: str) -> str:
Expand Down

0 comments on commit 1507981

Please sign in to comment.