From b9bfa7ab8b7d0fc191d9ed4f065369d29e8c96db Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Tue, 26 Feb 2019 13:40:41 +0100 Subject: [PATCH] chg: dev: [apache] refactor out ``yaml_get_values``. --- apache/lib/common | 41 +++------------------------------ apache/test/custom_rules | 23 +++++++++++++++++- apache/test/vhost | 27 +++++++++++++++++++++- apache/test/vhost_cert_provider | 25 ++++++++++++++++++-- apache/test/vhost_files | 24 ++++++++++++++++++- 5 files changed, 97 insertions(+), 43 deletions(-) diff --git a/apache/lib/common b/apache/lib/common index 3bf0109c..dc72b51a 100644 --- a/apache/lib/common +++ b/apache/lib/common @@ -616,44 +616,9 @@ EOF _get_custom_rules() { - local cfg="$1" custom_rules type elt value first - custom_rules=$(e "$cfg" | cfg-get-value apache-custom-rules 2>/dev/null) || true - if [ -z "$custom_rules" -o "$custom_rules" == "None" ]; then - return 0 - fi - type=$(echo "$custom_rules" | shyaml get-type) - value= - case "$type" in - "sequence") - first=1 - while read-0 elt; do - elt="$(echo "$elt" | yaml_get_interpret)" || return 1 - [ "$elt" ] || continue - if [ "$first" ]; then - first= - else - value+=$'\n' - fi - first= - value+="$elt" - done < <(echo "$custom_rules" | shyaml -y get-values-0) - ;; - "struct") - while read-0 _key val; do - value+=$'\n'"$(echo "$val" | yaml_get_interpret)" || return 1 - done < <(echo "$custom_rules" | shyaml -y key-values-0) - ;; - "str") - value+=$(echo "$custom_rules") - ;; - "NoneType") - value="" - ;; - *) - value+=$(echo "$custom_rules") - ;; - esac - printf "%s" "$value" + local cfg="$1" custom_rules + custom_rules=$(e "$cfg" | shyaml -y -q get-value apache-custom-rules 2>/dev/null) || true + e "$custom_rules" | yaml_get_values } diff --git a/apache/test/custom_rules b/apache/test/custom_rules index 12078389..df1d80e1 100644 --- a/apache/test/custom_rules +++ b/apache/test/custom_rules @@ -2,6 +2,21 @@ exname=$(basename $0) +compose_core=$(which compose-core) || { + echo "Requires compose-core executable to be in \$PATH." >&2 + exit 1 +} + +fetch-def() { + local path="$1" fname="$2" + ( . "$path" 1>&2 || { + echo "Failed to load '$path'." >&2 + exit 1 + } + declare -f "$fname" + ) +} + prefix_cmd=" . /etc/shlib @@ -10,7 +25,13 @@ include parse . ../lib/common -" +$(fetch-def "$compose_core" yaml_get_values) +$(fetch-def "$compose_core" yaml_get_interpret) + +" || { + echo "Couldn't build prefix cmd" >&2 + exit 1 +} # mock cfg-get-value() { diff --git a/apache/test/vhost b/apache/test/vhost index 8e812e06..58e150db 100644 --- a/apache/test/vhost +++ b/apache/test/vhost @@ -2,6 +2,22 @@ exname=$(basename $0) +compose_core=$(which compose-core) || { + echo "Requires compose-core executable to be in \$PATH." >&2 + exit 1 +} + +fetch-def() { + local path="$1" fname="$2" + ( . "$path" 1>&2 || { + echo "Failed to load '$path'." >&2 + exit 1 + } + declare -f "$fname" + ) +} + + prefix_cmd=" . /etc/shlib @@ -10,7 +26,16 @@ include parse . ../lib/common -" +$(fetch-def "$compose_core" yaml_get_values) +$(fetch-def "$compose_core" yaml_get_interpret) + +" || { + echo "Couldn't build prefix cmd" >&2 + exit 1 +} + + + # mock relation-get() { diff --git a/apache/test/vhost_cert_provider b/apache/test/vhost_cert_provider index 093175dc..6754dba6 100644 --- a/apache/test/vhost_cert_provider +++ b/apache/test/vhost_cert_provider @@ -2,6 +2,22 @@ exname=$(basename $0) +compose_core=$(which compose-core) || { + echo "Requires compose-core executable to be in \$PATH." >&2 + exit 1 +} + +fetch-def() { + local path="$1" fname="$2" + ( . "$path" 1>&2 || { + echo "Failed to load '$path'." >&2 + exit 1 + } + declare -f "$fname" + ) +} + + prefix_cmd=" . /etc/shlib @@ -10,9 +26,14 @@ include parse . ../lib/common -depends compose +$(fetch-def "$compose_core" yaml_get_values) +$(fetch-def "$compose_core" yaml_get_interpret) + +" || { + echo "Couldn't build prefix cmd" >&2 + exit 1 +} -" ## ## Mocks diff --git a/apache/test/vhost_files b/apache/test/vhost_files index 3a2884bc..4a17fa52 100644 --- a/apache/test/vhost_files +++ b/apache/test/vhost_files @@ -2,6 +2,21 @@ exname=$(basename $0) +compose_core=$(which compose-core) || { + echo "Requires compose-core executable to be in \$PATH." >&2 + exit 1 +} + +fetch-def() { + local path="$1" fname="$2" + ( . "$path" 1>&2 || { + echo "Failed to load '$path'." >&2 + exit 1 + } + declare -f "$fname" + ) +} + prefix_cmd=" . /etc/shlib @@ -10,7 +25,14 @@ include parse . ../lib/common -" +$(fetch-def "$compose_core" yaml_get_values) +$(fetch-def "$compose_core" yaml_get_interpret) + +" || { + echo "Couldn't build prefix cmd" >&2 + exit 1 +} + ## ## Mocks