diff --git a/create-nginx-map.py b/create-nginx-map.py index 726864a..08b9abc 100644 --- a/create-nginx-map.py +++ b/create-nginx-map.py @@ -2,10 +2,10 @@ import requests from typing import NamedTuple import re import sys -import operator import tomllib from pathlib import Path from typing import TypedDict +from collections import defaultdict TRAEFIK_HOST_RE = re.compile(r"Host\(`([a-z0-9\.-]+)`\)") @@ -86,10 +86,14 @@ def main(): if len(routes) != len(set(routes)): raise ValueError("Conflict found!") - for route in sorted(routes, key=operator.attrgetter("hostname")): - print(f"{route.hostname}\t{route.destination}; # {route.name}") + grouped_routes = defaultdict(set) + for route in routes: + grouped_routes[route.hostname, route.destination].add(route.name) - print("Found", len(routes), "routes") + for (hostname, destination), names in sorted(grouped_routes.items()): + print(f"{hostname}\t{destination}; # {', '.join(names)}") + + print("Found", len(routes), "routes, grouped into", len(grouped_routes), "groups") if __name__ == "__main__": main()