Skip to content

Commit f292ba9

Browse files
committed
Merge branch 'fix/web-server-rpc-namespace' of github.com:pcrespov/osparc-simcore into fix/web-server-rpc-namespace
2 parents 8516e4e + 20be01b commit f292ba9

File tree

8 files changed

+44
-20
lines changed

8 files changed

+44
-20
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@
2828
RegisteredFunctionJobWithStatus,
2929
)
3030
from models_library.products import ProductName
31-
from models_library.rest_ordering import OrderBy
32-
3331
from models_library.rabbitmq_basic_types import RPCMethodName, RPCNamespace
32+
from models_library.rest_ordering import OrderBy
3433
from models_library.rest_pagination import PageMetaInfoLimitOffset
3534
from models_library.users import UserID
3635
from pydantic import TypeAdapter
@@ -201,7 +200,7 @@ async def list_function_jobs(
201200

202201
@log_decorator(_logger, level=logging.DEBUG)
203202
async def list_function_jobs_with_status(
204-
rabbitmq_rpc_client: RabbitMQRPCClient,
203+
rpc_client: RabbitMQRPCClient,
205204
*,
206205
user_id: UserID,
207206
product_name: ProductName,
@@ -214,7 +213,7 @@ async def list_function_jobs_with_status(
214213
list[RegisteredFunctionJobWithStatus],
215214
PageMetaInfoLimitOffset,
216215
]:
217-
result = await rabbitmq_rpc_client.request(
216+
result = await rpc_client.request(
218217
WEBSERVER_RPC_NAMESPACE,
219218
TypeAdapter(RPCMethodName).validate_python("list_function_jobs_with_status"),
220219
user_id=user_id,
@@ -341,14 +340,14 @@ async def register_function_job(
341340

342341
@log_decorator(_logger, level=logging.DEBUG)
343342
async def patch_registered_function_job(
344-
rabbitmq_rpc_client: RabbitMQRPCClient,
343+
rpc_client: RabbitMQRPCClient,
345344
*,
346345
user_id: UserID,
347346
product_name: ProductName,
348347
function_job_uuid: FunctionJobID,
349348
registered_function_job_patch: RegisteredFunctionJobPatch,
350349
) -> RegisteredFunctionJob:
351-
result = await rabbitmq_rpc_client.request(
350+
result = await rpc_client.request(
352351
WEBSERVER_RPC_NAMESPACE,
353352
TypeAdapter(RPCMethodName).validate_python("patch_registered_function_job"),
354353
user_id=user_id,

services/api-server/src/simcore_service_api_server/core/settings.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,15 @@ class ApplicationSettings(BasicSettings):
148148
),
149149
]
150150

151-
API_SERVER_WORKER_MODE: Annotated[
152-
bool, Field(description="If True, the API server runs in worker mode")
153-
] = False
154151
API_SERVER_WEBSERVER_RPC_NAMESPACE: Annotated[
155152
RPCNamespace,
156153
Field(description="Namespace to connect to correct webserver's RPC interface"),
157154
]
158155

156+
API_SERVER_WORKER_MODE: Annotated[
157+
bool, Field(description="If True, the API server runs in worker mode")
158+
] = False
159+
159160
@cached_property
160161
def debug(self) -> bool:
161162
"""If True, debug tracebacks should be returned on errors."""

services/director-v2/src/simcore_service_director_v2/core/settings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ class AppSettings(BaseApplicationSettings, MixinLoggingSettings):
300300
Field(description="Namespace to connect to correct webserver's RPC interface"),
301301
]
302302

303+
DIRECTOR_V2_WEBSERVER_RPC_NAMESPACE: Annotated[
304+
RPCNamespace,
305+
Field(description="Namespace to connect to correct webserver's RPC interface"),
306+
]
307+
303308
@field_validator("LOG_LEVEL", mode="before")
304309
@classmethod
305310
def _validate_loglevel(cls, value: str) -> str:

services/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ services:
522522
PAYMENTS_SWAGGER_API_DOC_ENABLED: ${PAYMENTS_SWAGGER_API_DOC_ENABLED}
523523
PAYMENTS_TRACING: ${PAYMENTS_TRACING}
524524
PAYMENTS_USERNAME: ${PAYMENTS_USERNAME}
525+
PAYMENTS_WEBSERVER_RPC_NAMESPACE: ${WEBSERVER_HOST}
525526
RABBIT_HOST: ${RABBIT_HOST}
526527
RABBIT_PASSWORD: ${RABBIT_PASSWORD}
527528
RABBIT_PORT: ${RABBIT_PORT}

services/web/server/src/simcore_service_webserver/payments/_rpc_invoice.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
from ..products import products_service
1111
from ..products.models import CreditResult
12-
from ..users import users_service
1312
from ..rabbitmq import create_register_rpc_routes_on_startup
13+
from ..users import users_service
1414

1515
router = RPCRouter()
1616

services/web/server/src/simcore_service_webserver/rabbitmq.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from aiohttp import web
66
from models_library.api_schemas_webserver import get_webserver_rpc_namespace
77
from models_library.errors import RABBITMQ_CLIENT_UNHEALTHY_MSG
8+
from models_library.rabbitmq_basic_types import RPCNamespace
89
from servicelib.aiohttp.application_keys import (
910
APP_RABBITMQ_CLIENT_KEY,
1011
APP_RABBITMQ_RPC_SERVER_KEY,
@@ -98,6 +99,13 @@ def get_rabbitmq_rpc_server(app: web.Application) -> RabbitMQRPCClient:
9899
return cast(RabbitMQRPCClient, app[APP_RABBITMQ_RPC_SERVER_KEY])
99100

100101

102+
def get_rpc_namespace(app: web.Application) -> RPCNamespace:
103+
settings = get_application_settings(app)
104+
105+
assert settings.WEBSERVER_HOST # nosec
106+
return get_webserver_rpc_namespace(settings.WEBSERVER_HOST)
107+
108+
101109
def create_register_rpc_routes_on_startup(router: RPCRouter):
102110
"""
103111
This high-order function allows for more flexible router registration
@@ -110,10 +118,7 @@ def create_register_rpc_routes_on_startup(router: RPCRouter):
110118

111119
async def _on_startup(app: web.Application):
112120
rpc_server = get_rabbitmq_rpc_server(app)
113-
settings = get_application_settings(app)
114-
115-
assert settings.WEBSERVER_HOST # nosec
116-
rpc_namespace = get_webserver_rpc_namespace(settings.WEBSERVER_HOST)
121+
rpc_namespace = get_rpc_namespace(app)
117122
await rpc_server.register_router(router, rpc_namespace, app)
118123

119124
return _on_startup

services/web/server/tests/unit/with_dbs/01/test_api_keys_rpc.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from collections.abc import AsyncIterable, Awaitable, Callable
77

88
import pytest
9-
from aiohttp.test_utils import TestServer
9+
from aiohttp.test_utils import TestClient, TestServer
1010
from faker import Faker
1111
from models_library.basic_types import IDStr
1212
from models_library.products import ProductName
@@ -15,7 +15,7 @@
1515
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
1616
from pytest_simcore.helpers.typing_env import EnvVarsDict
1717
from pytest_simcore.helpers.webserver_users import UserInfoDict
18-
from servicelib.rabbitmq import RabbitMQRPCClient
18+
from servicelib.rabbitmq import RabbitMQRPCClient, RPCNamespace
1919
from servicelib.rabbitmq.rpc_interfaces.webserver.auth.api_keys import (
2020
create_api_key,
2121
delete_api_key_by_key,
@@ -27,6 +27,7 @@
2727
from simcore_service_webserver.api_keys.errors import ApiKeyNotFoundError
2828
from simcore_service_webserver.api_keys.models import ApiKey
2929
from simcore_service_webserver.application_settings import ApplicationSettings
30+
from simcore_service_webserver.rabbitmq import get_rpc_namespace
3031

3132
pytest_simcore_core_services_selection = [
3233
"rabbit",
@@ -104,15 +105,23 @@ async def rpc_client(
104105
return await rabbitmq_rpc_client("client")
105106

106107

108+
@pytest.fixture
109+
async def app_rpc_namespace(client: TestClient) -> RPCNamespace:
110+
assert client.app is not None
111+
return get_rpc_namespace(client.app)
112+
113+
107114
async def test_get_api_key(
108115
fake_user_api_keys: list[ApiKey],
109116
rpc_client: RabbitMQRPCClient,
110117
osparc_product_name: ProductName,
111118
logged_user: UserInfoDict,
119+
app_rpc_namespace: RPCNamespace,
112120
):
113121
for api_key in fake_user_api_keys:
114122
result = await get_api_key(
115123
rpc_client,
124+
app_rpc_namespace,
116125
user_id=logged_user["id"],
117126
product_name=osparc_product_name,
118127
api_key_id=IDStr(api_key.id),
@@ -121,17 +130,18 @@ async def test_get_api_key(
121130

122131

123132
async def test_api_keys_workflow(
124-
web_server: TestServer,
125133
rpc_client: RabbitMQRPCClient,
126134
osparc_product_name: ProductName,
127135
logged_user: UserInfoDict,
136+
app_rpc_namespace: RPCNamespace,
128137
faker: Faker,
129138
):
130139
key_name = faker.pystr()
131140

132141
# creating a key
133142
created_api_key = await create_api_key(
134143
rpc_client,
144+
app_rpc_namespace,
135145
user_id=logged_user["id"],
136146
product_name=osparc_product_name,
137147
api_key=ApiKeyCreate(display_name=key_name, expiration=None),
@@ -141,6 +151,7 @@ async def test_api_keys_workflow(
141151
# query the key is still present
142152
queried_api_key = await get_api_key(
143153
rpc_client,
154+
app_rpc_namespace,
144155
product_name=osparc_product_name,
145156
user_id=logged_user["id"],
146157
api_key_id=created_api_key.id,
@@ -155,6 +166,7 @@ async def test_api_keys_workflow(
155166
# remove the key
156167
await delete_api_key_by_key(
157168
rpc_client,
169+
app_rpc_namespace,
158170
user_id=logged_user["id"],
159171
product_name=osparc_product_name,
160172
api_key=created_api_key.api_key,
@@ -164,6 +176,7 @@ async def test_api_keys_workflow(
164176
# key no longer present
165177
await get_api_key(
166178
rpc_client,
179+
app_rpc_namespace,
167180
product_name=osparc_product_name,
168181
user_id=logged_user["id"],
169182
api_key_id=created_api_key.id,

services/web/server/tests/unit/with_dbs/04/functions/test_function_jobs_controller_rpc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ async def test_list_function_jobs_with_status(
266266

267267
# List function jobs
268268
jobs, _ = await functions_rpc.list_function_jobs_with_status(
269-
rabbitmq_rpc_client=rpc_client,
269+
rpc_client=rpc_client,
270270
pagination_limit=10,
271271
pagination_offset=0,
272272
user_id=logged_user["id"],
@@ -574,7 +574,7 @@ async def test_patch_registered_function_jobs(
574574
)
575575

576576
registered_job = await functions_rpc.patch_registered_function_job(
577-
rabbitmq_rpc_client=rpc_client,
577+
rpc_client=rpc_client,
578578
user_id=logged_user["id"],
579579
function_job_uuid=registered_job.uid,
580580
product_name=osparc_product_name,
@@ -651,7 +651,7 @@ async def test_incompatible_patch_model_error(
651651
)
652652
with pytest.raises(FunctionJobPatchModelIncompatibleError):
653653
registered_job = await functions_rpc.patch_registered_function_job(
654-
rabbitmq_rpc_client=rpc_client,
654+
rpc_client=rpc_client,
655655
user_id=logged_user["id"],
656656
function_job_uuid=registered_job.uid,
657657
product_name=osparc_product_name,

0 commit comments

Comments
 (0)