1
Fork 0

Remove requests external dependency

This commit is contained in:
Jake Howard 2023-11-01 21:45:14 +00:00
parent d2e93bdc58
commit 8e00d6c918
Signed by: jake
GPG key ID: 57AFB45680EDD477

View file

@ -1,4 +1,3 @@
import requests
from typing import NamedTuple
import re
import sys
@ -6,6 +5,8 @@ import tomllib
from pathlib import Path
from typing import TypedDict
from collections import defaultdict
from urllib.request import urlopen
import json
TRAEFIK_HOST_RE = re.compile(r"Host\(`([a-z0-9\.-]+)`\)")
@ -35,7 +36,9 @@ def parse_traefik_rule(rule: str) -> list[str]:
def get_traefik_routes(traefik_host: str, traefik_route: str):
api_response = requests.get(f"{traefik_host}/api/http/routers").json()
with urlopen(f"{traefik_host}/api/http/routers") as response:
api_response = json.load(response)
routes = set()
for router in api_response:
@ -57,7 +60,8 @@ def get_traefik_routes(traefik_host: str, traefik_route: str):
return routes
def get_dokku_routes(dokku_exporter_url: str, dokku_route: str):
api_response = requests.get(dokku_exporter_url).json()
with urlopen(dokku_exporter_url) as response:
api_response = json.load(response)
routes = set()