fix: guard against non-dict route entries when filtering Caddy routes

r.get() crashed when the Caddy API returned a routes array containing
string elements. Added isinstance(r, dict) check and also made the
match[0] traversal safer by using any() over the match list.
This commit is contained in:
Claude 2026-03-19 10:55:40 +00:00
parent bddc1a8027
commit 11db59d612
No known key found for this signature in database

View file

@ -132,7 +132,10 @@ EOF
import sys, json import sys, json
routes = json.load(sys.stdin) routes = json.load(sys.stdin)
new_host = '${APP_ID}.${DOMAIN_SUFFIX}' new_host = '${APP_ID}.${DOMAIN_SUFFIX}'
routes = [r for r in routes if new_host not in r.get('match',[{}])[0].get('host',[])] routes = [r for r in routes
if not (isinstance(r, dict)
and any(isinstance(m, dict) and new_host in m.get('host', [])
for m in r.get('match', [])))]
routes.append(json.loads(sys.argv[1])) routes.append(json.loads(sys.argv[1]))
print(json.dumps(routes)) print(json.dumps(routes))
" "$ROUTE_JSON") " "$ROUTE_JSON")