Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
# NOTE: to mark a plugin as a DEV-FEATURE annotated it with
# `Field(json_schema_extra={_X_DEV_FEATURE_FLAG: True})`
# This will force it to be disabled when WEBSERVER_DEV_FEATURES_ENABLED=False
_X_DEV_FEATURE_FLAG: Final[str] = "x-dev-feature"
_X_FEATURE_UNDER_DEVELOPMENT: Final[str] = "x-dev-feature"


class ApplicationSettings(BaseApplicationSettings, MixinLoggingSettings):
Expand Down Expand Up @@ -108,10 +108,9 @@ class ApplicationSettings(BaseApplicationSettings, MixinLoggingSettings):
WEBSERVER_FUNCTIONS: Annotated[
bool,
Field(
validation_alias=AliasChoices("WEBSERVER_FUNCTIONS"),
json_schema_extra={_X_DEV_FEATURE_FLAG: True},
json_schema_extra={_X_FEATURE_UNDER_DEVELOPMENT: True},
),
] = False
] = True

WEBSERVER_LOGLEVEL: Annotated[
LogLevel,
Expand Down Expand Up @@ -406,8 +405,8 @@ def _build_vcs_release_url_if_unset(cls, values):

@model_validator(mode="before")
@classmethod
def _enable_only_if_dev_features_allowed(cls, data: Any) -> Any:
"""Force disables plugins marked 'under development' when WEBSERVER_DEV_FEATURES_ENABLED=False"""
def _disable_features_under_development_in_production(cls, data: Any) -> Any:
"""Force disables plugins marked '_X_FEATURE_UNDER_DEVELOPMENT' when WEBSERVER_DEV_FEATURES_ENABLED=False"""

dev_features_allowed = TypeAdapter(bool).validate_python(
data.get("WEBSERVER_DEV_FEATURES_ENABLED", False)
Expand All @@ -423,7 +422,8 @@ def _enable_only_if_dev_features_allowed(cls, data: Any) -> Any:
field.json_schema_extra(json_schema)

assert isinstance(json_schema, dict) # nosec
if json_schema.get(_X_DEV_FEATURE_FLAG):
if json_schema.get(_X_FEATURE_UNDER_DEVELOPMENT):
assert not dev_features_allowed # nosec
_logger.warning(
"'%s' is still under development and will be forcibly disabled [WEBSERVER_DEV_FEATURES_ENABLED=%s].",
field_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
from pytest_simcore.helpers.typing_env import EnvVarsDict
from simcore_service_webserver.application_settings import (
_X_DEV_FEATURE_FLAG,
_X_FEATURE_UNDER_DEVELOPMENT,
APP_SETTINGS_KEY,
ApplicationSettings,
setup_settings,
Expand Down Expand Up @@ -130,17 +130,25 @@ def test_disabled_plugins_settings_to_client_statics(
)

class DevSettings(ApplicationSettings):
TEST_FOO: Annotated[bool, Field(json_schema_extra={_X_DEV_FEATURE_FLAG: True})]
TEST_FOO: Annotated[
bool, Field(json_schema_extra={_X_FEATURE_UNDER_DEVELOPMENT: True})
]
TEST_BAR: Annotated[
int | None, Field(json_schema_extra={_X_DEV_FEATURE_FLAG: True})
int | None, Field(json_schema_extra={_X_FEATURE_UNDER_DEVELOPMENT: True})
]

settings = DevSettings.create_from_envs()

if is_dev_feature_enabled:
assert settings.WEBSERVER_DEV_FEATURES_ENABLED is True
assert settings.WEBSERVER_FUNCTIONS is True

assert settings.TEST_FOO is True
assert settings.TEST_BAR == 42
else:
assert settings.WEBSERVER_DEV_FEATURES_ENABLED is False
assert settings.WEBSERVER_FUNCTIONS is False

assert settings.TEST_FOO is False
assert settings.TEST_BAR is None

Expand Down
Loading