Skip to content

Instantly share code, notes, and snippets.

@naunga
Created August 31, 2015 14:29
Show Gist options
  • Save naunga/8ad873dbf760e69884e2 to your computer and use it in GitHub Desktop.
Save naunga/8ad873dbf760e69884e2 to your computer and use it in GitHub Desktop.
Output the URL for a Vault server based on the configuration file.
#!/bin/bash
proto="https://"
while read line; do
if [[ $line =~ listener ]]; then
listener_section=1
elif [[ $listener_section == 1 ]] && [[ $line != "}" ]]; then
key=$( echo $line | cut -d'=' -f 1 | sed 's/\s*//g' | sed 's/\"//g')
val=$( echo $line | cut -d'=' -f 2 | sed 's/\s*//g' | sed 's/\"//g')
case "$key" in
address )
addr=$val
;;
tls_disable )
if [[ $val == 1 ]]; then
proto="http://"
fi
esac
fi
done < "$1"
echo "$proto$addr"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment