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:
parent
bddc1a8027
commit
11db59d612
1 changed files with 4 additions and 1 deletions
|
|
@ -132,7 +132,10 @@ EOF
|
|||
import sys, json
|
||||
routes = json.load(sys.stdin)
|
||||
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]))
|
||||
print(json.dumps(routes))
|
||||
" "$ROUTE_JSON")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue