diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 33a2d8b..2087896 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -23,10 +23,30 @@ file_env() { unset "$fileVar" } +urlencode() { + raw="$1" + encoded="" + length=$(echo -n "$raw" | wc -c) + i=0 + + while [ $i -lt $length ]; do + c=$(echo "$raw" | cut -c $((i + 1))) + case "$c" in + [a-zA-Z0-9.~_-]) encoded="$encoded$c" ;; + *) encoded="$encoded$(printf '%%%02X' "'$c")" ;; + esac + i=$((i + 1)) + done + + echo "$encoded" +} + file_env "TOKEN" file_env "MONGODB_PASSWORD" file_env "PAYLOAD_SECRET" -export MONGODB_URI="mongodb://$MONGODB_USER:$MONGODB_PASSWORD@$MONGODB_HOST:$MONGODB_PORT" +MONGODB_PASSWORD_ENCODED=$(urlencode "$MONGODB_PASSWORD") + +export MONGODB_URI="mongodb://$MONGODB_USER:$MONGODB_PASSWORD_ENCODED@$MONGODB_HOST:$MONGODB_PORT" "$@"