Skip to content

Commit 4bc0815

Browse files
committed
request options
1 parent 7101ab5 commit 4bc0815

File tree

1 file changed

+26
-6
lines changed
  • packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/webserver/v1

1 file changed

+26
-6
lines changed

packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/webserver/v1/_base.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,49 @@
1111
class BaseRpcApi:
1212
"""Base class for all RPC API subclients."""
1313

14-
def __init__(self, rpc_client: RabbitMQRPCClient, namespace: RPCNamespace):
14+
def __init__(
15+
self,
16+
rpc_client: RabbitMQRPCClient,
17+
namespace: RPCNamespace,
18+
rpc_request_kwargs: dict[str, Any] | None = None,
19+
):
1520
self._rpc_client = rpc_client
1621
self._namespace = namespace
22+
self._rpc_request_kwargs = rpc_request_kwargs or {}
1723

1824
async def _request(
1925
self,
2026
method_name: RPCMethodName,
2127
*,
2228
product_name: ProductName,
2329
user_id: UserID,
24-
**kwargs: Any
30+
**optional_kwargs: Any
2531
) -> Any:
26-
return await self._rpc_client.request(
27-
self._namespace,
32+
assert self._rpc_request_kwargs.keys().isdisjoint(optional_kwargs.keys()), (
33+
"Conflict between request extras and kwargs"
34+
"Please rename the conflicting keys."
35+
)
36+
37+
return await self._request_without_authentication(
2838
method_name,
2939
product_name=product_name,
3040
user_id=user_id,
31-
**kwargs
41+
**optional_kwargs,
42+
**self._rpc_request_kwargs,
3243
)
3344

3445
async def _request_without_authentication(
3546
self, method_name: RPCMethodName, *, product_name: ProductName, **kwargs: Any
3647
) -> Any:
48+
assert self._rpc_request_kwargs.keys().isdisjoint(kwargs.keys()), (
49+
"Conflict between request extras and kwargs"
50+
"Please rename the conflicting keys."
51+
)
52+
3753
return await self._rpc_client.request(
38-
self._namespace, method_name, product_name=product_name, **kwargs
54+
self._namespace,
55+
method_name,
56+
product_name=product_name,
57+
**kwargs,
58+
**self._rpc_request_kwargs,
3959
)

0 commit comments

Comments
 (0)