Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit 332a3b9

Browse files
committed
Masking Passwords
1 parent 6f76aad commit 332a3b9

File tree

3 files changed

+76
-125
lines changed

3 files changed

+76
-125
lines changed

plugin_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ pluginType: STAGED
77
entryPoint: plugin_runner:plugin
88
srcDir: src
99
schemaFile: schema.json
10-
buildNumber: 1.69.5
10+
buildNumber: 1.69.7

src/resources/library.sh

Lines changed: 54 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#
2020
# ? DLPX_TMP_DIRECTORY
2121
#
22-
23-
#
2422
# Toolkit Specific ...
2523
#
2624
DLPX_TOOLKIT_NAME="mysql"
@@ -208,16 +206,11 @@ portStatus () {
208206
ZBASEDIR=""
209207
ZDATADIR=""
210208

211-
#
212209
# Process Exist, get data values from process ...
213-
#
214210
if [[ "${ZPSID}" != "" ]]
215211
then
216212
zstr=`echo "$ZPSEF" | ${AWK} '{ s = ""; for (i = 8; i <= NF; i++) s = s $i " "; print s }'`
217213
log "$zstr"
218-
219-
###/usr/local/mysql/bin/mysqld --defaults-file=/mnt/provision/mytest/my.cnf --basedir=/usr/local/mysql --datadir=/mnt/provision/mytest/data --pid-file=/mnt/provision/mytest/clone.pid --port=3309 --server-id=201 --socket=/mnt/provision/mytest/mysql.sock --tmpdir=/mnt/provision/mytest/tmp
220-
221214
ZPGCMD=`echo $zstr | ${AWK} -F" " '{print $1}' | xargs`
222215
ZPGBIN=`dirname "${ZPGCMD}"`
223216

@@ -244,44 +237,35 @@ portStatus () {
244237

245238
ZTMPDIR=`echo "${ZPSEF}" | ${AWK} 'BEGIN {RS=" "}; /--tmpdir/' | cut -d"=" -f2 | tr '\n' ' ' | xargs`
246239
#log "--tmpdir: ${ZTMPDIR}"
247-
248240
else
249-
#
250241
# If port IS NOT included in the process command, read from my.cnf file if specified ...
251-
#
252242
#zinstances=$( ps -ef | grep -E "[m]ysqld .*--defaults-file=" | grep -v grep )
253-
254243
log "Warning: Missing Process Id for Specified Port ${ZPORT}"
255-
256244
fi
257245

258-
#
259246
# Found valid process ...
260-
#
261247
ZSTATUS="INACTIVE"
262248
if [[ "${ZPSID}" != "" ]] && [[ "${ZPSCMD}" != "" ]] && [[ "${ZDATADIR}" != "" ]]
263249
then
264250
ZSTATUS="ACTIVE"
265251
fi
266252
echo "{
267-
\"port\": \"${ZPORT}\",
268-
\"processId\": \"${ZPSID}\",
269-
\"processCmd\": \"${ZPSCMD}\",
270-
\"socket\": \"${ZSOCKET}\",
271-
\"baseDir\": \"${ZBASEDIR}\",
272-
\"dataDir\": \"${ZDATADIR}\",
273-
\"myCnf\": \"${ZMYCNF}\",
274-
\"serverId\": \"${ZSERVERID}\",
275-
\"pidFile\": \"${ZPIDFILE}\",
276-
\"tmpDir\": \"${ZTMPDIR}\",
277-
\"status\": \"${ZSTATUS}\"
278-
}"
279-
253+
\"port\": \"${ZPORT}\",
254+
\"processId\": \"${ZPSID}\",
255+
\"processCmd\": \"${ZPSCMD}\",
256+
\"socket\": \"${ZSOCKET}\",
257+
\"baseDir\": \"${ZBASEDIR}\",
258+
\"dataDir\": \"${ZDATADIR}\",
259+
\"myCnf\": \"${ZMYCNF}\",
260+
\"serverId\": \"${ZSERVERID}\",
261+
\"pidFile\": \"${ZPIDFILE}\",
262+
\"tmpDir\": \"${ZTMPDIR}\",
263+
\"status\": \"${ZSTATUS}\"
264+
}"
280265
}
281266

