add common.setMapDefaults()
PRODX-4799
Change-Id: I896ef3aae8f82b0162b09837c8d99334ead1ed2c
diff --git a/src/com/mirantis/mk/Common.groovy b/src/com/mirantis/mk/Common.groovy
index 031bf6f..bd42378 100644
--- a/src/com/mirantis/mk/Common.groovy
+++ b/src/com/mirantis/mk/Common.groovy
@@ -945,6 +945,29 @@
}
}
+def setMapDefaults(Object base, Object defaults, Boolean recursive = false) {
+/**
+ * Function to update dict with params, if its not set yet
+ * Will not fail entire job in case any issues.
+ * Those function will not overwrite current options if already passed.
+ * @param base - dict
+ * @param defaults - dict
+ */
+ if (base instanceof Map && defaults instanceof Map) {
+ defaults.inject(base) { result, key, value ->
+ if (result.containsKey(key)) {
+ setMapDefaults(result[key], value, recursive = true)
+ } else {
+ result.put(key, value)
+ }
+ return result
+ }
+ } else if (!recursive) {
+ echo("Can't update map parameters, wrong input data, skipping")
+ }
+}
+
+
/**
* Wrapper around parallel pipeline function
* with ability to restrict number of parallel threads
@@ -1073,4 +1096,4 @@
// Official regex for Semver2 (https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string)
String semVerRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
return version ==~ semVerRegex
-}
\ No newline at end of file
+}