Skip to content

Commit

Permalink
Merge pull request #1 from luqasn/fix-import-race
Browse files Browse the repository at this point in the history
Read stdin to memory instead of file
  • Loading branch information
luqasn authored Sep 29, 2022
2 parents 2f6e1f4 + eeda46d commit 8e1196d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions image/auth.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#!/bin/sh
#!/bin/bash

# read "input" (we only use target database)
cp /dev/stdin input.vars
. ./input.vars
set -eo pipefail -o nounset
# read "input"
INPUT=$(</dev/stdin)
# extract desired database name
database=$(echo -n "$INPUT" | grep '^database=.*$' | tr -d '\n' | cut -d'=' -f2-)

set -eo nounset
# generate hashed pw to return
md5=$(printf '%s' "$TARGET_PASSWORD$TARGET_USER" | md5sum | cut -d ' ' -f 1)
# create database requested by user on demand if it does not exist
echo "SELECT 'CREATE DATABASE $database' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '$database')\gexec" | psql "postgresql://$TARGET_USER:$TARGET_PASSWORD@$TARGET_HOST/$TARGET_DUMMY_DB"

# return connection info to proxy
# keep original options intact
cat input.vars
# but override user
cat << END
database=$database
$INPUT
user=$TARGET_USER
_META_TARGET_HOST=$TARGET_HOST
_META_TARGET_CRED=md5$md5
Expand Down

0 comments on commit 8e1196d

Please sign in to comment.