From f5f67a10735e0605b9b1549cbc9ef6e8ff1a323b Mon Sep 17 00:00:00 2001 From: Johan Wassberg Date: Tue, 26 Sep 2023 15:16:04 +0200 Subject: [PATCH] Improve error handling --- .../opt/mdqp/post.d/40-create-transitive | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/natmd-test-common/overlay/opt/mdqp/post.d/40-create-transitive b/natmd-test-common/overlay/opt/mdqp/post.d/40-create-transitive index ec531904..2c36ee07 100755 --- a/natmd-test-common/overlay/opt/mdqp/post.d/40-create-transitive +++ b/natmd-test-common/overlay/opt/mdqp/post.d/40-create-transitive @@ -32,10 +32,20 @@ for expression in "role-sp" "role-idp" "index.html"; do esac curl ${base_url}/${url} -o "${tmpfile}" - if ! grep -q entityID "${tmpfile}" ; then - echo "No entityID found in file for ${expression}" - exit 1 - fi + + case $file in + *.json) + jq -e .[].entityID "${tmpfile}" 1> /dev/null + ;; + *.xml|*.html) + xmlstarlet sel -t -v "//md:EntityDescriptor/@entityID" -n -m "//*[local-name()='EntityDescriptor']" -v "@entityID" -n "${tmpfile}" 1>/dev/null + ;; + *) + echo "Unsupported file type (${file}))" + exit 1 + ;; + esac + full_path=${base_dir}${file} mkdir -p "$(dirname ${full_path})" mv "${tmpfile}" "${full_path}"