diff --git a/apache/lib/common b/apache/lib/common index b81decf0..75c11ebf 100644 --- a/apache/lib/common +++ b/apache/lib/common @@ -2,18 +2,21 @@ get_domain() { - local cfg="$1" - - e "$cfg" | cfg-get-value domain 2>/dev/null && return 0 - - ## is service name a regex ? - if [[ "$BASE_SERVICE_NAME" =~ ^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$ ]]; then - echo "$BASE_SERVICE_NAME" + local cfg="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$SERVICE_NAME" "$MASTER_BASE_SERVICE_NAME" "$@")" \ + domain + if [ -e "$cache_file" ]; then + cat "$cache_file" return 0 fi - - err "You must specify a ${WHITE}domain$NORMAL option in relation. (${FUNCNAME[@]})" - return 1 + domain=$(e "$cfg" | cfg-get-value domain 2>/dev/null) || true + if [ "$domain" ]; then + echo "$domain" | tee "$cache_file" + elif [[ "$BASE_SERVICE_NAME" =~ ^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$ ]]; then + echo "$BASE_SERVICE_NAME" | tee "$cache_file" + else + err "You must specify a ${WHITE}domain$NORMAL option in relation. (${FUNCNAME[@]})" + return 1 + fi } @@ -115,14 +118,27 @@ export -f is_protocol_enabled _get_ssl_option_value() { - local cfg="$1" target_relation rn ts rc td - e "$cfg" | cfg-get-value ssl 2>/dev/null && return 0 + local cfg="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$SERVICE_NAME" "$MASTER_BASE_SERVICE_NAME" "$@")" \ + target_relation rn ts rc td + + if [ -e "$cache_file" ]; then + cat "$cache_file" + return 0 + fi + + if ssl_cfg=$(e "$cfg" | cfg-get-value ssl 2>/dev/null); then + if [[ "$ssl_cfg" =~ ^False|None$ ]]; then + ssl_cfg="" + fi + echo "$ssl_cfg" | tee "$cache_file" + return 0 + fi target_relation="cert-provider" while read-0 rn ts rc td; do [ "$rn" == "${target_relation}" ] || continue info "A cert-provider '$ts' declared as 'ssl' value" - echo "$ts" + echo "$ts" | tee "$cache_file" return 0 done < <(get_service_relations "$SERVICE_NAME") diff --git a/apache/test/vhost b/apache/test/vhost index 5f7bc4d8..e2cef37a 100644 --- a/apache/test/vhost +++ b/apache/test/vhost @@ -30,7 +30,8 @@ get_service_relations() { } export -f get_service_relations - +export state_tmpdir=$(mktemp -d -t tmp.XXXXXXXXXX) +trap "rm -rf \"$state_tmpdir\"" EXIT ## ## Tests diff --git a/apache/test/vhost_cert_provider b/apache/test/vhost_cert_provider index 6970a3ae..fe7125cb 100644 --- a/apache/test/vhost_cert_provider +++ b/apache/test/vhost_cert_provider @@ -133,6 +133,10 @@ cached_cmd_on_base_image() { export -f cached_cmd_on_base_image +export state_tmpdir=$(mktemp -d -t tmp.XXXXXXXXXX) +trap "rm -rf \"$state_tmpdir\"" EXIT + + ## ## cert-provider ## diff --git a/apache/test/vhost_files b/apache/test/vhost_files index 039cd8f5..a0309868 100644 --- a/apache/test/vhost_files +++ b/apache/test/vhost_files @@ -122,6 +122,10 @@ cached_cmd_on_base_image() { export -f cached_cmd_on_base_image +export state_tmpdir=$(mktemp -d -t tmp.XXXXXXXXXX) +trap "rm -rf \"$state_tmpdir\"" EXIT + + ## ## apache_vhost_create ##