2026-05-06 22:16:58 +03:30
|
|
|
import requests
|
|
|
|
|
import time
|
2026-05-06 22:41:53 +03:30
|
|
|
import redis
|
|
|
|
|
from utils.yaml_loader import load_config
|
2026-05-06 22:16:58 +03:30
|
|
|
|
2026-05-06 22:41:53 +03:30
|
|
|
redis_client = redis.Redis(
|
|
|
|
|
host="redis",
|
|
|
|
|
port=6379,
|
|
|
|
|
decode_responses=True
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
config = load_config()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def http_request(method, url, authenticated=True, **kwargs):
|
2026-05-06 22:16:58 +03:30
|
|
|
start = time.time()
|
|
|
|
|
|
2026-05-06 22:41:53 +03:30
|
|
|
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
|
|
|
|
|
)
|
2026-05-06 22:16:58 +03:30
|
|
|
|
|
|
|
|
latency = time.time() - start
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
data = response.json()
|
2026-05-06 22:41:53 +03:30
|
|
|
except Exception:
|
2026-05-06 22:16:58 +03:30
|
|
|
data = response.text
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
"status": response.status_code,
|
|
|
|
|
"data": data,
|
|
|
|
|
"latency": latency
|
|
|
|
|
}
|