Skip to content

Commit 8af1a51

Browse files
committed
[Community] remove authenticated http calls
1 parent 47c67e9 commit 8af1a51

File tree

1 file changed

+0
-59
lines changed

1 file changed

+0
-59
lines changed

octobot/community/supabase_backend/community_supabase_client.py

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@
1414
# You should have received a copy of the GNU General Public
1515
# License along with OctoBot. If not, see <https://www.gnu.org/licenses/>.
1616
import asyncio
17-
import base64
1817
import datetime
1918
import time
2019
import typing
2120
import logging
22-
import httpx
2321
import uuid
2422
import json
2523
import contextlib
@@ -66,41 +64,6 @@ def error_describer():
6664
raise errors.SessionTokenExpiredError(err) from err
6765
raise
6866

69-
70-
def _httpx_retrier(f):
71-
async def httpx_retrier_wrapper(*args, **kwargs):
72-
resp = None
73-
for i in range(0, HTTP_RETRY_COUNT):
74-
error = None
75-
try:
76-
resp: httpx.Response = await f(*args, **kwargs)
77-
if resp.status_code in (502, 503, 520):
78-
# waking up or SLA issue, retry
79-
error = f"{resp.status_code} error {resp.reason_phrase}"
80-
commons_logging.get_logger(__name__).debug(
81-
f"{f.__name__}(args={args[1:]}) failed with {error} after {i+1} attempts, retrying."
82-
)
83-
else:
84-
if i > 0:
85-
commons_logging.get_logger(__name__).debug(
86-
f"{f.__name__}(args={args[1:]}) succeeded after {i+1} attempts"
87-
)
88-
return resp
89-
except httpx.ReadTimeout as err:
90-
error = f"{err} ({err.__class__.__name__})"
91-
# retry
92-
commons_logging.get_logger(__name__).debug(
93-
f"Error on {f.__name__}(args={args[1:]}) "
94-
f"request, retrying now. Attempt {i+1} / {HTTP_RETRY_COUNT} ({error})."
95-
)
96-
# no more attempts
97-
if resp:
98-
resp.raise_for_status()
99-
return resp
100-
else:
101-
raise errors.RequestError(f"Failed to execute {f.__name__}(args={args[1:]} kwargs={kwargs})")
102-
return httpx_retrier_wrapper
103-
10467
class CommunitySupabaseClient(supabase_client.AuthenticatedAsyncSupabaseClient):
10568
"""
10669
Octobot Community layer added to supabase_client.AuthenticatedSupabaseClient
@@ -829,28 +792,6 @@ def _get_auth_key(self):
829792
return session.access_token
830793
return self.supabase_key
831794

832-
@_httpx_retrier
833-
async def http_get(self, url: str, *args, params=None, headers=None, **kwargs) -> httpx.Response:
834-
"""
835-
Perform http get using the current supabase auth token
836-
"""
837-
params = params or {}
838-
params["access_token"] = params.get("access_token", base64.b64encode(self._get_auth_key().encode()).decode())
839-
return await self.postgrest.session.get(url, *args, params=params, headers=headers, **kwargs)
840-
841-
@_httpx_retrier
842-
async def http_post(
843-
self, url: str, *args, json=None, params=None, headers=None, **kwargs
844-
) -> httpx.Response:
845-
"""
846-
Perform http get using the current supabase auth token
847-
"""
848-
json_body = json or {}
849-
json_body["access_token"] = json_body.get("access_token", self._get_auth_key())
850-
return await self.postgrest.session.post(
851-
url, *args, json=json_body, params=params, headers=headers, **kwargs
852-
)
853-
854795
@staticmethod
855796
def get_formatted_time(timestamp: float) -> str:
856797
return datetime.datetime.utcfromtimestamp(timestamp).isoformat('T')

0 commit comments

Comments
 (0)