Created
August 9, 2018 19:03
-
-
Save v6/f4683336eb1c4a6a98a0f3cf21e62df2 to your computer and use it in GitHub Desktop.
// , convert_hcl_vault_policy_to_json.sh converts a Vault Policy in HashiCorp Language format to the Single line JSON format.
This file contains 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 | |
## tr -d '\n' | | |
## | |
## Behold. | |
## | |
## ______ _____ _ _ _____ _ ______ | |
## | ___ \ ___| | | | _ | | | _ \ | |
## | |_/ / |__ | |_| | | | | | | | | | | |
## | ___ \ __|| _ | | | | | | | | | | |
## | |_/ / |___| | | \ \_/ / |___| |/ / | |
## \____/\____/\_| |_/\___/\_____/___/ (_) | |
## | |
## | |
## | |
## | |
## It is hcl2json, Policy Weirdness Edition™ | |
## This removes comments from a .hcl file, serializes | |
## its contents into a string compatible with JSON, and | |
## outputs JSON with that string assigned to the | |
## key "policy". | |
## Created this based on my experiments documented here: | |
## https://groups.google.com/forum/#!topic/vault-tool/VslgAkDsEtc | |
printf "{ | |
\"policy\": \"" | |
cat $1 | sed '/^[[:blank:]]*#/d;s/#.*//' | sed 's/\"/\\\"/g' | tr -d '\n' ## Remove comments and serialize string | |
printf "\" | |
}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
4 years later and still working perfectly