1
Fork 0

Group routes

This commit is contained in:
Jake Howard 2023-10-31 19:15:26 +00:00
parent 48d8b5511c
commit d2e93bdc58
Signed by: jake
GPG key ID: 57AFB45680EDD477

View file

@ -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()