Skip to content

Commit 878cc43

Browse files
move
1 parent 16f5c93 commit 878cc43

File tree

4 files changed

+27
-28
lines changed
  • packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/webserver
  • services

4 files changed

+27
-28
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212

1313

1414
@log_decorator(_logger, level=logging.DEBUG)
15-
async def get_product_base_url(
15+
async def get_product_api_base_url(
1616
rpc_client: RabbitMQRPCClient,
1717
*,
1818
product_name: ProductName,
1919
) -> str:
2020

2121
resp = await rpc_client.request(
2222
WEBSERVER_RPC_NAMESPACE,
23-
TypeAdapter(RPCMethodName).validate_python("get_product_base_url"),
23+
TypeAdapter(RPCMethodName).validate_python("get_product_api_base_url"),
2424
product_name=product_name,
2525
)
2626
assert resp # nosec

services/director-v2/src/simcore_service_director_v2/modules/osparc_variables/substitutions.py

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import logging
55
from copy import deepcopy
66
from typing import Any, Final, TypeVar
7-
from urllib.parse import urlparse, urlunparse
87

98
from fastapi import FastAPI
109
from models_library.osparc_variable_identifier import (
@@ -24,7 +23,9 @@
2423
from pydantic import BaseModel
2524
from servicelib.fastapi.app_state import SingletonInAppStateMixin
2625
from servicelib.logging_utils import log_context
27-
from servicelib.rabbitmq.rpc_interfaces.webserver.products import get_product_base_url
26+
from servicelib.rabbitmq.rpc_interfaces.webserver.products import (
27+
get_product_api_base_url,
28+
)
2829

2930
from ...modules.rabbitmq import get_rabbitmq_rpc_client
3031
from ...utils.db import get_repository
@@ -42,16 +43,6 @@
4243
TBaseModel = TypeVar("TBaseModel", bound=BaseModel)
4344

4445

45-
def _make_api_server_base_url(base_url: str):
46-
parsed = urlparse(base_url)
47-
hostname = parsed.hostname or ""
48-
49-
if not hostname.startswith("api."):
50-
hostname = f"api.{hostname}"
51-
52-
return urlunparse((parsed.scheme, hostname, "", "", "", ""))
53-
54-
5546
async def substitute_vendor_secrets_in_model(
5647
app: FastAPI,
5748
model: TBaseModel,
@@ -217,11 +208,9 @@ async def resolve_and_substitute_session_variables_in_model(
217208
node_id=node_id,
218209
run_id=service_run_id,
219210
wallet_id=wallet_id,
220-
api_server_base_url=_make_api_server_base_url(
221-
await get_product_base_url(
222-
get_rabbitmq_rpc_client(app),
223-
product_name=product_name,
224-
),
211+
api_server_base_url=await get_product_api_base_url(
212+
get_rabbitmq_rpc_client(app),
213+
product_name=product_name,
225214
),
226215
),
227216
)
@@ -267,11 +256,9 @@ async def resolve_and_substitute_session_variables_in_specs(
267256
node_id=node_id,
268257
run_id=service_run_id,
269258
wallet_id=wallet_id,
270-
api_server_base_url=_make_api_server_base_url(
271-
await get_product_base_url(
272-
get_rabbitmq_rpc_client(app),
273-
product_name=product_name,
274-
),
259+
api_server_base_url=await get_product_api_base_url(
260+
get_rabbitmq_rpc_client(app),
261+
product_name=product_name,
275262
),
276263
),
277264
)

services/web/server/src/simcore_service_webserver/products/_controller/rpc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ async def get_credit_amount(
3030

3131

3232
@router.expose()
33-
async def get_product_base_url(
33+
async def get_product_api_base_url(
3434
app: web.Application,
3535
*,
3636
product_name: ProductName,
3737
) -> str:
38-
return await _service.get_product_base_url(app, product_name=product_name)
38+
return await _service.get_product_api_base_url(app, product_name=product_name)
3939

4040

4141
async def _register_rpc_routes_on_startup(app: web.Application):

services/web/server/src/simcore_service_webserver/products/_service.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from decimal import Decimal
22
from typing import Any
3+
from urllib.parse import urlparse, urlunparse
34

45
from aiohttp import web
56
from models_library.groups import GroupID
@@ -22,6 +23,16 @@
2223
from .models import Product
2324

2425

26+
def _make_api_server_base_url(base_url: str):
27+
parsed = urlparse(base_url)
28+
hostname = parsed.hostname or ""
29+
30+
if not hostname.startswith("api."):
31+
hostname = f"api.{hostname}"
32+
33+
return urlunparse((parsed.scheme, hostname, "", "", "", ""))
34+
35+
2536
async def load_products(app: web.Application) -> list[Product]:
2637
repo = ProductRepository.create_from_app(app)
2738
try:
@@ -137,12 +148,13 @@ async def get_template_content(app: web.Application, *, template_name: str):
137148
return content
138149

139150

140-
async def get_product_base_url(app: web.Application, *, product_name) -> str:
151+
async def get_product_api_base_url(app: web.Application, *, product_name) -> str:
141152
repo = ProductRepository.create_from_app(app)
142153
base_url = await repo.get_product_base_url(product_name)
143154
if not base_url:
144155
raise ProductBaseUrlNotFoundError(product_name=product_name)
145-
return base_url
156+
157+
return _make_api_server_base_url(base_url)
146158

147159

148160
async def auto_create_products_groups(

0 commit comments

Comments
 (0)