3 # ============LICENSE_START=======================================================
4 # Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
5 # Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
6 # ================================================================================
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
19 # SPDX-License-Identifier: Apache-2.0
20 # ============LICENSE_END=========================================================
22 SQL_FILE="${POLICY_HOME}/mysql/sql/createguardtable.sql"
24 # Remove escape backslashes if present and save output in temp file
25 sed 's/\\//g' "${POLICY_HOME}"/apps/guard/xacml.properties > /tmp/temp.xacml.properties
28 if [ ! -f /tmp/temp.xacml.properties ]; then
29 echo "Temporary guard xacml properties file not found!"
33 # Extract Maria DB Credential properties from xacml.properties file
34 DB_HOSTNAME=$(awk -F[/:] '$1 == "javax.persistence.jdbc.url=jdbc" { print $3 $5 }' /tmp/temp.xacml.properties)
35 DB_USERNAME=$(awk -F= '$1 == "javax.persistence.jdbc.user" { print $2 }' /tmp/temp.xacml.properties)
36 DB_PASSWORD=$(awk -F= '$1 == "javax.persistence.jdbc.password" { print $2 }' /tmp/temp.xacml.properties)
39 rm /tmp/temp.xacml.properties
41 if [ -z "$DB_HOSTNAME" ]; then
42 echo "No Mariadb host provided in guard xacml.properties."
46 if [ -z "$DB_USERNAME" ]; then
47 echo "No Mariadb username provided in guard xacml.properties."
51 if [ -z "$DB_PASSWORD" ]; then
52 echo "No Mariadb password provided in guard xacml.properties."
56 # Execute mysql command using sql file to create table
57 mysql -u${DB_USERNAME} -p${DB_PASSWORD} -h${DB_HOSTNAME} < "${SQL_FILE}"