blue-brain-token-fetch


Nameblue-brain-token-fetch JSON
Version 3.0.1 PyPI version JSON
download
home_pagehttps://github.com/BlueBrain/bbp-token-fetch
SummaryPackage to perform fetching and automatic refreshing of the Nexus access token using Keycloak. Using the CLI you can choose to either have its value periodically written in the file whose path is given in input or either have it periodically printed on the console output.
upload_time2024-10-30 20:18:52
maintainerNone
docs_urlNone
authorBlue Brain Project, EPFL
requires_python>=3.6.0
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements click python-keycloak PyYAML
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## 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/

## Source
You can find the source of this module here: [https://bbpgitlab.epfl.ch/dke/apps/blue_brain_nexus_token_fetch]

## Install
Clone the repository:
```
git clone https://bbpgitlab.epfl.ch/dke/apps/blue_brain_nexus_token_fetch.git
```

And install with pip:
```
cd blue_brain_nexus_token_fetch
pip install .
```
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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/BlueBrain/bbp-token-fetch",
    "name": "blue-brain-token-fetch",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6.0",
    "maintainer_email": null,
    "keywords": null,
    "author": "Blue Brain Project, EPFL",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/55/85/625160171e01454d99a1471888ae267433ad8d92c96d5dd21e15d379b6e4/blue_brain_token_fetch-3.0.1.tar.gz",
    "platform": null,
    "description": "## Description\nThis CLI allows the fetching and the automatic refreshing of the Nexus token using Keycloak. \nIts value can be written periodically in a file whose path is given in input or be displayed on the console output as desired.\nThe CLI is based on the class TokenFetcherUser that is in charge of the token fetching and \nrefreshing. If being imported as a library, two public methods of a TokenFetcherUser object makes \npossible to get a fresh Nexus access token and to get its life duration.\n\nFor more information about Nexus, see https://bluebrainnexus.io/\n\n## Source\nYou can find the source of this module here: [https://bbpgitlab.epfl.ch/dke/apps/blue_brain_nexus_token_fetch]\n\n## Install\nClone the repository:\n```\ngit clone https://bbpgitlab.epfl.ch/dke/apps/blue_brain_nexus_token_fetch.git\n```\n\nAnd install with pip:\n```\ncd blue_brain_nexus_token_fetch\npip install .\n```\nFrom now on, the executable **blue-brain-token-fetch** is in your PATH.\n\n## CLI arguments\n- **--username** - [Prompt] Username to request the access token. Default is the username detected by whoami (environmental variable $USER).\n- **--password** - [Prompt] Password to request the access token.\n- **--output / -o** - [Flag] Flag option allowing for 3 distinct outputs:\n  - {not_given} : By default the fetched token will be written in the file located at\n    $HOME/.token_fetch/Token,\n  - {-o/--output} : Providing only the flag will print the token on the console output,\n  - {-o/--output} {PATH}: If a value (argument 'path') is given as a file path, the token\n    will be written in this file location,\nNote: The output file containing the token will have owner read/write access.\n- **path** - [File path] Path to the eventual output token file.\n- **--refresh-period / -rp** - [default 15] Duration of the period between which the token\nwill 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 :\n  - ['s', 'sec', 'secs', 'second', 'seconds'] for seconds,\n  - ['m', 'min', 'mins', 'minute', 'minutes'] for minutes,\n  - ['h', 'hr', 'hrs', 'hour', 'hours'] for hours,\n  - ['d', 'day', 'days'] for days.\nEx: '-rp 30' '-rp 30sec', '-rp 0.5min', '-rp 0.1hour'\n- **--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 :\n  - ['s', 'sec', 'secs', 'second', 'seconds'] for seconds,\n  - ['m', 'min', 'mins', 'minute', 'minutes'] for minutes,\n  - ['h', 'hr', 'hrs', 'hour', 'hours'] for hours,\n  - ['d', 'day', 'days'] for days.\nEx: '-rp 30' '-rp 30sec', '-rp 0.5min', '-rp 0.1hour'\n- **--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'.\n\n## Examples\n- Print to the console output a fresh 'access token' continuously :\n```\nblue-brain-token-fetch\n```\n\n- Write every 10 seconds a fresh 'access token' into the token file before exiting after 1 hour:\n```\nblue-brain-token-fetch -o path ./token.txt \\\n              \t       -rp 10s \\\n                       -to 1h \\\n```\nNote: 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:\n```\nblue-brain-token-fetch\n# ctrl+z\nbg\n```\n- If imported in a script:\n\n  - For regular accounts with credentials `username` and `password`\n  ```\n  my_token_fetcher = TokenFetcherUser(username, password, keycloak_config_file)\n  ```\n  - For service accounts with credentials `client_id` and `client_password` \n  ```\n  my_token_fetcher = TokenFetcherService(client_id, client_password, keycloak_config_file)\n  ```\n  Then you can get an access token and its duration (how long until it expires) with:\n  ```\n  my_access_token = my_token_fetcher.get_access_token() \n  acess_token_duration = my_token_tetcher.get_access_token_duration() \n  ```\n\n## Funding & Acknowledgment\nThe development of this software was supported by funding to the Blue Brain Project, a \nresearch center of the \u00c9cole polytechnique f\u00e9d\u00e9rale de Lausanne (EPFL), from the Swiss \ngovernment\u2019s ETH Board of the Swiss Federal Institutes of Technology.\n\nCopyright \u00a9 2021-2024 Blue Brain Project/EPFL\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Package to perform fetching and automatic refreshing of the Nexus access token using Keycloak. Using the CLI you can choose to either have its value periodically written in the file whose path is given in input or either have it periodically printed on the console output.",
    "version": "3.0.1",
    "project_urls": {
        "Homepage": "https://github.com/BlueBrain/bbp-token-fetch"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a53790f1478ae8afa475f756e5d1d6d6f30e76430a69f025e907bffd7871dfbf",
                "md5": "fe4732e7bbd63547e0c056a04770390f",
                "sha256": "bd7c4587a579e5f2792844c0bafd8fb320f21e3cd2f15c89b4a542cd1ad4e3ed"
            },
            "downloads": -1,
            "filename": "blue_brain_token_fetch-3.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fe4732e7bbd63547e0c056a04770390f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6.0",
            "size": 24607,
            "upload_time": "2024-10-30T20:18:49",
            "upload_time_iso_8601": "2024-10-30T20:18:49.132699Z",
            "url": "https://files.pythonhosted.org/packages/a5/37/90f1478ae8afa475f756e5d1d6d6f30e76430a69f025e907bffd7871dfbf/blue_brain_token_fetch-3.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5585625160171e01454d99a1471888ae267433ad8d92c96d5dd21e15d379b6e4",
                "md5": "b20e042a71560c1b1af22caeff1b2ca2",
                "sha256": "5ae43a106bec1ef54cb14a9db3b16dbe2c3941d8c4cbc4b59818c12d4e94941c"
            },
            "downloads": -1,
            "filename": "blue_brain_token_fetch-3.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "b20e042a71560c1b1af22caeff1b2ca2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6.0",
            "size": 32249,
            "upload_time": "2024-10-30T20:18:52",
            "upload_time_iso_8601": "2024-10-30T20:18:52.991966Z",
            "url": "https://files.pythonhosted.org/packages/55/85/625160171e01454d99a1471888ae267433ad8d92c96d5dd21e15d379b6e4/blue_brain_token_fetch-3.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-30 20:18:52",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "BlueBrain",
    "github_project": "bbp-token-fetch",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "click",
            "specs": [
                [
                    ">=",
                    "7.0"
                ]
            ]
        },
        {
            "name": "python-keycloak",
            "specs": [
                [
                    ">=",
                    "0.24.0"
                ]
            ]
        },
        {
            "name": "PyYAML",
            "specs": [
                [
                    ">=",
                    "5.3.1"
                ]
            ]
        }
    ],
    "lcname": "blue-brain-token-fetch"
}
        
Elapsed time: 0.69522s