3 # ============LICENSE_START=======================================================
4 # Copyright (C) 2022 Nordix Foundation. All rights reserved.
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 # SPDX-License-Identifier: Apache-2.0
19 # ============LICENSE_END=========================================================
21 SQL_FILE="${POLICY_HOME}/mysql/sql/createguardtable-pg.sql"
23 # Remove escape backslashes if present and save output in temp file
24 sed 's/\\//g' "${POLICY_HOME}"/apps/guard/xacml-pg.properties > /tmp/temp.xacml-pg.properties
27 if [ ! -f /tmp/temp.xacml-pg.properties ]; then
28 echo "Temporary guard xacml properties file not found!"
32 # Extract Maria DB Credential properties from xacml.properties file
33 DB_HOSTNAME=$(awk -F[/:] '$1 == "javax.persistence.jdbc.url=jdbc" { print $3 $5 }' /tmp/temp.xacml-pg.properties)
34 DB_USERNAME=$(awk -F= '$1 == "javax.persistence.jdbc.user" { print $2 }' /tmp/temp.xacml-pg.properties)
35 DB_PASSWORD=$(awk -F= '$1 == "javax.persistence.jdbc.password" { print $2 }' /tmp/temp.xacml-pg.properties)
38 rm /tmp/temp.xacml-pg.properties
40 if [ -z "$DB_HOSTNAME" ]; then
41 echo "No db host provided in guard xacml-pg.properties."
45 if [ -z "$DB_USERNAME" ]; then
46 echo "No db username provided in guard xacml-pg.properties."
50 if [ -z "$DB_PASSWORD" ]; then
51 echo "No db password provided in guard xacml-pg.properties."
55 # Execute sql command using sql file to create table
56 psql -U postgres -h ${DB_HOSTNAME} -f ${SQL_FILE}