Skip to content

Commit 7674e6b

Browse files
committed
web states
1 parent c5b1ba2 commit 7674e6b

File tree

7 files changed

+20
-11
lines changed

7 files changed

+20
-11
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
assert APP_CLIENT_SESSION_KEY # nosec
2929
assert APP_CONFIG_KEY # nosec
3030

31-
# Application storage keys
32-
APP_PRODUCTS_KEY: Final[str] = f"{__name__ }.APP_PRODUCTS_KEY"
3331

3432
# Public config per product returned in /config
3533
APP_PUBLIC_CONFIG_PER_PRODUCT: Final[str] = f"{__name__}.APP_PUBLIC_CONFIG_PER_PRODUCT"

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from servicelib.exceptions import InvalidConfig
99
from simcore_postgres_database.utils_products_prices import ProductPriceInfo
1010

11-
from ..constants import APP_PRODUCTS_KEY
12-
from ._models import CreditResult, ProductStripeInfo
11+
from ._app_state import APP_PRODUCTS_KEY
12+
from ._models import CreditResult, Product, ProductStripeInfo
1313
from ._repository import ProductRepository
1414
from .errors import (
1515
BelowMinimumPaymentError,
@@ -18,7 +18,6 @@
1818
ProductPriceNotDefinedError,
1919
ProductTemplateNotFoundError,
2020
)
21-
from .models import Product
2221

2322

2423
async def load_products(app: web.Application) -> list[Product]:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
from aiohttp import web
77
from models_library.products import ProductName
88

9-
from ..constants import APP_PRODUCTS_KEY
109
from . import _service
1110
from ._models import Product
11+
from ._web_app_states import APP_PRODUCTS_KEY, APP_PRODUCTS_KEY_DEFAULT
1212

1313
_logger = logging.getLogger(__name__)
1414

@@ -36,7 +36,7 @@ def _set_app_state(
3636
# cache them in the `app` upon startup
3737
app[APP_PRODUCTS_KEY] = app_products
3838
assert default_product_name in app_products # nosec
39-
app[f"{APP_PRODUCTS_KEY}_default"] = default_product_name
39+
app[APP_PRODUCTS_KEY_DEFAULT] = default_product_name
4040

4141

4242
async def _load_products_on_startup(app: web.Application):

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
from servicelib.rest_constants import X_PRODUCT_NAME_HEADER
88

99
from .._meta import API_VTAG
10-
from ..constants import APP_PRODUCTS_KEY, RQ_PRODUCT_KEY
10+
from ..constants import RQ_PRODUCT_KEY
1111
from ..utils_aiohttp import iter_origins
12+
from ._web_app_states import APP_PRODUCTS_KEY, APP_PRODUCTS_KEY_DEFAULT
1213
from .models import Product
1314

1415
_logger = logging.getLogger(__name__)
1516

1617

1718
def _get_default_product_name(app: web.Application) -> str:
18-
product_name: str = app[f"{APP_PRODUCTS_KEY}_default"]
19+
product_name: str = app[APP_PRODUCTS_KEY_DEFAULT]
1920
return product_name
2021

2122

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from typing import Final
2+
3+
from aiohttp import web
4+
5+
from ._models import Product, ProductName
6+
7+
APP_PRODUCTS_KEY: Final = web.AppKey("APP_PRODUCTS_KEY", dict[ProductName, Product])
8+
9+
APP_PRODUCTS_KEY_DEFAULT: Final = web.AppKey("_APP_PRODUCTS_KEY_DEFAULT", ProductName)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from ._web_app_states import APP_PRODUCTS_KEY
12
from ._web_helpers import (
23
get_current_product,
34
get_current_product_credit_price_info,
@@ -7,6 +8,7 @@
78
)
89

910
__all__: tuple[str, ...] = (
11+
"APP_PRODUCTS_KEY",
1012
"get_current_product",
1113
"get_current_product_credit_price_info",
1214
"get_product_name",

services/web/server/src/simcore_service_webserver/statics/_events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
from yarl import URL
1919

2020
from ..application_settings import ApplicationSettings, get_application_settings
21-
from ..constants import APP_PRODUCTS_KEY
2221
from ..products.models import Product
22+
from ..products.products_web import APP_PRODUCTS_KEY
2323
from ._constants import (
2424
APP_FRONTEND_CACHED_INDEXES_KEY,
2525
APP_FRONTEND_CACHED_STATICS_JSON_KEY,
@@ -119,7 +119,7 @@ async def create_and_cache_statics_json(app: web.Application) -> None:
119119
common.update(frontend_settings.to_statics())
120120

121121
# Adds products defined in db
122-
products: dict[str, Product] = app[APP_PRODUCTS_KEY]
122+
products = app[APP_PRODUCTS_KEY]
123123
assert products # nosec
124124

125125
app[APP_FRONTEND_CACHED_STATICS_JSON_KEY] = {}

0 commit comments

Comments
 (0)