Skip to content

Instantly share code, notes, and snippets.

@Dmitry-Kucher
Last active January 24, 2020 13:06
Show Gist options
  • Save Dmitry-Kucher/4d200329ca5db01dc7aa172cfff0c17f to your computer and use it in GitHub Desktop.
Save Dmitry-Kucher/4d200329ca5db01dc7aa172cfff0c17f to your computer and use it in GitHub Desktop.
Mongodb auth string generation via bash based on env variables
#!/bin/bash
MONGODB_SERVER=${MONGODB_SERVER:-127.0.0.1}
MONOGDB_PORT=${MONGODB_PORT:-27017}
MONGODB_USER=${MONGODB_USER:-""}
MONGODB_PWD=${MONGODB_PWD:-""}
MONGODB_AUTH=$([ $MONGODB_USER ] && printf "%s" "$MONGODB_USER" && [ $MONGODB_PWD ] && printf "%s" ":$MONGODB_PWD")
MONGODB_URI="mongodb://${MONGODB_AUTH}@${MONGODB_SERVER}"
echo ${MONGODB_URI}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment