From c74e6ce216b733bb028fac11ebaa0edf29dcb4d5 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 15 Nov 2022 23:42:36 -0500 Subject: [PATCH] refactor: use a common wrapper function to migrate config vars to properties --- plugins/checks/install | 18 ++---------------- plugins/common/functions | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/plugins/checks/install b/plugins/checks/install index a11b9f3c7..7ee6f8b9a 100755 --- a/plugins/checks/install +++ b/plugins/checks/install @@ -6,23 +6,9 @@ source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" migrate_checks_vars_0_29_0() { - declare desc="migrates deprecated DOKKU_WAIT_TO_RETIRE config variables to simplified counter part introduced in 0.29.x" + declare desc="migrates deprecated DOKKU_WAIT_TO_RETIRE config variables to property counter part introduced in 0.29.x" - local wait_to_retire=$(config_get --global DOKKU_WAIT_TO_RETIRE || true) - if [[ -n "$wait_to_retire" ]]; then - dokku_log_info1 "Migrating deprecated global DOKKU_WAIT_TO_RETIRE to scheduler-docker-local property." - fn-plugin-property-write "checks" --global "wait-to-retire" "$wait_to_retire" - DOKKU_QUIET_OUTPUT=1 config_unset --global DOKKU_WAIT_TO_RETIRE || true - fi - - for app in $(dokku_apps "false"); do - local wait_to_retire=$(config_get "$app" DOKKU_WAIT_TO_RETIRE || true) - if [[ -n "$wait_to_retire" ]]; then - dokku_log_info1 "Migrating deprecated DOKKU_WAIT_TO_RETIRE to scheduler-docker-local property for $app." - fn-plugin-property-write "checks" "$app" "wait-to-retire" "$wait_to_retire" - DOKKU_QUIET_OUTPUT=1 config_unset --no-restart "$app" DOKKU_WAIT_TO_RETIRE || true - fi - done + fn-migrate-config-to-property "checks" "wait-to-retire" "DOKKU_WAIT_TO_RETIRE" "DOKKU_WAIT_TO_RETIRE" } migrate_checks_vars_0_5_0() { diff --git a/plugins/common/functions b/plugins/common/functions index 1261774a6..aa53fc219 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -1143,3 +1143,35 @@ suppress_output() { } return 0 } + +fn-migrate-config-to-property() { + declare desc="migrates deprecated config variables to property counterpart" + declare PLUGIN="$1" KEY="$2" CONFIG_VAR="$3" GLOBAL_CONFIG_VAR="$4" + + # todo: refactor to remove config_unset usage + if ! declare -f -F config_unset >/dev/null; then + source "$PLUGIN_AVAILABLE_PATH/config/functions" + fi + + if ! declare -f -F fn-plugin-property-write >/dev/null; then + source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" + fi + + if [[ -n "$GLOBAL_CONFIG_VAR" ]]; then + local value=$(plugn trigger config-get-global "$GLOBAL_CONFIG_VAR" || true) + if [[ -n "$value" ]]; then + dokku_log_info1 "Migrating deprecated global $GLOBAL_CONFIG_VAR to $PLUGIN $KEY property." + fn-plugin-property-write "$PLUGIN" --global "$KEY" "$value" + DOKKU_QUIET_OUTPUT=1 config_unset --global "$GLOBAL_CONFIG_VAR" || true + fi + fi + + for app in $(dokku_apps "false"); do + local value=$(plugn trigger config-get "$app" "$CONFIG_VAR" || true) + if [[ -n "$value" ]]; then + dokku_log_info1 "Migrating deprecated $CONFIG_VAR to $PLUGIN $KEY property for $app." + fn-plugin-property-write "$PLUGIN" "$app" "$KEY" "$value" + DOKKU_QUIET_OUTPUT=1 config_unset --no-restart "$app" "$CONFIG_VAR" || true + fi + done +} \ No newline at end of file