This commit is contained in:
2026-05-06 22:41:53 +03:30
parent 2ce93b51d7
commit dfb103e16a
5 changed files with 45 additions and 76 deletions
+28 -4
View File
@@ -1,16 +1,41 @@
import requests
import time
import redis
from utils.yaml_loader import load_config
def http_request(method, url, **kwargs):
redis_client = redis.Redis(
host="redis",
port=6379,
decode_responses=True
)
config = load_config()
def http_request(method, url, authenticated=True, **kwargs):
start = time.time()
response = requests.request(method, url, **kwargs)
headers = kwargs.pop("headers", {})
if authenticated:
token_key = config["flows"]["auth"]["login"]["store_redis"]["key"]
token = redis_client.get(token_key)
if token:
headers["Authorization"] = f"Bearer {token}"
response = requests.request(
method,
url,
headers=headers,
**kwargs
)
latency = time.time() - start
try:
data = response.json()
except:
except Exception:
data = response.text
return {
@@ -18,4 +43,3 @@ def http_request(method, url, **kwargs):
"data": data,
"latency": latency
}
+2 -2
View File
@@ -1,6 +1,6 @@
import yaml
def load_apis():
with open("apis.yaml", "r") as f:
def load_config():
with open("config/apis.yaml", "r") as f:
return yaml.safe_load(f)