Skip to content

Commit 00633b4

Browse files
nmarukovichvalmiranogueira
authored andcommitted
fix
1 parent c3238a3 commit 00633b4

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

build/heartbeat-entrypoint.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ for i in {1..5}; do
2929
sleep "$((TIMEOUT * i))"
3030
fi
3131
done
32+
33+
# If password contains commas they must be escaped with a backslash: “exam,ple” according https://docs.percona.com/percona-toolkit/pt-heartbeat.html
3234
ESCAPED_HEARTBEAT_PASSWORD="${HEARTBEAT_PASSWORD//,/\\,}"
3335

3436
HEARTBEAT_USER='heartbeat'

build/ps-entrypoint.sh

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -212,26 +212,10 @@ ensure_read_only() {
212212

213213
escape_special() {
214214
{ set +x; } 2>/dev/null
215-
216-
# $1 = input string
217-
# $2 = optional flag, e.g., "heartbeat" to enable comma escaping
218-
219-
result="$1"
220-
221-
# Escape backslashes
222-
result=$(echo "$result" | sed 's/\\/\\\\/g')
223-
# Escape single quotes
224-
result=$(echo "$result" | sed "s/'/\\\\'/g")
225-
# Escape double quotes
226-
result=$(echo "$result" | sed 's/"/\\\"/g')
227-
228-
# Escape comma ONLY if second argument is "heartbeat"
229-
# If password contains commas they must be escaped with a backslash: “exam,ple” according https://docs.percona.com/percona-toolkit/pt-heartbeat.html
230-
if [[ $2 == "heartbeat" ]]; then
231-
result=$(echo "$result" | sed 's/,/\\,/g')
232-
fi
233-
234-
echo "$result"
215+
echo "$1" \
216+
| sed 's/\\/\\\\/g' \
217+
| sed 's/'\''/'\\\\\''/g' \
218+
| sed 's/"/\\\"/g'
235219
}
236220

237221
MYSQL_VERSION=$(mysqld -V | awk '{print $3}' | awk -F'.' '{print $1"."$2}')
@@ -374,7 +358,7 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
374358
GRANT SELECT ON sys_operator.* TO 'orchestrator'@'%';
375359
376360
CREATE DATABASE IF NOT EXISTS sys_operator;
377-
CREATE USER 'heartbeat'@'localhost' IDENTIFIED BY '$(escape_special "${HEARTBEAT_PASSWORD}" "heartbeat")' PASSWORD EXPIRE NEVER;
361+
CREATE USER 'heartbeat'@'localhost' IDENTIFIED BY '$(escape_special "${HEARTBEAT_PASSWORD}")' PASSWORD EXPIRE NEVER;
378362
GRANT SYSTEM_USER, REPLICATION CLIENT ON *.* TO 'heartbeat'@'localhost';
379363
GRANT SELECT, CREATE, DELETE, UPDATE, INSERT ON sys_operator.heartbeat TO 'heartbeat'@'localhost';
380364

0 commit comments

Comments
 (0)