Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/codemonauts/json2env
Directly load variables from AWS SecretsManager or json into environment variables
https://github.com/codemonauts/json2env
Last synced: about 4 hours ago
JSON representation
Directly load variables from AWS SecretsManager or json into environment variables
- Host: GitHub
- URL: https://github.com/codemonauts/json2env
- Owner: codemonauts
- Created: 2023-05-23T14:36:01.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-05-24T14:43:20.000Z (over 1 year ago)
- Last Synced: 2024-06-21T06:45:01.280Z (5 months ago)
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# json2env
In our CI/CD pipelines we regularly had the same pattern emerge which resulted in a lot of boilerplate code.
We always read a secret from the AWS SecretsManager, torn it apart with jq and loaded it into environment variables to use it e.g. with sed to put them into different configuration files.This tool can either read json from stdin, or if `-secret-id` is given, directly read key/value pairs from AWS
SecretsManager.It will output a list of `export KEY=value` lines to stdout so you could just wrap
it into an `eval $()` call in your pipeline script.## Usage
To directly query AWS SecretsManager use the *-secret-id* flag:
```bash
json2env -secret-id myAWSsecret
```if no *-secret-id* argument is provided, the tool will expect json input via STDIN:
```bash
echo '{"username":"johndoe","password":"swordfish"}' | ./json2env
```The tool will print something like this to the terminal:
```bash
export username=johndoe
export password=swordfish
```To get this directly into environment variables you can wrap the call into `eval` and execute it into your current
terminal:```bash
$ eval $(echo '{"username":"johndoe","password":"swordfish"}' | ./json2env -prefix 'SM_')
$ env | grep "SM_"
SM_username=johndoe
SM_password=swordfish
```