Skip to content

Commit

Permalink
[Community] remove authenticated http calls
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeDSM committed Oct 3, 2024
1 parent 127c7e7 commit 6341d36
Showing 1 changed file with 0 additions and 59 deletions.
59 changes: 0 additions & 59 deletions octobot/community/supabase_backend/community_supabase_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
# You should have received a copy of the GNU General Public
# License along with OctoBot. If not, see <https://www.gnu.org/licenses/>.
import asyncio
import base64
import datetime
import time
import typing
import logging
import httpx
import uuid
import json
import contextlib
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 6341d36

Please sign in to comment.