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 from typing import NamedTuple
import re import re
import sys import sys
import operator
import tomllib import tomllib
from pathlib import Path from pathlib import Path
from typing import TypedDict from typing import TypedDict
from collections import defaultdict
TRAEFIK_HOST_RE = re.compile(r"Host\(`([a-z0-9\.-]+)`\)") TRAEFIK_HOST_RE = re.compile(r"Host\(`([a-z0-9\.-]+)`\)")
@ -86,10 +86,14 @@ def main():
if len(routes) != len(set(routes)): if len(routes) != len(set(routes)):
raise ValueError("Conflict found!") raise ValueError("Conflict found!")
for route in sorted(routes, key=operator.attrgetter("hostname")): grouped_routes = defaultdict(set)
print(f"{route.hostname}\t{route.destination}; # {route.name}") 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__": if __name__ == "__main__":
main() main()