Skip to main content

Description

This CLI allows the fetching and the automatic refreshing of the Nexus token using Keycloak. Its value can be written periodically in a file whose path is given in input or be displayed on the console output as desired. The CLI is based on the class TokenFetcherUser that is in charge of the token fetching and refreshing. If being imported as a library, two public methods of a TokenFetcherUser object makes possible to get a fresh Nexus access token and to get its life duration.

For more information about Nexus, see https://bluebrainnexus.io/

Install

Clone the repository:

git clone https://github.com/BlueBrain/bbp-token-fetch.git

and install with pip:

pip install blue_brain_nexus_token_fetch

From now on, the executable blue-brain-token-fetch is in your PATH.

CLI arguments

  • --username - [Prompt] Username to request the access token. Default is the username detected by whoami (environmental variable $USER).
  • --password - [Prompt] Password to request the access token.
  • --output / -o - [Flag] Flag option allowing for 3 distinct outputs:
    • {not_given} : By default the fetched token will be written in the file located at $HOME/.token_fetch/Token,
    • {-o/--output} : Providing only the flag will print the token on the console output,
    • {-o/--output} {PATH}: If a value (argument 'path') is given as a file path, the token will be written in this file location, Note: The output file containing the token will have owner read/write access.
  • path - [File path] Path to the eventual output token file.
  • --refresh-period / -rp - [default 15] Duration of the period between which the token will be written in the file. It can be expressed as number of seconds or by using time unit : '{float}{time unit}'.Available time unit are :
    • ['s', 'sec', 'secs', 'second', 'seconds'] for seconds,
    • ['m', 'min', 'mins', 'minute', 'minutes'] for minutes,
    • ['h', 'hr', 'hrs', 'hour', 'hours'] for hours,
    • ['d', 'day', 'days'] for days. Ex: '-rp 30' '-rp 30sec', '-rp 0.5min', '-rp 0.1hour'
  • --timeout / -to - "Duration corresponding to the life span to be applied to the application before it is stopped. It can be expressed as number of seconds or by using time unit : '{float}{time unit}'. Available time unit are :
    • ['s', 'sec', 'secs', 'second', 'seconds'] for seconds,
    • ['m', 'min', 'mins', 'minute', 'minutes'] for minutes,
    • ['h', 'hr', 'hrs', 'hour', 'hours'] for hours,
    • ['d', 'day', 'days'] for days. Ex: '-rp 30' '-rp 30sec', '-rp 0.5min', '-rp 0.1hour'
  • --keycloak-config-file / -kcf - [File Path] The path to the yaml file containing the configuration to create the keycloak instance. If not provided, it will search in your $HOME directory for a '$HOME/.token_fetch/keycloack_config.yaml' file containing the keycloak configuration.If this file does not exist or the configuration inside is wrong, the configuration will be prompt in the console output and saved in the $HOME directory under the name: '$HOME/.token_fetch/keycloack_config.yaml'.

Examples

  • Print to the console output a fresh 'access token' continuously :
blue-brain-token-fetch
  • Write every 10 seconds a fresh 'access token' into the token file before exiting after 1 hour:
blue-brain-token-fetch -o path ./token.txt \
              	       -rp 10s \
                       -to 1h \

Note: If you want to regain control on the keyboard you can launch the CLI then kill its process then relaunch it in background mode by doing:

blue-brain-token-fetch
# ctrl+z
bg
  • If imported in a script:

    • For regular accounts with credentials username and password
    my_token_fetcher = TokenFetcherUser(username, password, keycloak_config_file)
    
    • For service accounts with credentials client_id and client_password
    my_token_fetcher = TokenFetcherService(client_id, client_password, keycloak_config_file)
    

    Then you can get an access token and its duration (how long until it expires) with:

    my_access_token = my_token_fetcher.get_access_token() 
    acess_token_duration = my_token_tetcher.get_access_token_duration() 
    

Funding & Acknowledgment

The development of this software was supported by funding to the Blue Brain Project, a research center of the École polytechnique fédérale de Lausanne (EPFL), from the Swiss government’s ETH Board of the Swiss Federal Institutes of Technology.

Copyright © 2021-2024 Blue Brain Project/EPFL

Metadata

Release files for blue-brain-token-fetch 3.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for blue-brain-token-fetch 3.0.2
File Size Uploaded Provenance Actions
blue_brain_token_fetch-3.0.2.tar.gz 32.1 kB Without provenance Details for blue_brain_token_fetch-3.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for blue-brain-token-fetch 3.0.2
File Interpreter ABI Platform Actions
blue_brain_token_fetch-3.0.2-py3-none-any.whl Python 3 none any Details for blue_brain_token_fetch-3.0.2-py3-none-any.whl

Total release size: 56.6 kB

Release files / blue_brain_token_fetch-3.0.2.tar.gz

Download URL blue_brain_token_fetch-3.0.2.tar.gz
Size 32.1 kB
Tags Source
SHA-256 checksum
How to use checksums
49a46288f173f4d6abd49b919115c7b2f4951885eb566f0df628d67dd06dec71
BLAKE2b-256 checksum
How to use checksums
33d65f72168c9a9b92dbec4d1750997c0ea320f7b60b41d9682717a4ca18f014
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release files / blue_brain_token_fetch-3.0.2-py3-none-any.whl

Download URL blue_brain_token_fetch-3.0.2-py3-none-any.whl
Size 24.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
798b4813e4bb22c6f3954c0a30d18378375841df663de3dd0b1aeb4552691ca2
BLAKE2b-256 checksum
How to use checksums
a4943a4f21767cb05c531c2e233a2be536f5f5e412dbd19ec238259b55b2b202
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Security for blue-brain-token-fetch 3.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page