Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL-decode DB user/password to allow special chars #139

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Unreleased
* streamline bin/compile
* add support for urlencoded special chars like `@` in usernames and passwords (@zyv)

## v0.7.0 (August 7, 2020)
* Change default branch name from master to main
Expand Down
7 changes: 7 additions & 0 deletions bin/gen-pgbouncer-conf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,18 @@ query_wait_timeout = ${PGBOUNCER_QUERY_WAIT_TIMEOUT:-120}
[databases]
EOFEOF

function urldecode() {
echo "$1" | sed -e 's@+@ @g;s@%@\\x@g' | xargs -0 printf "%b"
}

for POSTGRES_URL in $POSTGRES_URLS
do
eval POSTGRES_URL_VALUE=\$$POSTGRES_URL
IFS=':' read DB_USER DB_PASS DB_HOST DB_PORT DB_NAME <<< $(echo $POSTGRES_URL_VALUE | perl -lne 'print "$1:$2:$3:$4:$5" if /^postgres(?:ql)?:\/\/([^:]*):([^@]*)@(.*?):(.*?)\/(.*?)$/')

DB_USER="$(urldecode "$DB_USER")"
DB_PASS="$(urldecode "$DB_PASS")"

DB_MD5_PASS="md5"`echo -n ${DB_PASS}${DB_USER} | md5sum | awk '{print $1}'`

CLIENT_DB_NAME="db${n}"
Expand Down