From 42c5c2c5c0a25586065a4f7f20e34b36effe978d Mon Sep 17 00:00:00 2001 From: Guillaume De Saint Martin Date: Tue, 1 Oct 2024 12:15:44 +0200 Subject: [PATCH] [Community] remove authenticated http calls --- .../community_supabase_client.py | 59 ------------------- 1 file changed, 59 deletions(-) diff --git a/octobot/community/supabase_backend/community_supabase_client.py b/octobot/community/supabase_backend/community_supabase_client.py index ab977f6e7..53b53081f 100644 --- a/octobot/community/supabase_backend/community_supabase_client.py +++ b/octobot/community/supabase_backend/community_supabase_client.py @@ -14,12 +14,10 @@ # You should have received a copy of the GNU General Public # License along with OctoBot. If not, see . import asyncio -import base64 import datetime import time import typing import logging -import httpx import uuid import json import contextlib @@ -66,41 +64,6 @@ def error_describer(): raise errors.SessionTokenExpiredError(err) from err raise - -def _httpx_retrier(f): - async def httpx_retrier_wrapper(*args, **kwargs): - resp = None - for i in range(0, HTTP_RETRY_COUNT): - error = None - try: - resp: httpx.Response = await f(*args, **kwargs) - if resp.status_code in (502, 503, 520): - # waking up or SLA issue, retry - error = f"{resp.status_code} error {resp.reason_phrase}" - commons_logging.get_logger(__name__).debug( - f"{f.__name__}(args={args[1:]}) failed with {error} after {i+1} attempts, retrying." - ) - else: - if i > 0: - commons_logging.get_logger(__name__).debug( - f"{f.__name__}(args={args[1:]}) succeeded after {i+1} attempts" - ) - return resp - except httpx.ReadTimeout as err: - error = f"{err} ({err.__class__.__name__})" - # retry - commons_logging.get_logger(__name__).debug( - f"Error on {f.__name__}(args={args[1:]}) " - f"request, retrying now. Attempt {i+1} / {HTTP_RETRY_COUNT} ({error})." - ) - # no more attempts - if resp: - resp.raise_for_status() - return resp - else: - raise errors.RequestError(f"Failed to execute {f.__name__}(args={args[1:]} kwargs={kwargs})") - return httpx_retrier_wrapper - class CommunitySupabaseClient(supabase_client.AuthenticatedAsyncSupabaseClient): """ Octobot Community layer added to supabase_client.AuthenticatedSupabaseClient @@ -829,28 +792,6 @@ def _get_auth_key(self): return session.access_token return self.supabase_key - @_httpx_retrier - async def http_get(self, url: str, *args, params=None, headers=None, **kwargs) -> httpx.Response: - """ - Perform http get using the current supabase auth token - """ - params = params or {} - params["access_token"] = params.get("access_token", base64.b64encode(self._get_auth_key().encode()).decode()) - return await self.postgrest.session.get(url, *args, params=params, headers=headers, **kwargs) - - @_httpx_retrier - async def http_post( - self, url: str, *args, json=None, params=None, headers=None, **kwargs - ) -> httpx.Response: - """ - Perform http get using the current supabase auth token - """ - json_body = json or {} - json_body["access_token"] = json_body.get("access_token", self._get_auth_key()) - return await self.postgrest.session.post( - url, *args, json=json_body, params=params, headers=headers, **kwargs - ) - @staticmethod def get_formatted_time(timestamp: float) -> str: return datetime.datetime.utcfromtimestamp(timestamp).isoformat('T')