Skip to content

Commit 4f38b88

Browse files
bisgaard-itismrnicegyu11
authored andcommitted
♻️ Refactor and polish api keys domain of webserver (ITISFoundation#7293)
1 parent 6362c1b commit 4f38b88

File tree

7 files changed

+8
-41
lines changed

7 files changed

+8
-41
lines changed

api/specs/web-server/_auth_api_keys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from models_library.generics import Envelope
1010
from models_library.rest_error import EnvelopedError
1111
from simcore_service_webserver._meta import API_VTAG
12+
from simcore_service_webserver.api_keys._controller_rest import ApiKeysPathParams
1213
from simcore_service_webserver.api_keys._exceptions_handlers import _TO_HTTP_ERROR_MAP
13-
from simcore_service_webserver.api_keys._rest import ApiKeysPathParams
1414

1515
router = APIRouter(
1616
prefix=f"/{API_VTAG}",

services/web/server/src/simcore_service_webserver/api_keys/_repository.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -180,40 +180,6 @@ async def delete_api_key(
180180
await conn.execute(stmt)
181181

182182

183-
async def delete_by_name(
184-
app: web.Application,
185-
connection: AsyncConnection | None = None,
186-
*,
187-
display_name: str,
188-
user_id: UserID,
189-
product_name: ProductName,
190-
) -> None:
191-
async with transaction_context(get_asyncpg_engine(app), connection) as conn:
192-
stmt = api_keys.delete().where(
193-
(api_keys.c.user_id == user_id)
194-
& (api_keys.c.display_name == display_name)
195-
& (api_keys.c.product_name == product_name)
196-
)
197-
await conn.execute(stmt)
198-
199-
200-
async def delete_by_key(
201-
app: web.Application,
202-
connection: AsyncConnection | None = None,
203-
*,
204-
api_key: str,
205-
user_id: UserID,
206-
product_name: ProductName,
207-
) -> None:
208-
async with transaction_context(get_asyncpg_engine(app), connection) as conn:
209-
stmt = api_keys.delete().where(
210-
(api_keys.c.user_id == user_id)
211-
& (api_keys.c.api_key == api_key)
212-
& (api_keys.c.product_name == product_name)
213-
)
214-
await conn.execute(stmt)
215-
216-
217183
async def prune_expired(
218184
app: web.Application, connection: AsyncConnection | None = None
219185
) -> list[str]:

services/web/server/src/simcore_service_webserver/api_keys/plugin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from ..products.plugin import setup_products
99
from ..rabbitmq import setup_rabbitmq
1010
from ..rest.plugin import setup_rest
11-
from . import _rest, _rpc
11+
from . import _controller_rest, _controller_rpc
1212

1313
_logger = logging.getLogger(__name__)
1414

@@ -26,9 +26,9 @@ def setup_api_keys(app: web.Application):
2626

2727
# http api
2828
setup_rest(app)
29-
app.router.add_routes(_rest.routes)
29+
app.router.add_routes(_controller_rest.routes)
3030

3131
# rpc api
3232
setup_rabbitmq(app)
3333
if app[APP_SETTINGS_KEY].WEBSERVER_RABBITMQ:
34-
app.on_startup.append(_rpc.register_rpc_routes_on_startup)
34+
app.on_startup.append(_controller_rpc.register_rpc_routes_on_startup)

services/web/server/src/simcore_service_webserver/garbage_collector/_tasks_api_keys.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""
2-
Scheduled task that periodically runs prune in the garbage collector service
2+
Scheduled task that periodically runs prune in the garbage collector service
33
44
"""
5+
56
import asyncio
67
import logging
78
from collections.abc import AsyncIterator, Callable
@@ -11,7 +12,7 @@
1112
from tenacity.before_sleep import before_sleep_log
1213
from tenacity.wait import wait_exponential
1314

14-
from ..api_keys.api import prune_expired_api_keys
15+
from ..api_keys import api_keys_service
1516

1617
logger = logging.getLogger(__name__)
1718

@@ -31,7 +32,7 @@ async def _run_task(app: web.Application):
3132
3233
It is resilient, i.e. if update goes wrong, it waits a bit and retries
3334
"""
34-
if deleted := await prune_expired_api_keys(app):
35+
if deleted := await api_keys_service.prune_expired_api_keys(app):
3536
# broadcast force logout of user_id
3637
for api_key in deleted:
3738
logger.info("API-key %s expired and was removed", f"{api_key=}")

0 commit comments

Comments
 (0)