Skip to main content

Utility function to fetch docker secrets/envvars. Fork of https://github.com/Fischerfredl/get-docker-secret

Project description

version license pyversions coverage

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

from get_docker_secret import get_docker_secret

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

Testing

python setup.py test

not tested under windows

Changelog

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docker-secret-getter-1.0.2.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

docker_secret_getter-1.0.2-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file docker-secret-getter-1.0.2.tar.gz.

File metadata

  • Download URL: docker-secret-getter-1.0.2.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for docker-secret-getter-1.0.2.tar.gz
Algorithm Hash digest
SHA256 d7767c0ef28cda55c594f64ed224f1ff8b3bd768e07589544512413ce055d7a8
MD5 f17eaf08274936a0fd2f386e14b79dc4
BLAKE2b-256 857d2de2db4ab03e6482c41212dd2dbf82c38ea882cfecdceb171f8cc46f4185

See more details on using hashes here.

File details

Details for the file docker_secret_getter-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: docker_secret_getter-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for docker_secret_getter-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 30159032ebe880a7874226e17def32034c9075a5d8506d27ab6de25f947bca10
MD5 a569b103c21e46e8d169263d9ddf1573
BLAKE2b-256 08f9be8f2b15cf78cec88a26b3c054247b71e8e72e1c72c422ba347e8d9aec9f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page