eid-ops/natmd-test-common/overlay/opt/mdqp/post.d/40-create-transitive

53 lines
1.1 KiB
Bash
Executable file

#!/usr/bin/env bash
set -e
base_url="http://localhost:8080"
base_dir="/opt/mdqp/work/signed_metadata"
tmpfile=$(mktemp /tmp/"$(basename "$0")".XXXXXX)
for expression in "role-sp" "role-idp" "index.html"; do
echo "Fetching up ${expression}"
case $expression in
role-sp)
url="role/sp.xml"
file="/role/sp.xml"
;;
role-idp)
url="role/idp.xml"
file="/role/idp.xml"
;;
index.html)
url="entities/"
file="/entities/index.html"
;;
*)
echo "Unsupported expression ${expression}"
exit 1
;;
esac
curl ${base_url}/${url} -o "${tmpfile}"
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}"
done