Browse Source

chg: dev: [apache] caching some function in library

framadate
Valentin Lab 6 years ago
parent
commit
46a96635a5
  1. 42
      apache/lib/common
  2. 3
      apache/test/vhost
  3. 4
      apache/test/vhost_cert_provider
  4. 4
      apache/test/vhost_files

42
apache/lib/common

@ -2,18 +2,21 @@
get_domain() { 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 return 0
fi 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() { _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" target_relation="cert-provider"
while read-0 rn ts rc td; do while read-0 rn ts rc td; do
[ "$rn" == "${target_relation}" ] || continue [ "$rn" == "${target_relation}" ] || continue
info "A cert-provider '$ts' declared as 'ssl' value" info "A cert-provider '$ts' declared as 'ssl' value"
echo "$ts"
echo "$ts" | tee "$cache_file"
return 0 return 0
done < <(get_service_relations "$SERVICE_NAME") done < <(get_service_relations "$SERVICE_NAME")

3
apache/test/vhost

@ -30,7 +30,8 @@ get_service_relations() {
} }
export -f get_service_relations export -f get_service_relations
export state_tmpdir=$(mktemp -d -t tmp.XXXXXXXXXX)
trap "rm -rf \"$state_tmpdir\"" EXIT
## ##
## Tests ## Tests

4
apache/test/vhost_cert_provider

@ -133,6 +133,10 @@ cached_cmd_on_base_image() {
export -f 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 ## cert-provider
## ##

4
apache/test/vhost_files

@ -122,6 +122,10 @@ cached_cmd_on_base_image() {
export -f 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 ## apache_vhost_create
## ##

Loading…
Cancel
Save