Skip to content

Commit 559f526

Browse files
refactor: FIR-35468 remove account resolve endpoint from python sdk (#401)
1 parent 041e333 commit 559f526

File tree

21 files changed

+23
-465
lines changed

21 files changed

+23
-465
lines changed

src/firebolt/async_db/connection.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
from firebolt.client.auth import Auth
1212
from firebolt.client.client import AsyncClient, AsyncClientV1, AsyncClientV2
1313
from firebolt.common.base_connection import BaseConnection
14-
from firebolt.common.cache import (
15-
_firebolt_account_info_cache,
16-
_firebolt_system_engine_cache,
17-
)
14+
from firebolt.common.cache import _firebolt_system_engine_cache
1815
from firebolt.common.constants import DEFAULT_TIMEOUT_SECONDS
1916
from firebolt.utils.exception import ConfigurationError, ConnectionClosedError
2017
from firebolt.utils.usage_tracker import get_user_agent_header
@@ -135,7 +132,6 @@ async def connect(
135132
user_agent_header = get_user_agent_header(user_drivers, user_clients)
136133
if disable_cache:
137134
_firebolt_system_engine_cache.disable()
138-
_firebolt_account_info_cache.disable()
139135
# Use v2 if auth is ClientCredentials
140136
# Use v1 if auth is ServiceAccount or UsernamePassword
141137
auth_version = auth.get_firebolt_version()

src/firebolt/async_db/cursor.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,6 @@ async def _parse_response_headers(self, headers: Headers) -> None:
136136
endpoint, params = _parse_update_endpoint(
137137
headers.get(UPDATE_ENDPOINT_HEADER)
138138
)
139-
if (
140-
params.get("account_id", await self._client.account_id)
141-
!= await self._client.account_id
142-
):
143-
raise OperationalError(
144-
"USE ENGINE command failed. Account parameter mismatch. "
145-
"Contact support"
146-
)
147139
self._update_set_parameters(params)
148140
self.engine_url = endpoint
149141

src/firebolt/client/client.py

Lines changed: 3 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,12 @@
2020
AsyncKeepaliveTransport,
2121
KeepaliveTransport,
2222
)
23-
from firebolt.common._types import _AccountInfo
24-
from firebolt.common.cache import _firebolt_account_info_cache
2523
from firebolt.utils.exception import (
2624
AccountNotFoundError,
27-
AccountNotFoundOrNoAccessError,
2825
FireboltEngineError,
2926
InterfaceError,
3027
)
3128
from firebolt.utils.urls import (
32-
ACCOUNT_BY_NAME_URL,
3329
ACCOUNT_BY_NAME_URL_V1,
3430
ACCOUNT_ENGINE_ID_BY_NAME_URL,
3531
ACCOUNT_ENGINE_URL,
@@ -47,13 +43,6 @@
4743
FireboltClientMixinBase = mixin_for(HttpxClient) # type: Any
4844

4945

50-
def parse_response_for_account_info(response: Response) -> _AccountInfo:
51-
"""Construct account info object from the API response."""
52-
account_id = response.json()["id"]
53-
account_version = int(response.json().get("infraVersion", 2))
54-
return _AccountInfo(id=account_id, version=account_version)
55-
56-
5746
class FireboltClientMixin(FireboltClientMixinBase):
5847
"""HttpxAsyncClient mixin with Firebolt authentication functionality."""
5948

@@ -101,7 +90,7 @@ def _merge_auth_request(self, request: Request) -> Request:
10190
return request
10291

10392
def _enforce_trailing_slash(self, url: URL) -> URL:
104-
"""Don't automatically append trailing slach to a base url"""
93+
"""Don't automatically append trailing slash to a base url"""
10594
return url
10695

10796
def clone(self) -> "Client":
@@ -124,11 +113,6 @@ def __init__(self, *args: Any, **kwargs: Any):
124113
def account_id(self) -> str:
125114
...
126115

127-
@property
128-
@abstractmethod
129-
def _account_version(self) -> int:
130-
...
131-
132116
def _send_handling_redirects(
133117
self, request: Request, *args: Any, **kwargs: Any
134118
) -> Response:
@@ -161,40 +145,6 @@ def __init__(
161145
**kwargs,
162146
)
163147

164-
@property
165-
def _account_info(self) -> _AccountInfo:
166-
if account_info := _firebolt_account_info_cache.get(
167-
[self.account_name, self._api_endpoint.host]
168-
):
169-
return account_info
170-
response = self.get(
171-
url=self._api_endpoint.copy_with(
172-
path=ACCOUNT_BY_NAME_URL.format(account_name=self.account_name)
173-
)
174-
)
175-
if response.status_code == HttpxCodes.NOT_FOUND:
176-
assert self.account_name is not None
177-
raise AccountNotFoundOrNoAccessError(self.account_name)
178-
# process all other status codes
179-
response.raise_for_status()
180-
account_info = parse_response_for_account_info(response)
181-
_firebolt_account_info_cache.set(
182-
key=[self.account_name, self._api_endpoint.host], value=account_info
183-
)
184-
return account_info
185-
186-
@property
187-
def _account_version(self) -> int:
188-
"""User account version. 2 means both database and engine v2 are supported.
189-
190-
Returns:
191-
int: Account version
192-
193-
Raises:
194-
AccountNotFoundError: No account found with provided name
195-
"""
196-
return self._account_info.version
197-
198148
@property
199149
def account_id(self) -> str:
200150
"""User account ID.
@@ -208,7 +158,7 @@ def account_id(self) -> str:
208158
Raises:
209159
AccountNotFoundError: No account found with provided name
210160
"""
211-
return self._account_info.id
161+
return ""
212162

213163

214164
class ClientV1(Client):
@@ -236,13 +186,6 @@ def __init__(
236186
)
237187
self._auth_endpoint = URL(fix_url_schema(api_endpoint))
238188

239-
@property
240-
def _account_version(self) -> int:
241-
"""User account version. Hardcoded since it's not returned
242-
by the backend for V1.
243-
"""
244-
return 1
245-
246189
@cached_property
247190
def account_id(self) -> str:
248191
"""User account ID.
@@ -333,11 +276,6 @@ def __init__(self, *args: Any, **kwargs: Any):
333276
async def account_id(self) -> str:
334277
...
335278

336-
@property
337-
@abstractmethod
338-
async def _account_version(self) -> int:
339-
...
340-
341279
async def _send_handling_redirects(
342280
self, request: Request, *args: Any, **kwargs: Any
343281
) -> Response:
@@ -370,30 +308,6 @@ def __init__(
370308
**kwargs,
371309
)
372310

373-
async def _account_info(self) -> _AccountInfo:
374-
# manual caching to avoid async_cached_property issues
375-
if account_info := _firebolt_account_info_cache.get(
376-
[self.account_name, self._api_endpoint.host]
377-
):
378-
return account_info
379-
380-
response = await self.get(
381-
url=self._api_endpoint.copy_with(
382-
path=ACCOUNT_BY_NAME_URL.format(account_name=self.account_name)
383-
)
384-
)
385-
if response.status_code == HttpxCodes.NOT_FOUND:
386-
assert self.account_name is not None
387-
raise AccountNotFoundOrNoAccessError(self.account_name)
388-
# process all other status codes
389-
response.raise_for_status()
390-
account_info = parse_response_for_account_info(response)
391-
# cache for future use
392-
_firebolt_account_info_cache.set(
393-
key=[self.account_name, self._api_endpoint.host], value=account_info
394-
)
395-
return account_info
396-
397311
@property
398312
async def account_id(self) -> str:
399313
"""User account ID.
@@ -407,19 +321,7 @@ async def account_id(self) -> str:
407321
Raises:
408322
AccountNotFoundError: No account found with provided name
409323
"""
410-
return (await self._account_info()).id
411-
412-
@property
413-
async def _account_version(self) -> int:
414-
"""User account version. 2 means both database and engine v2 are supported.
415-
416-
Returns:
417-
int: Account version
418-
419-
Raises:
420-
AccountNotFoundError: No account found with provided name
421-
"""
422-
return (await self._account_info()).version
324+
return ""
423325

424326

425327
class AsyncClientV1(AsyncClient):
@@ -448,12 +350,6 @@ def __init__(
448350
self.account_id_cache: Dict[str, str] = {}
449351
self._auth_endpoint = URL(fix_url_schema(api_endpoint))
450352

451-
@property
452-
async def _account_version(self) -> int:
453-
"""User account version. Hardcoded since it's not returned
454-
by the backend for V1."""
455-
return 1
456-
457353
@property
458354
async def account_id(self) -> str:
459355
"""User account ID.

src/firebolt/common/cache.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
TypeVar,
1111
)
1212

13-
from firebolt.common._types import _AccountInfo
14-
1513
T = TypeVar("T")
1614

1715

@@ -85,4 +83,3 @@ def __contains__(self, key: str) -> bool:
8583
_firebolt_system_engine_cache = UtilCache[Tuple[str, Dict[str, str]]](
8684
cache_name="system_engine"
8785
)
88-
_firebolt_account_info_cache = UtilCache[_AccountInfo](cache_name="account_info")

src/firebolt/db/connection.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
from firebolt.client import DEFAULT_API_URL, Client, ClientV1, ClientV2
1111
from firebolt.client.auth import Auth
1212
from firebolt.common.base_connection import BaseConnection
13-
from firebolt.common.cache import (
14-
_firebolt_account_info_cache,
15-
_firebolt_system_engine_cache,
16-
)
13+
from firebolt.common.cache import _firebolt_system_engine_cache
1714
from firebolt.common.constants import DEFAULT_TIMEOUT_SECONDS
1815
from firebolt.db.cursor import Cursor, CursorV1, CursorV2
1916
from firebolt.db.util import _get_system_engine_url_and_params
@@ -48,7 +45,6 @@ def connect(
4845
auth_version = auth.get_firebolt_version()
4946
if disable_cache:
5047
_firebolt_system_engine_cache.disable()
51-
_firebolt_account_info_cache.disable()
5248
# Use v2 if auth is ClientCredentials
5349
# Use v1 if auth is ServiceAccount or UsernamePassword
5450
if auth_version == 2:

src/firebolt/db/cursor.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,6 @@ def _parse_response_headers(self, headers: Headers) -> None:
135135
endpoint, params = _parse_update_endpoint(
136136
headers.get(UPDATE_ENDPOINT_HEADER)
137137
)
138-
if (
139-
params.get("account_id", self._client.account_id)
140-
!= self._client.account_id
141-
):
142-
raise OperationalError(
143-
"USE ENGINE command failed. Account parameter mismatch. "
144-
"Contact support"
145-
)
146138
self._update_set_parameters(params)
147139
self.engine_url = endpoint
148140

src/firebolt/utils/urls.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
ENGINES_URL = "/core/v1/account/engines"
66
ENGINES_BY_IDS_URL = "/core/v1/engines:getByIds"
77

8-
ACCOUNT_BY_NAME_URL = "/web/v3/account/{account_name}/resolve"
9-
108
ACCOUNT_DATABASES_URL = "/core/v1/accounts/{account_id}/databases"
119
ACCOUNT_DATABASE_URL = "/core/v1/accounts/{account_id}/databases/{database_id}"
1210
ACCOUNT_DATABASE_BINDING_URL = ACCOUNT_DATABASE_URL + "/bindings/{engine_id}"

tests/integration/dbapi/async/V2/test_system_engine_async.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,6 @@ async def test_system_engine_no_db(
7777
)
7878

7979

80-
async def test_system_engine_account(connection_system_engine: Connection):
81-
assert (
82-
await connection_system_engine._client.account_id
83-
), "Can't get account id explicitly"
84-
assert (
85-
await connection_system_engine._client._account_version
86-
) == 2, "Invalid account version"
87-
88-
8980
async def test_system_engine_use_engine(
9081
connection_system_engine: Connection, database_name: str, engine_name: str
9182
):

tests/integration/dbapi/sync/V2/test_system_engine.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,6 @@ def test_system_engine_no_db(
7878
)
7979

8080

81-
def test_system_engine_account(connection_system_engine: Connection):
82-
assert (
83-
connection_system_engine._client.account_id
84-
), "Can't get account id explicitly"
85-
assert (
86-
connection_system_engine._client._account_version == 2
87-
), "Invalid account version"
88-
89-
9081
def test_system_engine_use_engine(
9182
connection_system_engine: Connection, database_name: str, engine_name: str
9283
):

tests/unit/V1/client/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pytest import fixture
88

99
from firebolt.utils.exception import AccountNotFoundError
10-
from firebolt.utils.urls import ACCOUNT_BY_NAME_URL, ACCOUNT_URL, AUTH_URL
10+
from firebolt.utils.urls import ACCOUNT_BY_NAME_URL_V1, ACCOUNT_URL, AUTH_URL
1111
from tests.unit.response import Response
1212

1313

@@ -91,7 +91,7 @@ def check_credentials(
9191

9292
@fixture
9393
def account_id_url(api_endpoint: str) -> Pattern:
94-
base = f"https://{api_endpoint}{ACCOUNT_BY_NAME_URL}?account_name="
94+
base = f"https://{api_endpoint}{ACCOUNT_BY_NAME_URL_V1}?account_name="
9595
default_base = f"https://{api_endpoint}{ACCOUNT_URL}"
9696
base = base.replace("/", "\\/").replace("?", "\\?")
9797
default_base = default_base.replace("/", "\\/").replace("?", "\\?")

0 commit comments

Comments
 (0)