11from datetime import timedelta
22
33from fastapi import FastAPI
4- from models_library .api_schemas_webserver import WEBSERVER_RPC_NAMESPACE
54from models_library .products import ProductName
6- from models_library .rabbitmq_basic_types import RPCMethodName
7- from models_library .rpc .webserver .auth .api_keys import ApiKeyGet
5+ from models_library .rpc .webserver .auth .api_keys import ApiKeyCreate , ApiKeyGet
86from models_library .users import UserID
9- from pydantic import TypeAdapter
7+ from servicelib .rabbitmq .rpc_interfaces .webserver .auth import (
8+ api_keys as webserver_auth_api_keys_rpc ,
9+ )
1010
1111from ..rabbitmq import get_rabbitmq_rpc_client
1212
13- #
14- # RPC interface
15- #
16-
1713
1814async def create_api_key (
1915 app : FastAPI ,
@@ -24,15 +20,13 @@ async def create_api_key(
2420 expiration : timedelta | None = None ,
2521) -> ApiKeyGet :
2622 rpc_client = get_rabbitmq_rpc_client (app )
27- result = await rpc_client .request (
28- WEBSERVER_RPC_NAMESPACE ,
29- TypeAdapter (RPCMethodName ).validate_python ("create_api_key" ),
30- product_name = product_name ,
23+
24+ return await webserver_auth_api_keys_rpc .create_api_key (
25+ rpc_client ,
3126 user_id = user_id ,
32- display_name = display_name ,
33- expiration = expiration ,
27+ product_name = product_name ,
28+ api_key = ApiKeyCreate ( display_name = display_name , expiration = expiration ) ,
3429 )
35- return ApiKeyGet .model_validate (result )
3630
3731
3832async def delete_api_key_by_key (
@@ -43,10 +37,12 @@ async def delete_api_key_by_key(
4337 api_key : str ,
4438) -> None :
4539 rpc_client = get_rabbitmq_rpc_client (app )
46- await rpc_client . request (
47- WEBSERVER_RPC_NAMESPACE ,
48- TypeAdapter ( RPCMethodName ). validate_python ( "delete_api_key_by_key" ) ,
40+
41+ result = await webserver_auth_api_keys_rpc . delete_api_key_by_key (
42+ rpc_client ,
4943 product_name = product_name ,
5044 user_id = user_id ,
5145 api_key = api_key ,
5246 )
47+
48+ assert result is None
0 commit comments