get-docker-secret


Nameget-docker-secret JSON
Version 2.0.0 PyPI version JSON
download
home_pagehttps://github.com/fischerfredl/get-docker-secret
SummaryUtility function to fetch docker secrets/envvars.
upload_time2023-07-23 08:19:50
maintainer
docs_urlNone
authorAlfred Melch
requires_python
licenseMIT
keywords docker secret envvar config
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![version](https://img.shields.io/pypi/v/get-docker-secret.svg)](https://pypi.python.org/pypi/get-docker-secret)
[![license](https://img.shields.io/pypi/l/get-docker-secret.svg)](https://pypi.python.org/pypi/get-docker-secret)
[![pyversions](https://img.shields.io/pypi/pyversions/get-docker-secret.svg)](https://pypi.python.org/pypi/get-docker-secret)
[![coverage](https://img.shields.io/codecov/c/github/fischerfredl/get-docker-secret.svg)](https://codecov.io/gh/Fischerfredl/get-docker-secret)

# get-docker-secret

Utility function to fetch docker secrets/envvars.

For config values (flask projects) i like to fetch docker secrets and fall back to environment variables for development. This module provides a function to make this a one-liner: use docker secret -> fall back to envvar -> fall back to default value.

The function also provides the possibility to automatically cast the value or specify a custom directory for secrets.

Following assumptions are being made (params):

- `autocast_name=True`: secrets are lower-case, envvars upper-case. automatic conversion of name can be switched off via autocast_name=False
- `cast_to=str`: fill in desired datatype. special case bool: 'True'/'true' will be True. 'False'/'false' will be False
- `getenv=True`: you want to fall back to envvar. can be switched of via getenv=False
- `default=None`
- `safe=True`: returns None if name not found or cast fails. If you want exceptions: safe=False
- `secrets_dir=/var/run/secrets`

## Usage

```python
from get_docker_secret import get_docker_secret

value = get_docker_secret('secret_key', default='very_secret')
```

## Testing

```python
python setup.py test
```

not tested under windows

## Changelog


### 2.0.0 - 2023-07-23

- Changed: Use canonical `/run/secrets` directory to read secrets from (changed from `/var/run/secrets`) (PR #4) (Thanks @ThorpeJosh)

### 1.0.2 - 2021-03-19

- Fixed: Only strip trailing newlines from secrets file

### 1.0.1 - 2019-12-07

- Fixed: Strip values read from file.

### 1.0.0 - 2018-01-30

- Initial publish

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/fischerfredl/get-docker-secret",
    "name": "get-docker-secret",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "docker,secret,envvar,config",
    "author": "Alfred Melch",
    "author_email": "dev@melch.pro",
    "download_url": "https://files.pythonhosted.org/packages/53/10/8586b943cf23d3a620e546a2a126a79507378263890275e6c2fe8220a100/get-docker-secret-2.0.0.tar.gz",
    "platform": null,
    "description": "[![version](https://img.shields.io/pypi/v/get-docker-secret.svg)](https://pypi.python.org/pypi/get-docker-secret)\n[![license](https://img.shields.io/pypi/l/get-docker-secret.svg)](https://pypi.python.org/pypi/get-docker-secret)\n[![pyversions](https://img.shields.io/pypi/pyversions/get-docker-secret.svg)](https://pypi.python.org/pypi/get-docker-secret)\n[![coverage](https://img.shields.io/codecov/c/github/fischerfredl/get-docker-secret.svg)](https://codecov.io/gh/Fischerfredl/get-docker-secret)\n\n# get-docker-secret\n\nUtility function to fetch docker secrets/envvars.\n\nFor config values (flask projects) i like to fetch docker secrets and fall back to environment variables for development. This module provides a function to make this a one-liner: use docker secret -> fall back to envvar -> fall back to default value.\n\nThe function also provides the possibility to automatically cast the value or specify a custom directory for secrets.\n\nFollowing assumptions are being made (params):\n\n- `autocast_name=True`: secrets are lower-case, envvars upper-case. automatic conversion of name can be switched off via autocast_name=False\n- `cast_to=str`: fill in desired datatype. special case bool: 'True'/'true' will be True. 'False'/'false' will be False\n- `getenv=True`: you want to fall back to envvar. can be switched of via getenv=False\n- `default=None`\n- `safe=True`: returns None if name not found or cast fails. If you want exceptions: safe=False\n- `secrets_dir=/var/run/secrets`\n\n## Usage\n\n```python\nfrom get_docker_secret import get_docker_secret\n\nvalue = get_docker_secret('secret_key', default='very_secret')\n```\n\n## Testing\n\n```python\npython setup.py test\n```\n\nnot tested under windows\n\n## Changelog\n\n\n### 2.0.0 - 2023-07-23\n\n- Changed: Use canonical `/run/secrets` directory to read secrets from (changed from `/var/run/secrets`) (PR #4) (Thanks @ThorpeJosh)\n\n### 1.0.2 - 2021-03-19\n\n- Fixed: Only strip trailing newlines from secrets file\n\n### 1.0.1 - 2019-12-07\n\n- Fixed: Strip values read from file.\n\n### 1.0.0 - 2018-01-30\n\n- Initial publish\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Utility function to fetch docker secrets/envvars.",
    "version": "2.0.0",
    "project_urls": {
        "Homepage": "https://github.com/fischerfredl/get-docker-secret"
    },
    "split_keywords": [
        "docker",
        "secret",
        "envvar",
        "config"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "53108586b943cf23d3a620e546a2a126a79507378263890275e6c2fe8220a100",
                "md5": "da4f6e3ce95ed62600e2d08476c32b25",
                "sha256": "3b39eab1caa69b4f7863fd3d9b419e0435c25f4747a1847de5a08161fe8d3410"
            },
            "downloads": -1,
            "filename": "get-docker-secret-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "da4f6e3ce95ed62600e2d08476c32b25",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3603,
            "upload_time": "2023-07-23T08:19:50",
            "upload_time_iso_8601": "2023-07-23T08:19:50.845919Z",
            "url": "https://files.pythonhosted.org/packages/53/10/8586b943cf23d3a620e546a2a126a79507378263890275e6c2fe8220a100/get-docker-secret-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-23 08:19:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "fischerfredl",
    "github_project": "get-docker-secret",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "get-docker-secret"
}
        
Elapsed time: 0.09466s