Skip to content

Commit

Permalink
Update user documentation with environment variable command (#62)
Browse files Browse the repository at this point in the history
* Add example showing how to set environment variable on Windows command line
* Update Linux example of setting an environment variable
* Update <click> message to show correct environment variable command based on OS
  • Loading branch information
rbrazinskas authored Nov 22, 2023
1 parent b8046cc commit 70c2b90
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 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.5
===========

* Update user documentation with an example how to set environment variable `#62 <https://github.com/iqm-finland/cortex-cli/pull/62>`_

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

Expand Down
12 changes: 10 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,19 @@ Use with Cirq on IQM, Qiskit on IQM, etc.
Adapters based on IQM Client, such as Cirq on IQM and Qiskit on IQM, can take advantage of the tokens file maintained by
Cortex CLI. This way you won't need to provide the authentication server URL, username, or password to the adapter
library itself. To achieve this, follow the instructions printed on the screen after running ``cortex auth login``.
Namely, set the ``IQM_TOKENS_FILE`` environment variable to point to your tokens file, for example:
Namely, set the ``IQM_TOKENS_FILE`` environment variable to point to your tokens file.

On Linux:

.. code-block:: bash
$ export IQM_TOKENS_FILE=/home/user/iqm_tokens.json
$ export IQM_TOKENS_FILE=/home/<username>/tokens.json
On Windows:

.. code-block:: batch
set IQM_TOKENS_FILE=C:\Users\<username>\.cache\iqm-cortex-cli\tokens.json
Once set, this environment variable is read by the instance of IQM Client associated with the adapter. As a result,
from the point of view of the adapter it looks like authentication is simply not required (i.e. no
Expand Down
7 changes: 4 additions & 3 deletions src/iqm/cortex_cli/cortex_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
from iqm.cortex_cli.token_manager import check_token_manager, daemonize_token_manager, start_token_manager

HOME_PATH = str(Path.home())
DEFAULT_CONFIG_PATH = f'{HOME_PATH}/.config/iqm-cortex-cli/config.json'
DEFAULT_TOKENS_PATH = f'{HOME_PATH}/.cache/iqm-cortex-cli/tokens.json'
DEFAULT_CONFIG_PATH = os.path.join(HOME_PATH, '.config', 'iqm-cortex-cli', 'config.json')
DEFAULT_TOKENS_PATH = os.path.join(HOME_PATH, '.cache', 'iqm-cortex-cli', 'tokens.json')
REALM_NAME = 'cortex'
CLIENT_ID = 'iqm_client'
USERNAME = ''
Expand Down Expand Up @@ -609,11 +609,12 @@ def login( # pylint: disable=too-many-arguments, too-many-locals, too-many-bran

logger.info('Logged in successfully as %s', username)
save_tokens_file(tokens_file, tokens, auth_server_url)
env_var_command = 'set' if platform.system().lower().startswith('win') else 'export'
click.echo(
f"""
To use the tokens file with IQM Client or IQM Client-based software, set the environment variable:
export IQM_TOKENS_FILE={tokens_file}
{env_var_command} IQM_TOKENS_FILE={tokens_file}
Refer to IQM Client documentation for details: https://iqm-finland.github.io/iqm-client/
"""
Expand Down

0 comments on commit 70c2b90

Please sign in to comment.