From 8e00d6c9184cc7bbb48871000365ae4c858589d1 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 1 Nov 2023 21:45:14 +0000 Subject: [PATCH] Remove requests external dependency --- create-nginx-map.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/create-nginx-map.py b/create-nginx-map.py index 08b9abc..eb60936 100644 --- a/create-nginx-map.py +++ b/create-nginx-map.py @@ -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()