Commit 5e9c1cc7 authored by otica-integrator's avatar otica-integrator
Browse files

Merge branch 'agent/issue-4' into 'main'

fix: preserve trailing newline in vault-read.sh output

Closes #4

See merge request !4
parents 7c938615 09e2c5ed
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ fi
path=$1

# Get the kv sec from path in json
j=$(vault kv get -format=json $path)
j=$(vault kv get -format=json "$path")

return_code=$?
if [ "$return_code" -ne "0" ]; then
@@ -21,12 +21,15 @@ if [ "$return_code" -ne "0" ]; then
fi

f=$(echo "$j" | jq -r '.data.format//.data.data.format' 2> /dev/null)
v=$(echo "$j" | jq -r '.data.value//.data.data.value')
# jq -j adds no trailing newline; the trailing-x sentinel preserves
# any newlines in the value that $(...) would otherwise strip.
v=$(echo "$j" | jq -j '.data.value//.data.data.value'; printf x)
v=${v%x}

# if value format is base64, decode it
if [ "base64" == "$f" ]
then
    echo -n "$v" | base64 --decode
    printf '%s' "$v" | base64 --decode
else
    echo -n "$v"
    printf '%s' "$v"
fi