Skip to content

Commit

Permalink
first draft of the solution (#497)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marinovsky authored Sep 5, 2024
1 parent cdc59be commit 3b59b3d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lean/components/api/auth0_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self, api_client: 'APIClient') -> None:
:param api_client: the APIClient instance to use when making requests
"""
self._api = api_client
self._cache = {}

def read(self, brokerage_id: str) -> QCAuth0Authorization:
"""Reads the authorization data for a brokerage.
Expand All @@ -35,12 +36,18 @@ def read(self, brokerage_id: str) -> QCAuth0Authorization:
:return: the authorization data for the specified brokerage
"""
try:
# First check cache
if brokerage_id in self._cache.keys():
return self._cache[brokerage_id]
payload = {
"brokerage": brokerage_id
}

data = self._api.post("live/auth0/read", payload)
return QCAuth0Authorization(**data)
# Store in cache
result = QCAuth0Authorization(**data)
self._cache[brokerage_id] = result
return result
except RequestFailedError as e:
return QCAuth0Authorization(authorization=None)

Expand Down

0 comments on commit 3b59b3d

Please sign in to comment.