282267
#
283268
# Stop Database ...
284-
#
285269
# Usage:
286270
# stopDatabase "${RESULTS_JSON}" "${SOURCE_CONN}"
287271
#
@@ -299,34 +283,27 @@ stopDatabase() {
299283
ZBASEDIR=`echo "${ZRESULTS}" | $DLPX_BIN_JQ --raw-output ".baseDir"`
300284
ZLOGSYNC=`echo "${ZRESULTS}" | $DLPX_BIN_JQ --raw-output ".logSync"`
301285

302-
echo "========ZCONN========"
286+
echo "ZCONN:"
303287
echo "$ZCONN"
304-
#
288+
305289
# Found valid process ...
306-
#
307290
if [[ "${ZPORT}" != "" ]] && [[ "${ZPSID}" != "" ]]
308291
then
309-
310292
if [[ -f "${ZBASEDIR}/bin/mysqladmin" ]] && [[ "${ZPORT}" != "" ]]
311-
then
312-
293+
then
313294
if [[ "${ZLOGSYNC}" == "true" ]]
314295
then
315-
log "Shutdown Slave: ${ZBASEDIR}/bin/mysqladmin ${ZCONN} stop-slave"
296+
masklog "Shutdown Slave: ${ZBASEDIR}/bin/mysqladmin ${ZCONN} stop-slave"
316297
CMD="${ZBASEDIR}/bin/mysqladmin ${ZCONN} stop-slave"
317298
##eval ${CMD} </dev/null >/dev/null 2>&1 & disown "$!"
318299
eval ${CMD} 1>>${DEBUG_LOG} 2>&1
319300
fi
320-
321-
#
322301
# Shutdown Database ...
323-
#
324-
log "Shutdown: ${ZBASEDIR}/bin/mysqladmin ${ZCONN} shutdown"
302+
masklog "Shutdown: ${ZBASEDIR}/bin/mysqladmin ${ZCONN} shutdown"
325303
CMD="${ZBASEDIR}/bin/mysqladmin ${ZCONN} shutdown"
326-
log "Executing shutdown ... "
304+
log "Executing shutdown"
327305
#eval ${CMD} </dev/null >/dev/null 2>&1 & disown "$!"
328306
eval ${CMD} 1>>${DEBUG_LOG} 2>&1
329-
330307
sleep 4
331308

332309
else
@@ -337,14 +314,12 @@ stopDatabase() {
337314
ZPSID2=`echo "${ZPSEF2}" | ${AWK} -F" " '{print $2}'`
338315
if [[ "${ZPSID}" == "${ZPSID2}" ]]
339316
then
340-
log "Killing ${ZPSID} ..."
341-
kill -9 ${ZPSID}
342-
sleep 4
317+
log "Killing ${ZPSID}"
318+
kill -9 ${ZPSID}
319+
sleep 10
343320
fi
344321

345-
#
346322
# Verify ...
347-
#
348323
ZPSEF2=$( ps -ef | grep -E "[m]ysqld .*--port=${ZPORT}" )
349324
ZPSID2=`echo "${ZPSEF2}" | ${AWK} -F" " '{print $2}'`
350325
if [[ "${ZPSID2}" == "" ]]
@@ -353,11 +328,8 @@ stopDatabase() {
353328
else
354329
log "Warning: Unknown Database Status ..."
355330
fi
356-
357-
else
358-
331+
else
359332
log "Warning: Shutdown aborted since port/process id does not exist or was not specified ..."
360-
361333
fi
362334
# return status?
363335
}
@@ -395,26 +367,20 @@ startDatabase() {
395367
then
396368
ZCMD="${ZPSCMD}"
397369
fi
398-
399-
#
400370
# Start Database ...
401-
#
402371
if [[ "${ZSTATUS}" != "ACTIVE" ]]
403372
then
404373

405374
ZMOUNTDIR=`${DIRNAME} ${ZDATADIR}`
406375
CMD="${ZCMD} ${ZOPTIONS} --defaults-file=${ZMYCNF} --basedir=${ZBASEDIR} --datadir=${ZDATADIR} --pid-file=${ZPIDFILE} --port=${ZPORT} --server-id=${ZSERVERID} --socket=${ZSOCKET} --tmpdir=${ZTMPDIR}"
407-
log "Startup Command: ${CMD} "
376+
masklog "Startup Command: ${CMD} "
408377

409-
#
410378
# Shoutout to Tom Walsh for the independent shell params !!!
411-
#
412379
${CMD} </dev/null >/dev/null 2>&1 & disown "$!"
413380

414381
ZPSEF=$( ps -ef | grep -E "[m]ysqld .*--port=${ZPORT}" )
415382
log "Process Status: ${ZPSEF}"
416-
417-
sleep 4
383+
sleep 10
418384

419385
ZPSID=`echo "${ZPSEF}" | ${AWK} -F" " '{print $2}'`
420386
log "Database Started on ProcessId: ${ZPSID}"
@@ -426,16 +392,13 @@ startDatabase() {
426392
log "====== Start Slave Check ======"
427393
if [[ "${LOGSYNC}" == "true" && "${ZSTARTSLAVE}" != "NO" ]]
428394
then
429-
log "ZCONN value for: ${ZCONN}"
395+
masklog "ZCONN value for: ${ZCONN}"
430396
CMD="${INSTALL_BIN}/mysqladmin ${ZCONN} start-slave"
431-
log "Command to start Slave> ${CMD}"
397+
masklog "Command to start Slave> ${CMD}"
432398
eval ${CMD} 1>>${DEBUG_LOG} 2>&1
433399
fi # end if $LOGSYNC ...
434-
435-
else
436-
400+
else
437401
log "Warning: Start Database aborted since status is ACTIVE ..."
438-
439402
fi
440403
}
441404

@@ -447,16 +410,12 @@ startDatabase() {
447410
# echo "${RESULTS}" | $DLPX_BIN_JQ --raw-output ".results"
448411
#
449412
buildConnectionString () {
450-
451413
ZCONN=${1}
452414
ZPASS=${2}
453415
ZPORT=${3}
454416
ZIP=${4}
455-
456-
#
457417
# Source Connection for Backup ...
458-
#
459-
log "Connection Input: ${ZCONN}"
418+
masklog "Connection Input: ${ZCONN}"
460419
ZSTRING="${ZCONN} --protocol=TCP --port=${ZPORT} --host=${ZIP}"
461420
if [[ "${ZCONN}" = *" -p"* ]] && [[ "${ZPASS}" != "" ]]
462421
then
@@ -473,22 +432,38 @@ buildConnectionString () {
473432
then
474433
ZSTRING="-u${ZCONN} -p${ZPASS} --protocol=TCP --port=${ZPORT} --host=${ZIP}"
475434
fi
476-
log "Updated Connection: ${ZSTRING}"
435+
masklog "Updated Connection: ${ZSTRING}"
477436
echo "{
478-
\"conn\": \"${ZCONN}\",
479-
\"pass\": \"${ZPASS}\",
480-
\"string\": \"${ZSTRING}\"
481-
}"
482-
437+
\"conn\": \"${ZCONN}\",
438+
\"pass\": \"${ZPASS}\",
439+
\"string\": \"${ZSTRING}\"
440+
}"
483441
}
484442

485-
#
486-
# Keep for Library Verification ...
487-
#
443+
# Keep for Library Verification
488444
function library_load {
489445
echo "LOADED"
490446
}
491447

448+
# mask passwords and log into debug
449+
function masklog {
450+
param=$1
451+
arr=(${param// / })
452+
i=0
453+
for val in "${arr[@]}"
454+
do
455+
if [[ "$val" == --pass* ]]; then
456+
arr[i+1]="M******"
457+
elif [[ "$val" == -p* ]]; then
458+
arr[i]="-p*****"
459+
fi
460+
let "i=i+1"
461+
done
462+
masked="${arr[@]}"
463+
log $masked
464+
}
465+
466+
492467
###########################################################
493468
## Test/Debug ...
494469

@@ -505,5 +480,5 @@ function library_load {
505480
#log "Delphix Bin: ${DLPX_BIN}"
506481
#log "Delphix Toolkit: ${DLPX_TOOLKIT}"
507482

508-
errorLog "Error Log Test ..."
483+
errorLog "Error Log Test"
509484
purgeLogs

0 commit comments

Comments
 (0)