From 73ff38dbce5ac8298e533a1c369c055b8504c99a Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Mon, 10 Dec 2018 15:44:03 +0100 Subject: [PATCH] new: [apache] default value for ``ssl``, is first cert-provider if any. --- apache/lib/common | 25 +++++++++++++++++++++---- apache/test/vhost_cert_provider | 5 ++--- apache/test/vhost_files | 4 ++++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/apache/lib/common b/apache/lib/common index ed89d90..1a20dd8 100644 --- a/apache/lib/common +++ b/apache/lib/common @@ -72,6 +72,22 @@ is_protocol_enabled() { export -f is_protocol_enabled +_get_ssl_option_value() { + local target_relation rn ts rc td + relation-get ssl 2>/dev/null && return 0 + + 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" + return 0 + done < <(get_service_relations "$SERVICE_NAME") + + return 1 +} + + __vhost_cfg_normalize_protocol() { local protocol @@ -83,7 +99,7 @@ __vhost_cfg_normalize_protocol() { case "$protocol" in auto) - if __vhost_cfg_ssl="$(relation-get ssl 2>/dev/null)"; then + if __vhost_cfg_ssl="$(_get_ssl_option_value)"; then protocol="https" export __vhost_cfg_ssl else @@ -114,7 +130,8 @@ __vhost_cfg_normalize_protocol() { ssl_get_plugin_fun() { # from ssl conf, return the function that should manage SSL code creation - local cfg="$(relation-get ssl 2>/dev/null)" type keys + local cfg type keys + cfg=$(_get_ssl_option_value) if [ -z "$cfg" ]; then return 0 else @@ -150,7 +167,7 @@ ssl_get_plugin_fun() { merged_config=$(merge_yaml_str "$relation_config" "$ssl_cfg") || return 1 printf "%s\0" "$fun" "$key" "$merged_config" return 0 - done < <(get_compose_relations "$SERVICE_NAME") || return 1 + done < <(get_service_relations "$SERVICE_NAME") || return 1 case "$key" in cert|ca-cert|key) : @@ -271,7 +288,7 @@ apache_vhost_statement() { __vhost_full_vhost_statement http fi if is_protocol_enabled https; then - "$SSL_PLUGIN_FUN"_vars "$(relation-get ssl 2>/dev/null)" + "$SSL_PLUGIN_FUN"_vars "$(_get_ssl_option_value 2>/dev/null)" cat < diff --git a/apache/test/vhost_cert_provider b/apache/test/vhost_cert_provider index 77f1bfd..6373db9 100644 --- a/apache/test/vhost_cert_provider +++ b/apache/test/vhost_cert_provider @@ -24,11 +24,10 @@ relation-get() { } export -f relation-get -get_compose_relations() { - local service="$1" +get_service_relations() { printf "%s\0" "${RELATIONS[@]}" } -export -f get_compose_relations +export -f get_service_relations merge_yaml_str() { printf "