Browse Source

new: can interpret ``bash-stdout`` tags in relations options

hostresources
Valentin Lab 6 years ago
parent
commit
e240392ec2
  1. 44
      bin/compose-core

44
bin/compose-core

@ -1512,34 +1512,60 @@ export -f setup_host_resources
relation-get () { relation-get () {
local key="$1"
cat "$RELATION_DATA_FILE" | shyaml get-value "$key" 2>/dev/null
if [ "$?" != 0 ]; then
local key="$1" out
if ! out=$(cat "$RELATION_DATA_FILE" | shyaml get-value "$key" 2>/dev/null); then
err "The key $WHITE$key$NORMAL was not found in relation's data." err "The key $WHITE$key$NORMAL was not found in relation's data."
return 1 return 1
fi fi
echo "$out" | yaml_get_interpret
} }
export -f relation-get export -f relation-get
yaml_get_interpret() {
local content tag
content=$(cat -)
tag=$(echo "$content" | shyaml -y get-value) || return 1
tag="${tag%% *}"
content=$(echo "$content" | shyaml get-value) || return 1
if ! [ "${tag:0:1}" == "!" ]; then
echo "$content" || return 1
return 0
fi
case "$tag" in
"!bash-stdout")
echo "$content" | bash || {
err "shell code didn't end with errorlevel 0"
return 1
}
;;
*)
err "Invalid object tag ${WHITE}$tag${NORMAL}"
return 1
;;
esac
}
export -f yaml_get_interpret
relation-base-compose-get () { relation-base-compose-get () {
local key="$1"
echo "$RELATION_BASE_COMPOSE_DEF" | shyaml get-value "options.$key" 2>/dev/null
if [ "$?" != 0 ]; then
local key="$1" out
if ! out=$(echo "$RELATION_BASE_COMPOSE_DEF" | shyaml -y get-value "options.$key" 2>/dev/null); then
err "The key $WHITE$key$NORMAL was not found in base service compose definition.." err "The key $WHITE$key$NORMAL was not found in base service compose definition.."
return 1 return 1
fi fi
echo "$out" | yaml_get_interpret
} }
export -f relation-base-compose-get export -f relation-base-compose-get
relation-target-compose-get () { relation-target-compose-get () {
local key="$1"
echo "$RELATION_BASE_COMPOSE_DEF" | shyaml get-value "options.$key" 2>/dev/null
if [ "$?" != 0 ]; then
local key="$1" out
if ! out=$(echo "$RELATION_TARGET_COMPOSE_DEF" | shyaml get-value "options.$key" 2>/dev/null); then
err "The key $WHITE$key$NORMAL was not found in base service compose definition.." err "The key $WHITE$key$NORMAL was not found in base service compose definition.."
return 1 return 1
fi fi
echo "$out" | yaml_get_interpret
} }
export -f relation-target-compose-get export -f relation-target-compose-get

Loading…
Cancel
Save