Shopify / ejson

EJSON is a small library to manage encrypted secrets using asymmetric encryption.
MIT License
1.34k stars 62 forks source link

Support for easier use in projects that don't read from JSON files #49

Closed jeffutter closed 3 months ago

jeffutter commented 6 years ago

We are using ejson to store our secrets encrypted in our repos, however, our applications expect settings to be set in the environment rather than reading from a file.

Currently, we use this bit of hackery to load the json settings as env variables:

 echo "${EJSON_PRIVATE_KEY}" | ejson decrypt --key-from-stdin "$(env_file_name)" | jq -r '. | delpaths( env | keys + (keys | map("_"+.)) + ["_public_key"] | map([.]) ) | to_entries | .[] | "declare -x " + (.key | gsub("^_"; "")) + "=" + (.value | @sh)' > /tmp/env
    . /tmp/env
    rm /tmp/env
    env -u EJSON_PRIVATE_KEY "$@"

This is kind of a mess and I would love it if ejson supported writing out json content in a way that was easy to consume into an environment.

How would you all feel about a contribution that outputs the json content in a format like:

if [ -z ${KEY+x} ]; then
  declare -x "KEY"="VAL"
fi

for each variable so that it can be easily consumed by *sh for loading into shell environments before starting applications?

catherinejones commented 6 years ago

Hi Jeff, I don't know if you are still looking for this feature, but the ejson2env command was designed to support this specific use case. You can get that from Shopify/ejson2env.