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

Fixes #15185: validated user sql script is not packaged #173

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion change-validation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
# make licensed : will build a license limited version of the plugin
#

FILES = # add the file that need to be package here like $(NAME)/changes-validation-schema.sql
FILES = $(NAME)/change-validation-schema.sql
SCRIPTS = postinst

include ../makefiles/common-scala-plugin.mk


target/$(NAME)/change-validation-schema.sql:
cp ./src/main/resources/change-validation-schema.sql target/$(NAME)/
30 changes: 29 additions & 1 deletion change-validation/packaging/postinst
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
#!/bin/bash

# add post-installation script, like:
SQL_CREDENTIALS=$(grep -c -E "^rudder.jdbc.(username|password)[ \t]*=" /opt/rudder/etc/rudder-web.properties || true)

if [ -f /opt/rudder/etc/rudder-web.properties -a ${SQL_CREDENTIALS} -eq 2 ]; then
# Get the database access credentials from the rudder-web.properties file
SQL_USER="$(grep -E '^rudder.jdbc.username[ \t]*=' /opt/rudder/etc/rudder-web.properties | cut -d "=" -f 2-)"
SQL_PASSWORD="$(grep -E '^rudder.jdbc.password[ \t]*=' /opt/rudder/etc/rudder-web.properties | cut -d "=" -f 2-)"
SQL_SERVER="$(grep -E '^rudder.jdbc.url[ \t]*=' /opt/rudder/etc/rudder-web.properties | cut -d '=' -f 2- | sed 's%^.*://\(.*\):\(.*\)/.*$%\1%')"
SQL_PORT="$(grep -E '^rudder.jdbc.url[ \t]*=' /opt/rudder/etc/rudder-web.properties | cut -d '=' -f 2- | sed 's%^.*://\(.*\):\(.*\)/.*$%\2%')"
SQL_DATABASE="$(grep -E '^rudder.jdbc.url[ \t]*=' /opt/rudder/etc/rudder-web.properties | cut -d '=' -f 2- | sed 's%^.*://.*:.*/\(.*\)$%\1%')"

export PGPASSWORD="${SQL_PASSWORD}"
else
# No database access credentials in rudder-web.properties... Try anyway using "guessed" values.
echo "WARNING: Database access credentials are missing in /opt/rudder/etc/rudder-web.properties, trying to guess adequate values."

SQL_USER="rudder"
SQL_PASSWORD="Normation"
SQL_SERVER="localhost"
SQL_PORT="5432"

# We rely on .pgpass instead
unset PGPASSWORD
fi

PSQL="psql -t -q -h ${SQL_SERVER} -p ${SQL_PORT} -U ${SQL_USER}"

# Run SQL script to update schema. This script is reentrant, so you can run it as much as you need
echo -n "Ensuring that Rudder validated users schema is up to date"
${PSQL} -d ${SQL_DATABASE} -f /opt/rudder/share/plugins/change-validation/change-validation-schema.sql
echo " Done"