4 # Copyright © 2019 Orange
5 # Copyright © 2020 Samsung Electronics
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.
20 # make sure the script fails if any of commands failed
24 USER_VAR="MYSQL_USER_$(echo $DB | tr '[:lower:]' '[:upper:]')"
25 PASS_VAR="MYSQL_PASSWORD_$(echo $DB | tr '[:lower:]' '[:upper:]')"
28 # PASS=`echo -n ${!PASS_VAR} | sed -e "s/'/''/g"`
29 # eval replacement of the bashism equivalents above might present a security issue here
30 # since it reads content from DB values filled by helm at the end of the script.
31 # These possible values has to be constrainted and/or limited by helm for a safe use of eval.
34 PASS=$(eval echo -n \$$PASS_VAR | sed -e "s/'/''/g")
35 MYSQL_OPTS=( -h ${DB_HOST} -P ${DB_PORT} -uroot -p${MYSQL_ROOT_PASSWORD} )
37 echo "Creating database ${DB} and user ${USER}..."
39 mysql "${MYSQL_OPTS[@]}" -e "CREATE OR REPLACE USER '${USER}'@'%' IDENTIFIED BY '${PASS}'"
40 mysql "${MYSQL_OPTS[@]}" -e "CREATE DATABASE IF NOT EXISTS ${DB}"
41 mysql "${MYSQL_OPTS[@]}" -e "GRANT ALL PRIVILEGES ON ${DB}.* TO '${USER}'@'%'"
43 echo "Created database ${DB} and user ${USER}."
45 {{ .Values.config.mysqlDatabase }}
46 {{- range $db, $_value := .Values.config.mysqlAdditionalDatabases }}