Created
August 22, 2020 21:05
-
-
Save andrewthauer/9c5178e4d7c3bfe9cee26180d7a1ce7d to your computer and use it in GitHub Desktop.
jq-examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Adapted as a fix for https://github.com/spotify/backstage/blob/master/docker/run.sh | |
# | |
# Call with | |
local key_map='{ "BACKEND_BASEURL": "backend_baseUrl" }' | |
config="$(jq --arg keyMap "$key_map" -n 'env | | |
def swap_key($k): $keyMap | fromjson | if has($k) then with_entries(select(.key == $k)) | .[] else $k end; | |
with_entries(select(.key | startswith("APP_CONFIG_")) | .key |= sub("APP_CONFIG_"; "")) | | |
to_entries | | |
reduce .[] as $item ( | |
{}; setpath(swap_key($item.key) | split("_"); $item.value | try fromjson catch $item.value) | |
)')" | |
>&2 echo "Runtime app config: $config" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment