-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
experiment generating multiple login users for pgbouncer
- Loading branch information
Showing
3 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM edoburu/pgbouncer:latest | ||
|
||
# Custom step to generate all users from environment variables | ||
RUN ./generate-config.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
# Define users and passwords | ||
declare -A users | ||
users=( | ||
["DB_USER"]="$DB_ROOT_PASSWORD" | ||
["FERRY_DB_USER"]="$FERRY_DB_PASSWORD" | ||
["HASURA_DB_USER"]="$HASURA_DB_PASSWORD" | ||
) | ||
|
||
output_file="/etc/pgbouncer/userlist.txt" | ||
|
||
for user in "${!users[@]}"; do | ||
if [ -z "${users[$user]}" ]; then | ||
echo "Error: Password for $user is not set in the environment variables." | ||
exit 1 | ||
fi | ||
done | ||
|
||
> "$output_file" # Clear the file | ||
|
||
for user in "${!users[@]}"; do | ||
password="${users[$user]}" | ||
md5_hash=$(echo -n "md5$(echo -n "${password}${user}" | md5sum | awk '{print $1}')") | ||
echo "\"$user\" \"$md5_hash\"" >> "$output_file" | ||
done |