Skip to content

Commit f909d18

Browse files
use base_url
1 parent f863ee1 commit f909d18

File tree

11 files changed

+99
-54
lines changed

11 files changed

+99
-54
lines changed

packages/models-library/src/models_library/api_schemas_webserver/products.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ def _update_json_schema_extra(schema: JsonDict) -> None:
8989
)
9090

9191

92-
class ProductHostRpcGet(BaseModel):
92+
class ProductBaseUrlRpcGet(BaseModel):
9393
product_name: ProductName
94-
host: str
94+
base_url: str
9595

9696
@staticmethod
9797
def _update_json_schema_extra(schema: JsonDict) -> None:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""Add base_url column to products
2+
3+
Revision ID: 972981ff823a
4+
Revises: 0d52976dc616
5+
Create Date: 2025-05-06 11:28:58.402681+00:00
6+
7+
"""
8+
9+
import sqlalchemy as sa
10+
from alembic import op
11+
12+
# revision identifiers, used by Alembic.
13+
revision = "972981ff823a"
14+
down_revision = "0d52976dc616"
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.add_column(
22+
"products",
23+
sa.Column(
24+
"base_url", sa.String(), server_default="https://osparc.io", nullable=True
25+
),
26+
)
27+
# ### end Alembic commands ###
28+
29+
30+
def downgrade():
31+
# ### commands auto generated by Alembic - please adjust! ###
32+
op.drop_column("products", "base_url")
33+
# ### end Alembic commands ###

packages/postgres-database/src/simcore_postgres_database/migration/versions/fc621eedc163_add_host_column.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

packages/postgres-database/src/simcore_postgres_database/models/products.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ class ProductLoginSettingsDict(TypedDict, total=False):
155155
doc="Regular expression that matches product hostname from an url string",
156156
),
157157
sa.Column(
158-
"host",
158+
"base_url",
159159
sa.String,
160-
server_default="osparc.io",
161-
doc="Product hostname",
160+
server_default="https://osparc.io",
161+
doc="Base URL of the product.",
162162
),
163163
# EMAILS --------------------
164164
sa.Column(
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import logging
2+
3+
from models_library.api_schemas_webserver import WEBSERVER_RPC_NAMESPACE
4+
from models_library.products import ProductName
5+
from models_library.rabbitmq_basic_types import RPCMethodName
6+
from pydantic import TypeAdapter
7+
8+
from ....logging_utils import log_decorator
9+
from ..._client_rpc import RabbitMQRPCClient
10+
11+
_logger = logging.getLogger(__name__)
12+
13+
14+
@log_decorator(_logger, level=logging.DEBUG)
15+
async def get_product_base_url(
16+
rpc_client: RabbitMQRPCClient,
17+
*,
18+
product_name: ProductName,
19+
) -> None:
20+
21+
base_url = await rpc_client.request(
22+
WEBSERVER_RPC_NAMESPACE,
23+
TypeAdapter(RPCMethodName).validate_python("get_product_base_url"),
24+
product_name=product_name,
25+
)
26+
assert base_url # nosec
27+
return base_url

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
from pydantic import BaseModel
2424
from servicelib.fastapi.app_state import SingletonInAppStateMixin
2525
from servicelib.logging_utils import log_context
26-
from simcore_service_director_v2.core.settings import get_application_settings
26+
from servicelib.rabbitmq.rpc_interfaces.webserver.products import get_product_host
2727

28+
from ...core.settings import get_application_settings
29+
from ...modules.rabbitmq import get_rabbitmq_rpc_client
2830
from ...utils.db import get_repository
2931
from ...utils.osparc_variables import (
3032
ContextDict,
@@ -40,6 +42,10 @@
4042
TBaseModel = TypeVar("TBaseModel", bound=BaseModel)
4143

4244

45+
def _make_api_server_base_url(base_url: str):
46+
pass
47+
48+
4349
async def substitute_vendor_secrets_in_model(
4450
app: FastAPI,
4551
model: TBaseModel,
@@ -194,7 +200,7 @@ async def resolve_and_substitute_session_variables_in_model(
194200
# if it raises an error vars need replacement
195201
raise_if_unresolved_osparc_variable_identifier_found(model)
196202
except UnresolvedOsparcVariableIdentifierError:
197-
app_settings = get_application_settings(app)
203+
api_server_base_url = get_application_settings(app)
198204
table = OsparcSessionVariablesTable.get_from_app_state(app)
199205
identifiers = await resolve_variables_from_context(
200206
table.copy(),
@@ -206,7 +212,10 @@ async def resolve_and_substitute_session_variables_in_model(
206212
node_id=node_id,
207213
run_id=service_run_id,
208214
wallet_id=wallet_id,
209-
api_server_base_url=app_settings.DIRECTOR_V2_PUBLIC_API_BASE_URL,
215+
api_server_base_url=get_product_host(
216+
get_rabbitmq_rpc_client(app),
217+
product_name=product_name,
218+
),
210219
),
211220
)
212221
_logger.debug("replacing with the identifiers=%s", identifiers)
@@ -241,7 +250,6 @@ async def resolve_and_substitute_session_variables_in_specs(
241250
identifiers_to_replace,
242251
)
243252
if identifiers_to_replace:
244-
app_settings = get_application_settings(app)
245253
environs = await resolve_variables_from_context(
246254
table.copy(include=identifiers_to_replace),
247255
context=ContextDict(
@@ -252,7 +260,10 @@ async def resolve_and_substitute_session_variables_in_specs(
252260
node_id=node_id,
253261
run_id=service_run_id,
254262
wallet_id=wallet_id,
255-
api_server_base_url=app_settings.DIRECTOR_V2_PUBLIC_API_BASE_URL,
263+
api_server_base_url=get_product_host(
264+
get_rabbitmq_rpc_client(app),
265+
product_name=product_name,
266+
),
256267
),
257268
)
258269

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from models_library.api_schemas_webserver import WEBSERVER_RPC_NAMESPACE
55
from models_library.api_schemas_webserver.products import (
66
CreditResultRpcGet,
7-
ProductHostRpcGet,
7+
ProductBaseUrlRpcGet,
88
)
99
from models_library.products import ProductName
1010
from servicelib.rabbitmq import RPCRouter
@@ -31,13 +31,13 @@ async def get_credit_amount(
3131

3232

3333
@router.expose()
34-
async def get_product_host(
34+
async def get_product_base_url(
3535
app: web.Application,
3636
*,
3737
product_name: ProductName,
38-
) -> ProductHostRpcGet:
39-
host: str = await _service.get_product_host(app, product_name=product_name)
40-
return ProductHostRpcGet(product_name=product_name, host=host)
38+
) -> ProductBaseUrlRpcGet:
39+
base_url: str = await _service.get_product_base_url(app, product_name=product_name)
40+
return ProductBaseUrlRpcGet(product_name=product_name, base_url=base_url)
4141

4242

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

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from models_library.products import ProductName, StripePriceID, StripeTaxRateID
1515
from models_library.utils.change_case import snake_to_camel
1616
from pydantic import (
17+
AnyHttpUrl,
1718
BaseModel,
1819
BeforeValidator,
1920
ConfigDict,
@@ -87,7 +88,7 @@ class Product(BaseModel):
8788
re.Pattern, BeforeValidator(str.strip), Field(..., description="Host regex")
8889
]
8990

90-
host: Annotated[str, BeforeValidator(str.strip), Field(..., description="Host")]
91+
base_url: Annotated[AnyHttpUrl, Field(..., description="Base URL of the product")]
9192

9293
support_email: Annotated[
9394
LowerCaseEmailStr,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
products.c.display_name,
4343
products.c.short_name,
4444
products.c.host_regex,
45-
products.c.host,
45+
products.c.base_url,
4646
products.c.support_email,
4747
products.c.product_owners_email,
4848
products.c.twilio_messaging_sid,
@@ -216,15 +216,15 @@ async def get_product_ui(
216216
row = result.one_or_none()
217217
return dict(**row.ui) if row else None
218218

219-
async def get_product_host(
219+
async def get_product_base_url(
220220
self, product_name: ProductName, connection: AsyncConnection | None = None
221221
) -> str | None:
222-
query = sa.select(products.c.host).where(products.c.name == product_name)
222+
query = sa.select(products.c.base_url).where(products.c.name == product_name)
223223

224224
async with pass_or_acquire_connection(self.engine, connection) as conn:
225225
result = await conn.execute(query)
226226
row = result.one_or_none()
227-
return f"{row.host}" if row else None
227+
return f"{row.base_url}" if row else None
228228

229229
async def auto_create_products_groups(
230230
self,

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from .errors import (
1515
BelowMinimumPaymentError,
1616
MissingStripeConfigError,
17-
ProductHostNotFoundError,
17+
ProductBaseUrlNotFoundError,
1818
ProductNotFoundError,
1919
ProductPriceNotDefinedError,
2020
ProductTemplateNotFoundError,
@@ -137,12 +137,12 @@ async def get_template_content(app: web.Application, *, template_name: str):
137137
return content
138138

139139

140-
async def get_product_host(app: web.Application, *, product_name) -> str:
140+
async def get_product_base_url(app: web.Application, *, product_name) -> str:
141141
repo = ProductRepository.create_from_app(app)
142-
host = await repo.get_product_host(product_name)
143-
if not host:
144-
raise ProductHostNotFoundError(product_name=product_name)
145-
return host
142+
base_url = await repo.get_product_base_url(product_name)
143+
if not base_url:
144+
raise ProductBaseUrlNotFoundError(product_name=product_name)
145+
return base_url
146146

147147

148148
async def auto_create_products_groups(

0 commit comments

Comments
 (0)