Skip to main content

Run a command with dynamically-sourced environment variables.

Project description

envrun

envrun is a CLI tool that runs a command with dynamically-sourced env variables.

Currently, only the keyring backend is implemented, which uses a libsecret-compatible service, eg. Gnome keyring.

Alternatively, a variable can be sourced from a file, output of an arbitrary coommand, of from the environment.

PyPi

This tool is still under heavy development and its API might change at any time. Use with caution.

Installation

To install using pip, run:

pip install envrun

Other installation options are not yet available.

Usage

envrun [OPTIONS] COMMAND...

To pass options to the invoked command, prepend the command with --

envrun -- ls -hal

Passing a -i / --interactive flag will prompt for missing variable values.

envrun -i ls

If supported by the storage backend, values provided will get stored automatically.

For debugging, invoke the env command, which should be available on most Unix-like systems:

envrun env

Example .envrun file

[vars]
; Variables can be hardcoded here
ENV=dev

[vars.SECRET]
; This will set SECRET from Gnome keyring.
type = keyring

[vars.MY_PATH]
; MY_PATH will be set to the value of the $PATH env variable
type = env
key = PATH

[vars.PWD]
; PWD will be set to captured stdout of the pwd command
type = shell
command = pwd

[vars.SSH_PUBKEY]
; SSH_PUBKEY will be set to the contents of id_rsa.pub
type = file
file = ~/.ssh/id_rsa.pub

Use cases

12-Factor apps

According to the Twelve-Factor App methodology, app secrets should be configured from the environment. envrun can neatly support this workflow by keeping the .envrun config files in version control and sourcing the config values from storage backends.

Infrastructure as code

When running configuration managament and Infrastructure as Code tools, there is often a need to inject secrets into the tool.

envrun provides a concise way of defining and passing the variables to tools like terraform and ansible.

Generating config files

Combined with the excelent envsubst, envrun can be used as a rudimentary templating engine.

envrun envsubst < nginx.conf.tmpl > nginx.conf

This will generate nginx.conf from nginx.conf.tmpl and replace all strings like $VAR or ${VAR} with their values - as provided by envrun.

Contributing

Create a virtualenv

python3 -m venv venv
. venv/bin/activate

Install the package:

pip install -e ".[dev]"

Make your changes.

Run code formatter:

black src

And finally: create a pull request.

Changes

0.0.4 (Unreleased)

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

envrun-0.0.3.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

envrun-0.0.3-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file envrun-0.0.3.tar.gz.

File metadata

  • Download URL: envrun-0.0.3.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for envrun-0.0.3.tar.gz
Algorithm Hash digest
SHA256 c3b7dfdb7ac513b1cd1d8a8792fb17afb38ef81cafffb0ee294be56e6853511a
MD5 0bbcc514c477718e2a4e6b0efecff8b3
BLAKE2b-256 9dce5850b8016b02b66543460e37139c44b5747b042ac35a07125617366a8efc

See more details on using hashes here.

File details

Details for the file envrun-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: envrun-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for envrun-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 91c3d760237a6360062c211060442db1a1f2ae7aa654897237873ae7885073da
MD5 f00921492bd9cfb827bb5635e4b67194
BLAKE2b-256 afcc86b8081a1d4253e7851bd7b6ae324607b97559f46cd687d05cfb0870acbb

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