2018-06-01 15:57:38 +00:00
[![Go Report Card ](https://goreportcard.com/badge/github.com/Luzifer/envrun )](https://goreportcard.com/report/github.com/Luzifer/envrun)
![](https://badges.fyi/github/license/Luzifer/envrun)
![](https://badges.fyi/github/downloads/Luzifer/envrun)
![](https://badges.fyi/github/latest-release/Luzifer/envrun)
2016-02-06 15:23:11 +00:00
# Luzifer / envrun
2018-06-01 15:58:06 +00:00
`envrun` is a small helper utility to inject environment variables stored in a file into processes.
2016-02-06 15:23:11 +00:00
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:
```python
import os
for k in os.environ.keys():
print "{} = {}".format(k, os.environ[k])
```
It just prints the current environment to `STDOUT` and exits.
2018-06-01 16:02:26 +00:00
```console
$ cat .env
2016-02-06 15:23:11 +00:00
MY_TEST_VAR=hello world
ANOTHER_VAR=foo
2018-06-01 16:02:26 +00:00
$ python test.py | grep MY_TEST_VAR
2016-02-06 15:23:11 +00:00
## No output on this command
2018-06-01 16:02:26 +00:00
$ envrun --help
2016-02-06 15:23:11 +00:00
Usage of envrun:
2018-06-01 15:57:38 +00:00
--clean Do not pass current environment to child process
2018-06-01 16:34:44 +00:00
--encryption string Encryption method used for encrypted env-file (Available: gpg-symmetric, openssl-md5) (default "openssl-md5")
2018-06-01 15:57:38 +00:00
--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
2016-02-06 15:23:11 +00:00
2018-06-01 16:02:26 +00:00
$ envrun python test.py | grep MY_TEST_VAR
2016-02-06 15:23:11 +00:00
MY_TEST_VAR = hello world
2018-06-01 16:02:26 +00:00
$ envrun python test.py | wc -l
2016-02-06 15:23:11 +00:00
45
2018-06-01 16:02:26 +00:00
$ envrun --clean python test.py | wc -l
2016-02-06 15:23:11 +00:00
3
2018-06-01 16:02:26 +00:00
$ envrun --clean python test.py
2016-02-06 15:23:11 +00:00
__CF_USER_TEXT_ENCODING = 0x1F5:0x0:0x0
ANOTHER_VAR = foo
MY_TEST_VAR = hello world
```
2017-03-21 15:35:53 +00:00
## Encrypted `.env`-file
2018-06-01 15:57:38 +00:00
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` :
2018-06-01 16:19:35 +00:00
### GnuPG symmetric encryption
In this example an armored (`-a`) encryption is used. This is not required and you can leave out the `-a` flag.
```console
$ echo "MYVAR=myvalue" | gpg --passphrase justatest --batch --quiet --yes -c -a -o .env
$ cat .env
-----BEGIN PGP MESSAGE-----
jA0ECQMCIsGVKNlJw1Py0kMB542XJvekKyuPi2LHQrnFlhD5ALm6orvE3WFAzp7D
kAisTMr10fmjLuENfQhxqd9MB0Kd2mfd3b1mgOzei5IMDLJc
=7k9M
-----END PGP MESSAGE-----
$ envrun -p justatest --encryption gpg-symmetric --clean -- env
MYVAR=myvalue
INFO[0000] Process exitted with code 0
```
2018-06-01 15:57:38 +00:00
### OpenSSL AES256 encryption
Pay attention on the `-md md5` flag: OpenSSL 1.1.0f and newer uses an incompatible hasing algorithm for the passwords!
2017-03-21 15:35:53 +00:00
2018-06-01 16:02:26 +00:00
```console
$ echo 'MYVAR=myvalue' | openssl enc -e -aes-256-cbc -pass pass:justatest -md md5 -base64 -out .env
2017-03-21 15:35:53 +00:00
2018-06-01 16:02:26 +00:00
$ cat .env
2017-03-21 15:35:53 +00:00
U2FsdGVkX18xcVIMejjwWzh1DppzptJCHhORH/JDj10=
2018-06-01 16:02:26 +00:00
$ envrun -p justatest --clean -- env
2017-03-21 15:35:53 +00:00
MYVAR=myvalue
2018-06-01 16:21:35 +00:00
INFO[0000] Process exitted with code 0
2017-03-21 15:35:53 +00:00
```