Untitled

mail@pastecode.io avatar
unknown
sh
2 years ago
662 B
2
Indexable
Never
#/bin/bash

IFS=''
while read line ; do
    #while [[ "$line" =~ \$\{VAULT:([a-zA-Z0-9_-/\.]*):([a-zA-Z0-9_-/\.]*)\} ]] ; do
    while [[ "$line" =~ \$\{VAULT:([^ {}]*):([^ {}]*)\} ]] ; do
        LHS=${BASH_REMATCH[0]}
        VAULT_RESULT=$(vault kv get -field ${BASH_REMATCH[2]} ${BASH_REMATCH[1]})
        if [[ $(echo ${VAULT_RESULT} | wc -l) > 1 ]]; then
            printf -v SPC %$(echo ${line//$LHS/} | awk '{ print length }')s
            RHS=$(echo ${VAULT_RESULT} | sed -E '2,$ s/^/'${SPC}'/g')
        else
            RHS=${VAULT_RESULT}
        fi
        line=${line//$LHS/$RHS}
    done
    echo "$line"
done < kube-prometheus-stack/values.yaml