#!/bin/sh set -eu value=${1-} policy_file=${BACKEND_URL_POLICY_FILE:-/etc/thothii/backend-url-policy.json} if jq -e --arg value "$value" '.relativeBases | index($value) != null' \ "$policy_file" >/dev/null; then exit 0 fi if ! jq -e --arg value "$value" \ '.absolutePattern as $pattern | $value | test($pattern)' \ "$policy_file" >/dev/null; then exit 2 fi authority=${value#*://} authority=${authority%%/*} port="" case "$authority" in *]:*) port=${authority##*:} ;; *]) ;; *:*) port=${authority##*:} ;; esac if [ -n "$port" ]; then max_port=$(jq -r '.maxPort' "$policy_file") if [ "${#port}" -gt 5 ] || [ "$port" -gt "$max_port" ]; then exit 2; fi fi