1
0
Fork 0
mirror of https://github.com/Luzifer/envrun.git synced 2024-12-20 10:21:16 +00:00
Helper utility to inject environment variables stored in a file into processes
Find a file
Knut Ahlers dc70a88edc
Update README
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2018-06-01 17:57:38 +02:00
vendor Update vendors 2018-06-01 17:34:46 +02:00
.gitignore Prepare addition of more encryption methods 2018-06-01 17:53:24 +02:00
.repo-runner.yaml Replace build image 2018-06-01 17:51:43 +02:00
decryption.go Prepare addition of more encryption methods 2018-06-01 17:53:24 +02:00
Gopkg.lock Update vendors 2018-06-01 17:34:46 +02:00
Gopkg.toml Migrate to dep for vendoring 2018-06-01 17:26:23 +02:00
History.md prepare release v0.3.1 2017-03-21 14:59:00 +01:00
main.go Prepare addition of more encryption methods 2018-06-01 17:53:24 +02:00
Makefile Add Gtihub publishing 2017-03-21 14:56:38 +01:00
README.md Update README 2018-06-01 17:57:38 +02:00

Go Report Card

Luzifer / envrun

envrun is a small helper utility I wrote for myself to debug programs and scripts during their development expecting environment variables to be set to special values. Sure there is gin for go webservers doing the same but I wanted something also for commandline utilities.

It reads a .env file (configurable) from the current directory and then either takes its own environment variables or a clean set and adds the env variables found in .env to it. The resulting set is passed to the command you put as arguments to envrun.

Examples

To visualize the effect of the utility the test command is python test.py with this simple python script:

import os

for k in os.environ.keys():
  print "{} = {}".format(k, os.environ[k])

It just prints the current environment to STDOUT and exits.

# cat .env
MY_TEST_VAR=hello world
ANOTHER_VAR=foo

# python test.py | grep MY_TEST_VAR
## No output on this command

# envrun --help
Usage of envrun:
      --clean                  Do not pass current environment to child process
      --encryption string      Encryption method used for encrypted env-file (Available: openssl-md5) (default "openssl-md5")
      --env-file string        Location of the environment file (default ".env")
      --log-level string       Log level (debug, info, warn, error, fatal) (default "info")
  -p, --password string        Password to decrypt environment file
      --password-file string   Read encryption key from file
      --q                      Suppress informational messages from envrun (DEPRECATED, use --log-level=warn)
      --version                Prints current version and exits

# envrun python test.py | grep MY_TEST_VAR
MY_TEST_VAR = hello world

# envrun python test.py | wc -l
      45

# envrun --clean python test.py | wc -l
       3

# envrun --clean python test.py
__CF_USER_TEXT_ENCODING = 0x1F5:0x0:0x0
ANOTHER_VAR = foo
MY_TEST_VAR = hello world

Encrypted .env-file

In case you don't want to put the environment variables into a plain text file onto your disk you can use an encrypted file and provide a password to envrun:

OpenSSL AES256 encryption

Pay attention on the -md md5 flag: OpenSSL 1.1.0f and newer uses an incompatible hasing algorithm for the passwords!

# echo 'MYVAR=myvalue' | openssl enc -e -aes-256-cbc -pass pass:justatest -md md5 -base64 -out .env

# cat .env
U2FsdGVkX18xcVIMejjwWzh1DppzptJCHhORH/JDj10=

# envrun -p justatest --clean -- env
MYVAR=myvalue
2017/03/21 16:34:57 Process exitted with code 0