From d563de7027f17c1ae50ea1a4772227c2aa8acae6 Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Tue, 28 Jan 2025 11:56:07 +0100 Subject: [PATCH 1/4] moving --- api/specs/web-server/_licensed_items.py | 6 ++++-- api/specs/web-server/_licensed_items_checkouts.py | 4 +++- api/specs/web-server/_licensed_items_purchases.py | 6 ++++-- .../simcore_service_webserver/licenses/_common/__init__.py | 0 .../exceptions_handlers.py} | 6 +++--- .../licenses/{_models.py => _common/models.py} | 2 +- .../licenses/_licensed_items_checkouts_rest.py | 4 ++-- .../licenses/_licensed_items_purchases_rest.py | 4 ++-- .../licenses/_licensed_items_rest.py | 4 ++-- .../licenses/_licensed_items_service.py | 2 +- 10 files changed, 22 insertions(+), 16 deletions(-) create mode 100644 services/web/server/src/simcore_service_webserver/licenses/_common/__init__.py rename services/web/server/src/simcore_service_webserver/licenses/{_exceptions_handlers.py => _common/exceptions_handlers.py} (86%) rename services/web/server/src/simcore_service_webserver/licenses/{_models.py => _common/models.py} (98%) diff --git a/api/specs/web-server/_licensed_items.py b/api/specs/web-server/_licensed_items.py index 377d6b9ab94b..02cf5f907858 100644 --- a/api/specs/web-server/_licensed_items.py +++ b/api/specs/web-server/_licensed_items.py @@ -14,8 +14,10 @@ from models_library.generics import Envelope from models_library.rest_error import EnvelopedError from simcore_service_webserver._meta import API_VTAG -from simcore_service_webserver.licenses._exceptions_handlers import _TO_HTTP_ERROR_MAP -from simcore_service_webserver.licenses._models import ( +from simcore_service_webserver.licenses._common.exceptions_handlers import ( + _TO_HTTP_ERROR_MAP, +) +from simcore_service_webserver.licenses._common.models import ( LicensedItemsBodyParams, LicensedItemsListQueryParams, LicensedItemsPathParams, diff --git a/api/specs/web-server/_licensed_items_checkouts.py b/api/specs/web-server/_licensed_items_checkouts.py index cfc51a7c4240..85ebe8073db0 100644 --- a/api/specs/web-server/_licensed_items_checkouts.py +++ b/api/specs/web-server/_licensed_items_checkouts.py @@ -17,7 +17,9 @@ from models_library.rest_error import EnvelopedError from models_library.rest_pagination import Page from simcore_service_webserver._meta import API_VTAG -from simcore_service_webserver.licenses._exceptions_handlers import _TO_HTTP_ERROR_MAP +from simcore_service_webserver.licenses._common.exceptions_handlers import ( + _TO_HTTP_ERROR_MAP, +) from simcore_service_webserver.licenses._licensed_items_checkouts_models import ( LicensedItemCheckoutPathParams, LicensedItemsCheckoutsListQueryParams, diff --git a/api/specs/web-server/_licensed_items_purchases.py b/api/specs/web-server/_licensed_items_purchases.py index 8a993cef6884..7283f424df93 100644 --- a/api/specs/web-server/_licensed_items_purchases.py +++ b/api/specs/web-server/_licensed_items_purchases.py @@ -17,8 +17,10 @@ from models_library.rest_error import EnvelopedError from models_library.rest_pagination import Page from simcore_service_webserver._meta import API_VTAG -from simcore_service_webserver.licenses._exceptions_handlers import _TO_HTTP_ERROR_MAP -from simcore_service_webserver.licenses._models import ( +from simcore_service_webserver.licenses._common.exceptions_handlers import ( + _TO_HTTP_ERROR_MAP, +) +from simcore_service_webserver.licenses._common.models import ( LicensedItemsPurchasesListQueryParams, LicensedItemsPurchasesPathParams, ) diff --git a/services/web/server/src/simcore_service_webserver/licenses/_common/__init__.py b/services/web/server/src/simcore_service_webserver/licenses/_common/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/services/web/server/src/simcore_service_webserver/licenses/_exceptions_handlers.py b/services/web/server/src/simcore_service_webserver/licenses/_common/exceptions_handlers.py similarity index 86% rename from services/web/server/src/simcore_service_webserver/licenses/_exceptions_handlers.py rename to services/web/server/src/simcore_service_webserver/licenses/_common/exceptions_handlers.py index 26cf9478b5fa..6c7d1255ca55 100644 --- a/services/web/server/src/simcore_service_webserver/licenses/_exceptions_handlers.py +++ b/services/web/server/src/simcore_service_webserver/licenses/_common/exceptions_handlers.py @@ -3,14 +3,14 @@ from servicelib.aiohttp import status from simcore_service_webserver.wallets.errors import WalletAccessForbiddenError -from ..exception_handling import ( +from ...exception_handling import ( ExceptionToHttpErrorMap, HttpErrorInfo, exception_handling_decorator, to_exceptions_handlers_map, ) -from ..wallets.errors import WalletNotEnoughCreditsError -from .errors import LicensedItemNotFoundError, LicensedItemPricingPlanMatchError +from ...wallets.errors import WalletNotEnoughCreditsError +from ..errors import LicensedItemNotFoundError, LicensedItemPricingPlanMatchError _logger = logging.getLogger(__name__) diff --git a/services/web/server/src/simcore_service_webserver/licenses/_models.py b/services/web/server/src/simcore_service_webserver/licenses/_common/models.py similarity index 98% rename from services/web/server/src/simcore_service_webserver/licenses/_models.py rename to services/web/server/src/simcore_service_webserver/licenses/_common/models.py index d5c2ac0947e5..5eedd039e5c6 100644 --- a/services/web/server/src/simcore_service_webserver/licenses/_models.py +++ b/services/web/server/src/simcore_service_webserver/licenses/_common/models.py @@ -18,7 +18,7 @@ from pydantic import BaseModel, ConfigDict, Field from servicelib.request_keys import RQT_USERID_KEY -from .._constants import RQ_PRODUCT_KEY +from ..._constants import RQ_PRODUCT_KEY _logger = logging.getLogger(__name__) diff --git a/services/web/server/src/simcore_service_webserver/licenses/_licensed_items_checkouts_rest.py b/services/web/server/src/simcore_service_webserver/licenses/_licensed_items_checkouts_rest.py index 0bcdbe9636cd..62970b0212a0 100644 --- a/services/web/server/src/simcore_service_webserver/licenses/_licensed_items_checkouts_rest.py +++ b/services/web/server/src/simcore_service_webserver/licenses/_licensed_items_checkouts_rest.py @@ -21,14 +21,14 @@ from ..utils_aiohttp import envelope_json_response from ..wallets._handlers import WalletsPathParams from . import _licensed_items_checkouts_service -from ._exceptions_handlers import handle_plugin_requests_exceptions +from ._common.exceptions_handlers import handle_plugin_requests_exceptions +from ._common.models import LicensedItemsRequestContext from ._licensed_items_checkouts_models import ( LicensedItemCheckoutGet, LicensedItemCheckoutGetPage, LicensedItemCheckoutPathParams, LicensedItemsCheckoutsListQueryParams, ) -from ._models import LicensedItemsRequestContext _logger = logging.getLogger(__name__) diff --git a/services/web/server/src/simcore_service_webserver/licenses/_licensed_items_purchases_rest.py b/services/web/server/src/simcore_service_webserver/licenses/_licensed_items_purchases_rest.py index 5ae0738ebe16..53c978837f75 100644 --- a/services/web/server/src/simcore_service_webserver/licenses/_licensed_items_purchases_rest.py +++ b/services/web/server/src/simcore_service_webserver/licenses/_licensed_items_purchases_rest.py @@ -21,8 +21,8 @@ from ..utils_aiohttp import envelope_json_response from ..wallets._handlers import WalletsPathParams from . import _licensed_items_purchases_service -from ._exceptions_handlers import handle_plugin_requests_exceptions -from ._models import ( +from ._common.exceptions_handlers import handle_plugin_requests_exceptions +from ._common.models import ( LicensedItemsPurchasesListQueryParams, LicensedItemsPurchasesPathParams, LicensedItemsRequestContext, diff --git a/services/web/server/src/simcore_service_webserver/licenses/_licensed_items_rest.py b/services/web/server/src/simcore_service_webserver/licenses/_licensed_items_rest.py index 4f0a936c041e..ae45f5aba5ed 100644 --- a/services/web/server/src/simcore_service_webserver/licenses/_licensed_items_rest.py +++ b/services/web/server/src/simcore_service_webserver/licenses/_licensed_items_rest.py @@ -22,8 +22,8 @@ from ..security.decorators import permission_required from ..utils_aiohttp import envelope_json_response from . import _licensed_items_service -from ._exceptions_handlers import handle_plugin_requests_exceptions -from ._models import ( +from ._common.exceptions_handlers import handle_plugin_requests_exceptions +from ._common.models import ( LicensedItemsBodyParams, LicensedItemsListQueryParams, LicensedItemsPathParams, diff --git a/services/web/server/src/simcore_service_webserver/licenses/_licensed_items_service.py b/services/web/server/src/simcore_service_webserver/licenses/_licensed_items_service.py index 374da33bbbef..c7e4a61b3b13 100644 --- a/services/web/server/src/simcore_service_webserver/licenses/_licensed_items_service.py +++ b/services/web/server/src/simcore_service_webserver/licenses/_licensed_items_service.py @@ -26,7 +26,7 @@ from ..wallets.api import get_wallet_with_available_credits_by_user_and_wallet from ..wallets.errors import WalletNotEnoughCreditsError from . import _licensed_items_repository -from ._models import LicensedItemsBodyParams +from ._common.models import LicensedItemsBodyParams from .errors import LicensedItemPricingPlanMatchError _logger = logging.getLogger(__name__) From 423fcf321be13fc7c006c460bfb7d251b925d682 Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Tue, 28 Jan 2025 12:18:00 +0100 Subject: [PATCH 2/4] expose to public config --- .../simcore_service_webserver/application_settings.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/services/web/server/src/simcore_service_webserver/application_settings.py b/services/web/server/src/simcore_service_webserver/application_settings.py index 8570a79ad2ff..3b74b8a9db39 100644 --- a/services/web/server/src/simcore_service_webserver/application_settings.py +++ b/services/web/server/src/simcore_service_webserver/application_settings.py @@ -384,6 +384,7 @@ def _get_disabled_public_plugins(self) -> list[str]: public_plugin_candidates: Final = { "WEBSERVER_EXPORTER", "WEBSERVER_FOLDERS", + "WEBSERVER_LICENSES", "WEBSERVER_META_MODELING", "WEBSERVER_PAYMENTS", "WEBSERVER_SCICRUNCH", @@ -451,16 +452,17 @@ def to_client_statics(self) -> dict[str, Any]: "SIMCORE_VCS_RELEASE_TAG": True, "SIMCORE_VCS_RELEASE_URL": True, "SWARM_STACK_NAME": True, + "WEBSERVER_LICENSES": True, + "WEBSERVER_LOGIN": { + "LOGIN_ACCOUNT_DELETION_RETENTION_DAYS", + "LOGIN_2FA_REQUIRED", + }, "WEBSERVER_PROJECTS": { "PROJECTS_MAX_NUM_RUNNING_DYNAMIC_NODES", }, "WEBSERVER_TRASH": { "TRASH_RETENTION_DAYS", }, - "WEBSERVER_LOGIN": { - "LOGIN_ACCOUNT_DELETION_RETENTION_DAYS", - "LOGIN_2FA_REQUIRED", - }, "WEBSERVER_SESSION": {"SESSION_COOKIE_MAX_AGE"}, }, exclude_none=True, From b0aada46196f3a68fd3814cc515171e975f86783 Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Tue, 28 Jan 2025 13:58:45 +0100 Subject: [PATCH 3/4] adds env --- .env-devel | 1 + services/docker-compose.yml | 4 ++++ .../src/simcore_service_webserver/application_settings.py | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.env-devel b/.env-devel index 26fb29a093a7..e2f8baef3ca7 100644 --- a/.env-devel +++ b/.env-devel @@ -371,6 +371,7 @@ WEBSERVER_GARBAGE_COLLECTOR=null WEBSERVER_GROUPS=1 WEBSERVER_GUNICORN_CMD_ARGS=--timeout=180 WEBSERVER_HOST=webserver +WEBSERVER_LICENSES=true WEBSERVER_LOGIN={} WEBSERVER_LOGLEVEL=INFO WEBSERVER_META_MODELING=1 diff --git a/services/docker-compose.yml b/services/docker-compose.yml index 1fae14e81d34..b900c931e441 100644 --- a/services/docker-compose.yml +++ b/services/docker-compose.yml @@ -704,6 +704,8 @@ services: INVITATIONS_SECRET_KEY: ${INVITATIONS_SECRET_KEY} INVITATIONS_USERNAME: ${INVITATIONS_USERNAME} + WEBSERVER_LICENSES: ${WEBSERVER_LICENSES} + WEBSERVER_LOGIN: ${WEBSERVER_LOGIN} LOGIN_ACCOUNT_DELETION_RETENTION_DAYS: ${LOGIN_ACCOUNT_DELETION_RETENTION_DAYS} LOGIN_REGISTRATION_CONFIRMATION_REQUIRED: ${LOGIN_REGISTRATION_CONFIRMATION_REQUIRED} @@ -897,6 +899,7 @@ services: WEBSERVER_GARBAGE_COLLECTOR: ${WB_DB_EL_GARBAGE_COLLECTOR} WEBSERVER_GROUPS: ${WB_DB_EL_GROUPS} WEBSERVER_INVITATIONS: ${WB_DB_EL_INVITATIONS} + WEBSERVER_LICENSES: 0 WEBSERVER_LOGIN: ${WB_DB_EL_LOGIN} WEBSERVER_PAYMENTS: ${WB_DB_EL_PAYMENTS} WEBSERVER_META_MODELING: ${WB_DB_EL_META_MODELING} @@ -1000,6 +1003,7 @@ services: WEBSERVER_FRONTEND: ${WB_GC_FRONTEND} WEBSERVER_GROUPS: ${WB_GC_GROUPS} WEBSERVER_INVITATIONS: ${WB_GC_INVITATIONS} + WEBSERVER_LICENSES: 0 WEBSERVER_LOGIN: ${WB_GC_LOGIN} WEBSERVER_META_MODELING: ${WB_GC_META_MODELING} WEBSERVER_NOTIFICATIONS: ${WB_GC_NOTIFICATIONS} diff --git a/services/web/server/src/simcore_service_webserver/application_settings.py b/services/web/server/src/simcore_service_webserver/application_settings.py index 3b74b8a9db39..1fc70271a6b1 100644 --- a/services/web/server/src/simcore_service_webserver/application_settings.py +++ b/services/web/server/src/simcore_service_webserver/application_settings.py @@ -283,7 +283,7 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings): WEBSERVER_DB_LISTENER: bool = True WEBSERVER_FOLDERS: bool = True WEBSERVER_GROUPS: bool = True - WEBSERVER_LICENSES: bool = True + WEBSERVER_LICENSES: bool WEBSERVER_META_MODELING: bool = True WEBSERVER_NOTIFICATIONS: bool = Field(default=True) WEBSERVER_PRODUCTS: bool = True From b37c40b80a828385150813f5dc6fbab5ef6c685c Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Tue, 28 Jan 2025 14:30:42 +0100 Subject: [PATCH 4/4] cleanup --- .../src/simcore_service_webserver/application_settings.py | 2 +- .../server/src/simcore_service_webserver/licenses/plugin.py | 3 ++- .../server/tests/unit/isolated/test_application_settings.py | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/services/web/server/src/simcore_service_webserver/application_settings.py b/services/web/server/src/simcore_service_webserver/application_settings.py index 1fc70271a6b1..c3f4e2ed7aec 100644 --- a/services/web/server/src/simcore_service_webserver/application_settings.py +++ b/services/web/server/src/simcore_service_webserver/application_settings.py @@ -283,7 +283,7 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings): WEBSERVER_DB_LISTENER: bool = True WEBSERVER_FOLDERS: bool = True WEBSERVER_GROUPS: bool = True - WEBSERVER_LICENSES: bool + WEBSERVER_LICENSES: bool = False WEBSERVER_META_MODELING: bool = True WEBSERVER_NOTIFICATIONS: bool = Field(default=True) WEBSERVER_PRODUCTS: bool = True diff --git a/services/web/server/src/simcore_service_webserver/licenses/plugin.py b/services/web/server/src/simcore_service_webserver/licenses/plugin.py index 72af99badeb1..859a52bf1bdd 100644 --- a/services/web/server/src/simcore_service_webserver/licenses/plugin.py +++ b/services/web/server/src/simcore_service_webserver/licenses/plugin.py @@ -8,6 +8,7 @@ from servicelib.aiohttp.application_setup import ModuleCategory, app_module_setup from ..rabbitmq import setup_rabbitmq +from ..rest.plugin import setup_rest from . import ( _licensed_items_checkouts_rest, _licensed_items_purchases_rest, @@ -22,13 +23,13 @@ __name__, ModuleCategory.ADDON, settings_name="WEBSERVER_LICENSES", - depends=["simcore_service_webserver.rest"], logger=_logger, ) def setup_licenses(app: web.Application): assert app[APP_SETTINGS_KEY].WEBSERVER_LICENSES # nosec # routes + setup_rest(app) app.router.add_routes(_licensed_items_rest.routes) app.router.add_routes(_licensed_items_purchases_rest.routes) app.router.add_routes(_licensed_items_checkouts_rest.routes) diff --git a/services/web/server/tests/unit/isolated/test_application_settings.py b/services/web/server/tests/unit/isolated/test_application_settings.py index da7fbf2f34fd..954f85d51293 100644 --- a/services/web/server/tests/unit/isolated/test_application_settings.py +++ b/services/web/server/tests/unit/isolated/test_application_settings.py @@ -84,6 +84,8 @@ def test_settings_to_client_statics_plugins( assert settings.WEBSERVER_LOGIN + assert statics["webserverLicenses"] == settings.WEBSERVER_LICENSES + assert ( statics["webserverLogin"]["LOGIN_ACCOUNT_DELETION_RETENTION_DAYS"] == settings.WEBSERVER_LOGIN.LOGIN_ACCOUNT_DELETION_RETENTION_DAYS