diff options
author | Michael Mokry <michael.mokry@att.com> | 2019-07-23 13:54:30 -0500 |
---|---|---|
committer | Michael Mokry <michael.mokry@att.com> | 2019-07-30 13:09:05 -0500 |
commit | c783b0e54860115e9ceadc5293256a563f0537ca (patch) | |
tree | 156b3d689ef89b8662ccae9265e25ea200b1ac3b /packages | |
parent | 77d4dd1668c290abfd5f2c6d4b1866416c313033 (diff) |
Fix guard table creation during startup issue
- Added -hpolicydb to the mysql command in the script
- Made this configurable by utilizing the existing parameters in
xacml.properties for db connections. No OOM or CSIT changes should be
needed now.
PATCH UPDATE:
- used Awk to extract property values
- removed echo except one needed for the base64 command, as far
as I can tell it is needed when assigning output to a variable,
I tried to get it to work unsuccessfully.
- added exit code 2 for missing properties as suggested by Jorge
and Jim
PATCH UPDATE:
- remove echo from base64 using Jim's suggestion
- Added code to remove escape backslashes from properties file,
I didn't see these locally but when testing in windriver they
show up in the xacml.properties file on OOM installs
- More changes per Jorge's latest review
Change-Id: I79c0502d8a4fadd2160785014fcb9db3c0faab5e
Issue-ID: POLICY-1934
Signed-off-by: Michael Mokry <michael.mokry@att.com>
Diffstat (limited to 'packages')
-rw-r--r-- | packages/policy-xacmlpdp-tarball/src/main/resources/mysql/bin/create-guard-table.sh | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/packages/policy-xacmlpdp-tarball/src/main/resources/mysql/bin/create-guard-table.sh b/packages/policy-xacmlpdp-tarball/src/main/resources/mysql/bin/create-guard-table.sh index 1c60cb0e..e7226078 100644 --- a/packages/policy-xacmlpdp-tarball/src/main/resources/mysql/bin/create-guard-table.sh +++ b/packages/policy-xacmlpdp-tarball/src/main/resources/mysql/bin/create-guard-table.sh @@ -1,4 +1,4 @@ -#!/bin/bash -xv +#!/bin/bash # # ============LICENSE_START======================================================= # Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. @@ -20,4 +20,42 @@ # SQL_FILE="${POLICY_HOME}/mysql/sql/createguardtable.sql" -mysql -upolicy_user -ppolicy_user < "${SQL_FILE}" +# Remove escape backslashes if present and save output in temp file +sed 's/\\//g' "${POLICY_HOME}"/apps/guard/xacml.properties > /tmp/temp.xacml.properties + +# Remove temp file +if [ ! -f /tmp/temp.xacml.properties ] + then + echo "Temporary guard xacml properties file not found!" + exit 1 +fi + +# Extract Maria DB Credential properties from xacml.properties file +DB_HOSTNAME=$(awk -F[/:] '$1 == "javax.persistence.jdbc.url=jdbc" { print $3 $5 }' /tmp/temp.xacml.properties) +DB_USERNAME=$(awk -F= '$1 == "javax.persistence.jdbc.user" { print $2 }' /tmp/temp.xacml.properties) +DB_PASSWORD=$(awk -F= '$1 == "javax.persistence.jdbc.password" { print $2 }' /tmp/temp.xacml.properties | base64 -d) + +# Remove temp file +rm /tmp/temp.xacml.properties + +if [ -z "$DB_HOSTNAME" ] + then + echo "No Mariadb host provided in guard xacml.properties." + exit 2 +fi + +if [ -z "$DB_USERNAME" ] + then + echo "No Mariadb username provided in guard xacml.properties." + exit 2 +fi + +if [ -z "$DB_PASSWORD" ] + then + echo "No Mariadb password provided in guard xacml.properties." + exit 2 +fi + +# Execute mysql command using sql file to create table +mysql -u${DB_USERNAME} -p${DB_PASSWORD} -h${DB_HOSTNAME} < "${SQL_FILE}" + |