Skip to content

Commit

Permalink
COMP-1097: No realm and client id config in cortex init (#61)
Browse files Browse the repository at this point in the history
Silently use hardcoded "Realm" and "Client Id" values for configuration with "cortex init" command. Also support an option to overwrite the hardcoded values with command line switches "--realm" and "--client-id"
  • Loading branch information
rbrazinskas committed Oct 31, 2023
1 parent 5c8c544 commit b8046cc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Changelog
=========

Version 5.4
===========

* Use default values of ``realm`` and ``client-id`` silently during ``cortex init``. Allow to overwrite the default values with command line switches ``--realm`` and ``--client-id``. `#61 <https://github.com/iqm-finland/cortex-cli/pull/61>`_

Version 5.3
===========

Expand Down
15 changes: 14 additions & 1 deletion src/iqm/cortex_cli/cortex_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,14 @@ def cortex_cli() -> None:


@cortex_cli.command()
@click.help_option()
@click.option(
'--config-file',
prompt='Where to save config',
callback=_validate_path,
default=CortexCliCommand.default_config_path,
type=ResolvedPath(dir_okay=False, writable=True, resolve_path=True),
is_eager=True,
help='Location where the configuration file will be saved.',
)
@click.option(
Expand All @@ -319,22 +321,33 @@ def cortex_cli() -> None:
callback=_validate_path,
default=CortexCliCommand.default_tokens_path,
type=ResolvedPath(dir_okay=False, writable=True, resolve_path=True),
is_eager=True,
help='Location where the tokens file will be saved.',
)
@click.option(
'--auth-server-url',
prompt='Authentication server URL',
callback=_validate_auth_server_url,
is_eager=True,
help='Authentication server URL.',
)
@click.option(
'--realm',
prompt='Realm on IQM auth server',
prompt_required=False,
default=REALM_NAME,
show_default=True,
callback=_validate_auth_realm,
help='Name of the realm on the IQM authentication server.',
)
@click.option('--client-id', prompt='Client ID', default=CLIENT_ID, help='Client ID on the IQM authentication server.')
@click.option(
'--client-id',
prompt='Client ID',
prompt_required=False,
default=CLIENT_ID,
show_default=True,
help='Client ID on the IQM authentication server.',
)
@click.option(
'--username',
prompt='Username (optional)',
Expand Down
5 changes: 3 additions & 2 deletions tests/cortex_cli_init_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
from tests.conftest import expect_process_terminate, prepare_auth_server_urls


@pytest.mark.parametrize('first_option', ['--config-file', '--tokens-file', '--auth-server-url', '--client-id'])
@pytest.mark.parametrize(
'first_option', ['--config-file', '--tokens-file', '--auth-server-url', '--realm', '--client-id']
)
@pytest.mark.parametrize('absolute_path', [True, False])
def test_init_saves_config_file(config_dict, first_option, tmp_path, absolute_path):
"""
Tests that ``cortex init`` produces config file.
Having different options as first one is tested since it can affect the initialization of ``click.Context``.
Specifying ``realm`` before ``auth-server-url`` is not allowed, so that case is not included.
"""
prepare_auth_server_urls(config_dict)
runner = CliRunner()
Expand Down

0 comments on commit b8046cc

Please sign in to comment.