Skip to content

Instantly share code, notes, and snippets.

@cedricvidal
Created January 17, 2017 17:08
Show Gist options
  • Save cedricvidal/f43bbead614d10bc70be12a93c09c5c4 to your computer and use it in GitHub Desktop.
Save cedricvidal/f43bbead614d10bc70be12a93c09c5c4 to your computer and use it in GitHub Desktop.
Load OpenStack OS_* env variables automatically using direnv and envchain
layout python
PATH_add bin
ENVCHAIN_NS=qs-ovh-cloud
if [ -z "$OS_PASSWORD" ]; then
if type envchain > /dev/null; then
echo "Loading OS_PASSWORD env var from keychain"
direnv_load envchain $ENVCHAIN_NS direnv dump
else
echo
echo "|--------------------------------------------------------------------------------------------|"
echo "| You could store the password in the keychain to avoid typing the password, using envchain: |"
echo "| brew install envchain |"
echo "| envchain --set $ENVCHAIN_NS OS_PASSWORD |"
echo "|--------------------------------------------------------------------------------------------|"
echo
fi
fi
if [ -f openrc.sh ]; then
# Loads openrc.sh but disables all password related stuff to avoid blocking
echo "Loading OS_* env vars from openrc.sh"
direnv_load bash -c "source <(cat openrc.sh | grep -vi password); direnv dump"
else
echo
echo "|------------------------------------------------------------------------|"
echo "| Openstack openrc.sh does not exist, you could create an openrc.sh file |"
echo "| exporting all OS_* env variables to automate the process of defining |"
echo "| OS_* variables. It would be loaded by direnv automatically |"
echo "|------------------------------------------------------------------------|"
echo
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment