Skip to content

Commit 1fc4d8d

Browse files
committed
minor
1 parent b3af500 commit 1fc4d8d

File tree

1 file changed

+14
-21
lines changed
  • services/api-server/src/simcore_service_api_server/repository

1 file changed

+14
-21
lines changed

services/api-server/src/simcore_service_api_server/repository/api_keys.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
import sqlalchemy as sa
55
from models_library.products import ProductName
66
from pydantic.types import PositiveInt
7-
from simcore_postgres_database.aiopg_errors import DatabaseError
8-
from simcore_postgres_database.models.api_keys import api_keys as api_keys_table
7+
from simcore_postgres_database.models.api_keys import api_keys as auth_api_keys_table
98
from simcore_postgres_database.utils_repos import pass_or_acquire_connection
109
from sqlalchemy.ext.asyncio import AsyncConnection
1110

@@ -31,28 +30,22 @@ async def get_user(
3130
) -> UserAndProductTuple | None:
3231

3332
stmt = sa.select(
34-
api_keys_table.c.user_id,
35-
api_keys_table.c.product_name,
33+
auth_api_keys_table.c.user_id,
34+
auth_api_keys_table.c.product_name,
3635
).where(
3736
(
38-
api_keys_table.c.api_key == api_key
37+
auth_api_keys_table.c.api_key == api_key
3938
) # NOTE: keep order, api_key is indexed
4039
& (
41-
api_keys_table.c.api_secret
42-
== sa.func.crypt(api_secret, api_keys_table.c.api_secret)
40+
auth_api_keys_table.c.api_secret
41+
== sa.func.crypt(api_secret, auth_api_keys_table.c.api_secret)
4342
)
4443
)
45-
result: UserAndProductTuple | None = None
46-
try:
47-
async with pass_or_acquire_connection(self.db_engine, connection) as conn:
48-
db_result = await conn.execute(stmt)
49-
row = db_result.one_or_none()
50-
if row:
51-
result = UserAndProductTuple(
52-
user_id=row.user_id, product_name=row.product_name
53-
)
54-
55-
except DatabaseError as err:
56-
_logger.debug("Failed to get user id: %s", err)
57-
58-
return result
44+
async with pass_or_acquire_connection(self.db_engine, connection) as conn:
45+
result = await conn.execute(stmt)
46+
row = result.one_or_none()
47+
return (
48+
UserAndProductTuple(user_id=row.user_id, product_name=row.product_name)
49+
if row
50+
else None
51+
)

0 commit comments

Comments
 (0)