Merge "Move common Ceph function to Ceph class" into release/proposed/2019.2.0
diff --git a/src/com/mirantis/mcp/Validate.groovy b/src/com/mirantis/mcp/Validate.groovy
index 9ac618d..dd53450 100644
--- a/src/com/mirantis/mcp/Validate.groovy
+++ b/src/com/mirantis/mcp/Validate.groovy
@@ -39,11 +39,12 @@
* @param env_var Environment variables to set in container
* @param entrypoint Set entrypoint to /bin/bash or leave default
* @param mounts Map with mounts for container
+ * @param output_replacing Maps with regex with should be hide from output (passwords, etc)
**/
def runContainer(Map params){
def common = new com.mirantis.mk.Common()
- defaults = ["name": "cvp", "env_var": [], "entrypoint": true]
+ defaults = ["name": "cvp", "env_var": [], "entrypoint": true, "mounts": [:], "output_replacing": []]
params = defaults + params
def salt = new com.mirantis.mk.Salt()
def variables = ''
@@ -69,8 +70,11 @@
params.mounts.each { local, container ->
mounts = mounts + " -v ${local}:${container}"
}
- salt.cmdRun(params.master, params.target, "docker run -tid --net=host --name=${params.name}" +
- "${mounts} -u root ${entry_point} ${variables} ${params.dockerImageLink}")
+ salt.cmdRun(params.master, params.target,
+ "docker run -tid --net=host --name=${params.name}" +
+ "${mounts} -u root ${entry_point} ${variables} ${params.dockerImageLink}",
+ true, null, true, [],
+ params.output_replacing)
}
def runContainer(master, target, dockerImageLink, name='cvp', env_var=[], entrypoint=true, mounts=[:]){
diff --git a/src/com/mirantis/mk/Common.groovy b/src/com/mirantis/mk/Common.groovy
index 296dd38..c8f2e05 100644
--- a/src/com/mirantis/mk/Common.groovy
+++ b/src/com/mirantis/mk/Common.groovy
@@ -147,6 +147,16 @@
}
/**
+ * Print informational message
+ *
+ * @param msg
+ * @param color Colorful output or not
+ */
+def infoSensitivityMsg(msg, color = true, replacing = []) {
+ printSensitivityMsg(msg, "cyan", replacing)
+}
+
+/**
* Print error message
*
* @param msg
@@ -215,6 +225,25 @@
}
/**
+ * Print sensitivity message
+ *
+ * @param msg Message to be printed
+ * @param color Color to use for output
+ * @param replacing List with maps for deletion (passwords, logins, etc).
+ * The first () matching is mandatory !
+ * Example:
+ * [/ (OS_PASSWORD=)(.*?)+ /,
+ * / (password = )(.*?)+ /,
+ * / (password )(.*?) / ]
+ */
+def printSensitivityMsg(msg, color, replacing = []) {
+ for (i in replacing) {
+ msg = msg.replaceAll(i, ' $1XXXXXX ')
+ }
+ printMsg(msg, color)
+}
+
+/**
* Traverse directory structure and return list of files
*
* @param path Path to search
diff --git a/src/com/mirantis/mk/Salt.groovy b/src/com/mirantis/mk/Salt.groovy
index 8c6384c..f4147e0 100644
--- a/src/com/mirantis/mk/Salt.groovy
+++ b/src/com/mirantis/mk/Salt.groovy
@@ -331,12 +331,13 @@
* @param batch salt batch parameter integer or string with percents (optional, default null - disable batch)
* @param output do you want to print output
* @param saltArgs additional salt args eq. ["runas=aptly"]
+ * @param replacing list with maps for deletion in info message (passwords, logins, etc)
* @return output of salt command
*/
-def cmdRun(saltId, target, cmd, checkResponse = true, batch=null, output = true, saltArgs = []) {
+def cmdRun(saltId, target, cmd, checkResponse = true, batch=null, output = true, saltArgs = [], replacing = []) {
def common = new com.mirantis.mk.Common()
def originalCmd = cmd
- common.infoMsg("Running command ${cmd} on ${target}")
+ common.infoSensitivityMsg("Running command ${cmd} on ${target}", true, replacing)
if (checkResponse) {
cmd = cmd + " && echo Salt command execution success"
}