Skip to content

Commit 8516e4e

Browse files
committed
✨ Refactor RPC calls to use dynamic RPCNamespace across various webserver interfaces
1 parent bccb1d6 commit 8516e4e

File tree

7 files changed

+95
-79
lines changed

7 files changed

+95
-79
lines changed

packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/webserver/auth/api_keys.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import logging
22

3-
from models_library.api_schemas_webserver import WEBSERVER_RPC_NAMESPACE
43
from models_library.basic_types import IDStr
5-
from models_library.rabbitmq_basic_types import RPCMethodName
4+
from models_library.rabbitmq_basic_types import RPCMethodName, RPCNamespace
65
from models_library.rpc.webserver.auth.api_keys import ApiKeyCreate, ApiKeyGet
76
from models_library.users import UserID
87
from pydantic import TypeAdapter
@@ -16,13 +15,14 @@
1615
@log_decorator(_logger, level=logging.DEBUG)
1716
async def create_api_key(
1817
rabbitmq_rpc_client: RabbitMQRPCClient,
18+
rpc_namespace: RPCNamespace,
1919
*,
2020
user_id: UserID,
2121
product_name: str,
2222
api_key: ApiKeyCreate,
2323
) -> ApiKeyGet:
2424
result: ApiKeyGet = await rabbitmq_rpc_client.request(
25-
WEBSERVER_RPC_NAMESPACE,
25+
rpc_namespace,
2626
TypeAdapter(RPCMethodName).validate_python("create_api_key"),
2727
user_id=user_id,
2828
product_name=product_name,
@@ -36,13 +36,14 @@ async def create_api_key(
3636
@log_decorator(_logger, level=logging.DEBUG)
3737
async def get_api_key(
3838
rabbitmq_rpc_client: RabbitMQRPCClient,
39+
rpc_namespace: RPCNamespace,
3940
*,
4041
user_id: UserID,
4142
product_name: str,
4243
api_key_id: IDStr,
4344
) -> ApiKeyGet:
4445
result: ApiKeyGet = await rabbitmq_rpc_client.request(
45-
WEBSERVER_RPC_NAMESPACE,
46+
rpc_namespace,
4647
TypeAdapter(RPCMethodName).validate_python("get_api_key"),
4748
user_id=user_id,
4849
product_name=product_name,
@@ -55,13 +56,14 @@ async def get_api_key(
5556
@log_decorator(_logger, level=logging.DEBUG)
5657
async def delete_api_key_by_key(
5758
rabbitmq_rpc_client: RabbitMQRPCClient,
59+
rpc_namespace: RPCNamespace,
5860
*,
5961
user_id: UserID,
6062
product_name: str,
6163
api_key: str,
6264
) -> None:
6365
result = await rabbitmq_rpc_client.request(
64-
WEBSERVER_RPC_NAMESPACE,
66+
rpc_namespace,
6567
TypeAdapter(RPCMethodName).validate_python("delete_api_key_by_key"),
6668
user_id=user_id,
6769
product_name=product_name,

packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/webserver/functions/functions_rpc_interface.py

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
RegisteredFunctionJobWithStatus,
2929
)
3030
from models_library.products import ProductName
31-
from models_library.rabbitmq_basic_types import RPCMethodName
3231
from models_library.rest_ordering import OrderBy
32+
33+
from models_library.rabbitmq_basic_types import RPCMethodName, RPCNamespace
3334
from models_library.rest_pagination import PageMetaInfoLimitOffset
3435
from models_library.users import UserID
3536
from pydantic import TypeAdapter
@@ -42,34 +43,34 @@
4243

4344
@log_decorator(_logger, level=logging.DEBUG)
4445
async def register_function(
45-
rabbitmq_rpc_client: RabbitMQRPCClient,
46+
rpc_client: RabbitMQRPCClient,
47+
rpc_namespace: RPCNamespace,
4648
*,
4749
user_id: UserID,
4850
product_name: ProductName,
4951
function: Function,
5052
) -> RegisteredFunction:
51-
result = await rabbitmq_rpc_client.request(
52-
WEBSERVER_RPC_NAMESPACE,
53+
result = await rpc_client.request(
54+
rpc_namespace,
5355
TypeAdapter(RPCMethodName).validate_python("register_function"),
5456
function=function,
5557
user_id=user_id,
5658
product_name=product_name,
5759
)
58-
return TypeAdapter(RegisteredFunction).validate_python(
59-
result
60-
) # Validates the result as a RegisteredFunction
60+
return TypeAdapter(RegisteredFunction).validate_python(result)
6161

6262

6363
@log_decorator(_logger, level=logging.DEBUG)
6464
async def get_function(
65-
rabbitmq_rpc_client: RabbitMQRPCClient,
65+
rpc_client: RabbitMQRPCClient,
66+
rpc_namespace: RPCNamespace,
6667
*,
6768
user_id: UserID,
6869
product_name: ProductName,
6970
function_id: FunctionID,
7071
) -> RegisteredFunction:
71-
result = await rabbitmq_rpc_client.request(
72-
WEBSERVER_RPC_NAMESPACE,
72+
result = await rpc_client.request(
73+
rpc_namespace,
7374
TypeAdapter(RPCMethodName).validate_python("get_function"),
7475
function_id=function_id,
7576
user_id=user_id,
@@ -80,14 +81,15 @@ async def get_function(
8081

8182
@log_decorator(_logger, level=logging.DEBUG)
8283
async def get_function_input_schema(
83-
rabbitmq_rpc_client: RabbitMQRPCClient,
84+
rpc_client: RabbitMQRPCClient,
85+
rpc_namespace: RPCNamespace,
8486
*,
8587
function_id: FunctionID,
8688
user_id: UserID,
8789
product_name: ProductName,
8890
) -> FunctionInputSchema:
89-
result = await rabbitmq_rpc_client.request(
90-
WEBSERVER_RPC_NAMESPACE,
91+
result = await rpc_client.request(
92+
rpc_namespace,
9193
TypeAdapter(RPCMethodName).validate_python("get_function_input_schema"),
9294
function_id=function_id,
9395
user_id=user_id,
@@ -98,14 +100,15 @@ async def get_function_input_schema(
98100

99101
@log_decorator(_logger, level=logging.DEBUG)
100102
async def get_function_output_schema(
101-
rabbitmq_rpc_client: RabbitMQRPCClient,
103+
rpc_client: RabbitMQRPCClient,
104+
rpc_namespace: RPCNamespace,
102105
*,
103106
function_id: FunctionID,
104107
user_id: UserID,
105108
product_name: ProductName,
106109
) -> FunctionOutputSchema:
107-
result = await rabbitmq_rpc_client.request(
108-
WEBSERVER_RPC_NAMESPACE,
110+
result = await rpc_client.request(
111+
rpc_namespace,
109112
TypeAdapter(RPCMethodName).validate_python("get_function_output_schema"),
110113
function_id=function_id,
111114
user_id=user_id,
@@ -116,14 +119,15 @@ async def get_function_output_schema(
116119

117120
@log_decorator(_logger, level=logging.DEBUG)
118121
async def delete_function(
119-
rabbitmq_rpc_client: RabbitMQRPCClient,
122+
rpc_client: RabbitMQRPCClient,
123+
rpc_namespace: RPCNamespace,
120124
*,
121125
function_id: FunctionID,
122126
user_id: UserID,
123127
product_name: ProductName,
124128
) -> None:
125-
result = await rabbitmq_rpc_client.request(
126-
WEBSERVER_RPC_NAMESPACE,
129+
result = await rpc_client.request(
130+
rpc_namespace,
127131
TypeAdapter(RPCMethodName).validate_python("delete_function"),
128132
function_id=function_id,
129133
user_id=user_id,
@@ -135,7 +139,7 @@ async def delete_function(
135139

136140
@log_decorator(_logger, level=logging.DEBUG)
137141
async def list_functions(
138-
rabbitmq_rpc_client: RabbitMQRPCClient,
142+
rpc_client: RabbitMQRPCClient,
139143
*,
140144
user_id: UserID,
141145
product_name: ProductName,
@@ -147,7 +151,7 @@ async def list_functions(
147151
search_by_multi_columns: str | None = None,
148152
) -> tuple[list[RegisteredFunction], PageMetaInfoLimitOffset]:
149153
result: tuple[list[RegisteredFunction], PageMetaInfoLimitOffset] = (
150-
await rabbitmq_rpc_client.request(
154+
await rpc_client.request(
151155
WEBSERVER_RPC_NAMESPACE,
152156
TypeAdapter(RPCMethodName).validate_python("list_functions"),
153157
pagination_offset=pagination_offset,
@@ -167,7 +171,7 @@ async def list_functions(
167171

168172
@log_decorator(_logger, level=logging.DEBUG)
169173
async def list_function_jobs(
170-
rabbitmq_rpc_client: RabbitMQRPCClient,
174+
rpc_client: RabbitMQRPCClient,
171175
*,
172176
user_id: UserID,
173177
product_name: ProductName,
@@ -178,7 +182,7 @@ async def list_function_jobs(
178182
filter_by_function_job_collection_id: FunctionJobCollectionID | None = None,
179183
) -> tuple[list[RegisteredFunctionJob], PageMetaInfoLimitOffset]:
180184
result: tuple[list[RegisteredFunctionJob], PageMetaInfoLimitOffset] = (
181-
await rabbitmq_rpc_client.request(
185+
await rpc_client.request(
182186
WEBSERVER_RPC_NAMESPACE,
183187
TypeAdapter(RPCMethodName).validate_python("list_function_jobs"),
184188
user_id=user_id,
@@ -231,15 +235,15 @@ async def list_function_jobs_with_status(
231235

232236
@log_decorator(_logger, level=logging.DEBUG)
233237
async def list_function_job_collections(
234-
rabbitmq_rpc_client: RabbitMQRPCClient,
238+
rpc_client: RabbitMQRPCClient,
235239
*,
236240
user_id: UserID,
237241
product_name: ProductName,
238242
pagination_limit: int,
239243
pagination_offset: int,
240244
filters: FunctionJobCollectionsListFilters | None = None,
241245
) -> tuple[list[RegisteredFunctionJobCollection], PageMetaInfoLimitOffset]:
242-
result = await rabbitmq_rpc_client.request(
246+
result = await rpc_client.request(
243247
WEBSERVER_RPC_NAMESPACE,
244248
TypeAdapter(RPCMethodName).validate_python("list_function_job_collections"),
245249
pagination_offset=pagination_offset,
@@ -255,14 +259,14 @@ async def list_function_job_collections(
255259

256260
@log_decorator(_logger, level=logging.DEBUG)
257261
async def update_function_title(
258-
rabbitmq_rpc_client: RabbitMQRPCClient,
262+
rpc_client: RabbitMQRPCClient,
259263
*,
260264
user_id: UserID,
261265
product_name: ProductName,
262266
function_id: FunctionID,
263267
title: str,
264268
) -> RegisteredFunction:
265-
result = await rabbitmq_rpc_client.request(
269+
result = await rpc_client.request(
266270
WEBSERVER_RPC_NAMESPACE,
267271
TypeAdapter(RPCMethodName).validate_python("update_function_title"),
268272
function_id=function_id,
@@ -275,14 +279,14 @@ async def update_function_title(
275279

276280
@log_decorator(_logger, level=logging.DEBUG)
277281
async def update_function_description(
278-
rabbitmq_rpc_client: RabbitMQRPCClient,
282+
rpc_client: RabbitMQRPCClient,
279283
*,
280284
user_id: UserID,
281285
product_name: ProductName,
282286
function_id: FunctionID,
283287
description: str,
284288
) -> RegisteredFunction:
285-
result = await rabbitmq_rpc_client.request(
289+
result = await rpc_client.request(
286290
WEBSERVER_RPC_NAMESPACE,
287291
TypeAdapter(RPCMethodName).validate_python("update_function_description"),
288292
function_id=function_id,
@@ -295,14 +299,14 @@ async def update_function_description(
295299

296300
@log_decorator(_logger, level=logging.DEBUG)
297301
async def run_function(
298-
rabbitmq_rpc_client: RabbitMQRPCClient,
302+
rpc_client: RabbitMQRPCClient,
299303
*,
300304
function_id: FunctionID,
301305
inputs: FunctionInputs,
302306
user_id: UserID,
303307
product_name: ProductName,
304308
) -> RegisteredFunctionJob:
305-
result = await rabbitmq_rpc_client.request(
309+
result = await rpc_client.request(
306310
WEBSERVER_RPC_NAMESPACE,
307311
TypeAdapter(RPCMethodName).validate_python("run_function"),
308312
function_id=function_id,
@@ -317,13 +321,13 @@ async def run_function(
317321

318322
@log_decorator(_logger, level=logging.DEBUG)
319323
async def register_function_job(
320-
rabbitmq_rpc_client: RabbitMQRPCClient,
324+
rpc_client: RabbitMQRPCClient,
321325
*,
322326
user_id: UserID,
323327
product_name: ProductName,
324328
function_job: FunctionJob,
325329
) -> RegisteredFunctionJob:
326-
result = await rabbitmq_rpc_client.request(
330+
result = await rpc_client.request(
327331
WEBSERVER_RPC_NAMESPACE,
328332
TypeAdapter(RPCMethodName).validate_python("register_function_job"),
329333
function_job=function_job,
@@ -359,13 +363,13 @@ async def patch_registered_function_job(
359363

360364
@log_decorator(_logger, level=logging.DEBUG)
361365
async def get_function_job(
362-
rabbitmq_rpc_client: RabbitMQRPCClient,
366+
rpc_client: RabbitMQRPCClient,
363367
*,
364368
user_id: UserID,
365369
function_job_id: FunctionJobID,
366370
product_name: ProductName,
367371
) -> RegisteredFunctionJob:
368-
result = await rabbitmq_rpc_client.request(
372+
result = await rpc_client.request(
369373
WEBSERVER_RPC_NAMESPACE,
370374
TypeAdapter(RPCMethodName).validate_python("get_function_job"),
371375
function_job_id=function_job_id,
@@ -458,13 +462,13 @@ async def update_function_job_outputs(
458462

459463
@log_decorator(_logger, level=logging.DEBUG)
460464
async def delete_function_job(
461-
rabbitmq_rpc_client: RabbitMQRPCClient,
465+
rpc_client: RabbitMQRPCClient,
462466
*,
463467
user_id: UserID,
464468
product_name: ProductName,
465469
function_job_id: FunctionJobID,
466470
) -> None:
467-
result: None = await rabbitmq_rpc_client.request(
471+
result: None = await rpc_client.request(
468472
WEBSERVER_RPC_NAMESPACE,
469473
TypeAdapter(RPCMethodName).validate_python("delete_function_job"),
470474
function_job_id=function_job_id,
@@ -476,14 +480,14 @@ async def delete_function_job(
476480

477481
@log_decorator(_logger, level=logging.DEBUG)
478482
async def find_cached_function_jobs(
479-
rabbitmq_rpc_client: RabbitMQRPCClient,
483+
rpc_client: RabbitMQRPCClient,
480484
*,
481485
user_id: UserID,
482486
product_name: ProductName,
483487
function_id: FunctionID,
484488
inputs: FunctionInputs,
485489
) -> list[RegisteredFunctionJob] | None:
486-
result = await rabbitmq_rpc_client.request(
490+
result = await rpc_client.request(
487491
WEBSERVER_RPC_NAMESPACE,
488492
TypeAdapter(RPCMethodName).validate_python("find_cached_function_jobs"),
489493
function_id=function_id,
@@ -498,13 +502,13 @@ async def find_cached_function_jobs(
498502

499503
@log_decorator(_logger, level=logging.DEBUG)
500504
async def register_function_job_collection(
501-
rabbitmq_rpc_client: RabbitMQRPCClient,
505+
rpc_client: RabbitMQRPCClient,
502506
*,
503507
user_id: UserID,
504508
product_name: ProductName,
505509
function_job_collection: FunctionJobCollection,
506510
) -> RegisteredFunctionJobCollection:
507-
result = await rabbitmq_rpc_client.request(
511+
result = await rpc_client.request(
508512
WEBSERVER_RPC_NAMESPACE,
509513
TypeAdapter(RPCMethodName).validate_python("register_function_job_collection"),
510514
function_job_collection=function_job_collection,
@@ -516,13 +520,13 @@ async def register_function_job_collection(
516520

517521
@log_decorator(_logger, level=logging.DEBUG)
518522
async def get_function_job_collection(
519-
rabbitmq_rpc_client: RabbitMQRPCClient,
523+
rpc_client: RabbitMQRPCClient,
520524
*,
521525
user_id: UserID,
522526
function_job_collection_id: FunctionJobCollectionID,
523527
product_name: ProductName,
524528
) -> RegisteredFunctionJobCollection:
525-
result = await rabbitmq_rpc_client.request(
529+
result = await rpc_client.request(
526530
WEBSERVER_RPC_NAMESPACE,
527531
TypeAdapter(RPCMethodName).validate_python("get_function_job_collection"),
528532
function_job_collection_id=function_job_collection_id,
@@ -534,13 +538,13 @@ async def get_function_job_collection(
534538

535539
@log_decorator(_logger, level=logging.DEBUG)
536540
async def delete_function_job_collection(
537-
rabbitmq_rpc_client: RabbitMQRPCClient,
541+
rpc_client: RabbitMQRPCClient,
538542
*,
539543
user_id: UserID,
540544
product_name: ProductName,
541545
function_job_collection_id: FunctionJobCollectionID,
542546
) -> None:
543-
result = await rabbitmq_rpc_client.request(
547+
result = await rpc_client.request(
544548
WEBSERVER_RPC_NAMESPACE,
545549
TypeAdapter(RPCMethodName).validate_python("delete_function_job_collection"),
546550
function_job_collection_id=function_job_collection_id,

0 commit comments

Comments
 (0)