simple-module-settings 0.0.48__tar.gz → 0.0.49__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/PKG-INFO +4 -4
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/pyproject.toml +4 -4
- simple_module_settings-0.0.49/settings/__main__.py +6 -0
- simple_module_settings-0.0.49/settings/cli.py +187 -0
- simple_module_settings-0.0.49/tests/core/module/test_settings_cli_entrypoint.py +50 -0
- simple_module_settings-0.0.49/tests/core/module/test_settings_cli_options.py +269 -0
- simple_module_settings-0.0.48/settings/cli.py +0 -78
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/.gitignore +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/LICENSE +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/README.md +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/package.json +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/__init__.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/contracts/__init__.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/contracts/accessor.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/contracts/events.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/contracts/invalidation.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/contracts/registry.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/contracts/schemas.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/core/__init__.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/core/_announce.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/core/_listing.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/core/_managed_keys.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/core/_row_masking.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/core/_secrets.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/core/_unique_write.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/core/constants.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/core/env_vars.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/core/errors.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/core/exceptions.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/core/invalidation.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/core/service.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/core/services.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/core/settings.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/core/tenant_scope.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/core/tenant_view.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/locales/de.json +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/locales/en.json +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/models.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/module.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/module_settings/__init__.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/module_settings/_field_meta.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/module_settings/discovery.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/module_settings/props.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/module_settings/reload.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/module_settings/store.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/pages/Browse.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/pages/Create.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/pages/Edit.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/pages/ModulesEdit.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/pages/api.generated.ts +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/pages/i18n.generated.ts +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/pages/routes.ts +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/pages/types.ts +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/py.typed +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/ui/components/FieldInput.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/ui/components/FieldSource.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/ui/components/FormLevelError.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/ui/components/JsonInput.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/ui/components/KeyField.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/ui/components/ModuleFieldRow.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/ui/components/ModuleForm.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/ui/components/ResolvedValue.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/ui/components/ScopeTabs.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/ui/components/StoreCards.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/ui/components/StoreTable.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/ui/components/TestConnectionButton.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/ui/components/ValueInput.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/ui/components/last-test.ts +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/ui/components/validation-errors.ts +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/web/__init__.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/web/browse_query.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/web/deps.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/web/endpoints/__init__.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/web/endpoints/_create_form.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/web/endpoints/api.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/web/endpoints/module_api.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/web/endpoints/tenant_api.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/web/endpoints/views.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/web/known_keys.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/core/contracts/test_settings_accessor.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/core/contracts/test_settings_events.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/core/contracts/test_settings_framework_reexports.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/core/contracts/test_settings_schemas.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/core/module/test_settings_cli_import.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/core/module/test_settings_host_restart_flags.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/core/module/test_settings_module.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/core/secrets/test_settings_secret_json_roundtrip.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/core/secrets/test_settings_secret_masking.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/core/secrets/test_settings_secret_urls.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/core/secrets/test_settings_store_secret_masking.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/core/secrets/test_settings_typed_secret_masking.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/core/service/test_settings_commit_invalidation.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/core/service/test_settings_concurrent_overrides.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/core/service/test_settings_default_clears_override.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/core/service/test_settings_domain_errors.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/core/service/test_settings_duplicate_and_race.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/core/service/test_settings_generic_module_guard.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/core/service/test_settings_group_metadata.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/core/service/test_settings_internal_metadata.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/core/service/test_settings_service.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/core/tenant/test_settings_tenant_settings.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/module_settings/fields/test_settings_control_hint.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/module_settings/fields/test_settings_env_pinned.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/module_settings/fields/test_settings_env_unprefixed.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/module_settings/fields/test_settings_field_sources.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/module_settings/fields/test_settings_lenient_related_fields_validators.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/module_settings/fields/test_settings_module_settings.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/module_settings/fields/test_settings_module_settings_render.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/module_settings/fields/test_settings_module_settings_serialize.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/module_settings/fields/test_settings_testable_checks.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/module_settings/hydrate/test_settings_hydrate.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/module_settings/hydrate/test_settings_hydrate_related_fields.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/module_settings/hydrate/test_settings_module_registry.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/module_settings/hydrate/test_settings_registration.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/module_settings/hydrate/test_settings_reload.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/module_settings/store/test_settings_store.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/module_settings/store/test_settings_store_filters.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/web/api/test_settings_api.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/web/api/test_settings_clear_route_per_scope.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/web/api/test_settings_known_keys_meta.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/web/api/test_settings_module_api.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/web/api/test_settings_module_api_json_fields.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/web/api/test_settings_upload_key_delete.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/web/api/test_settings_view_authz.py +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests-js/FieldInput.extensions.test.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests-js/JsonFields.test.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests-js/ModuleForm.test.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests-js/ModulesEdit.test.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests-js/RestartHint.test.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests-js/ScopeTabs.test.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests-js/settings_FormLevelError.test.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests-js/settings_ModuleFieldLayout.test.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests-js/settings_ModuleFormRevert.test.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests-js/settings_TestConnectionButton.test.tsx +0 -0
- {simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests-js/settings_validation-errors.test.ts +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: simple_module_settings
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.49
|
|
4
4
|
Summary: Runtime settings UI — modules plug their own settings panels into a shared admin view
|
|
5
5
|
Project-URL: Homepage, https://github.com/antosubash/simple_module_python
|
|
6
6
|
Project-URL: Repository, https://github.com/antosubash/simple_module_python
|
|
@@ -21,9 +21,9 @@ Classifier: Topic :: Internet :: WWW/HTTP
|
|
|
21
21
|
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
22
22
|
Classifier: Typing :: Typed
|
|
23
23
|
Requires-Python: >=3.12
|
|
24
|
-
Requires-Dist: simple-module-core==0.0.
|
|
25
|
-
Requires-Dist: simple-module-db==0.0.
|
|
26
|
-
Requires-Dist: simple-module-hosting==0.0.
|
|
24
|
+
Requires-Dist: simple-module-core==0.0.49
|
|
25
|
+
Requires-Dist: simple-module-db==0.0.49
|
|
26
|
+
Requires-Dist: simple-module-hosting==0.0.49
|
|
27
27
|
Requires-Dist: typer<0.28,>=0.12
|
|
28
28
|
Description-Content-Type: text/markdown
|
|
29
29
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "simple_module_settings"
|
|
3
|
-
version = "0.0.
|
|
3
|
+
version = "0.0.49"
|
|
4
4
|
description = "Runtime settings UI — modules plug their own settings panels into a shared admin view"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -21,9 +21,9 @@ classifiers = [
|
|
|
21
21
|
"Typing :: Typed",
|
|
22
22
|
]
|
|
23
23
|
dependencies = [
|
|
24
|
-
"simple_module_core==0.0.
|
|
25
|
-
"simple_module_db==0.0.
|
|
26
|
-
"simple_module_hosting==0.0.
|
|
24
|
+
"simple_module_core==0.0.49",
|
|
25
|
+
"simple_module_db==0.0.49",
|
|
26
|
+
"simple_module_hosting==0.0.49",
|
|
27
27
|
"typer>=0.12,<0.28",
|
|
28
28
|
]
|
|
29
29
|
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"""One-shot migration of legacy environment variables into DB settings."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import os
|
|
7
|
+
from collections.abc import Mapping, Sequence
|
|
8
|
+
from typing import Annotated
|
|
9
|
+
|
|
10
|
+
import typer
|
|
11
|
+
from fastapi import FastAPI
|
|
12
|
+
from pydantic import ValidationError
|
|
13
|
+
from pydantic_settings import BaseSettings
|
|
14
|
+
from simple_module_core.dotenv import find_env_file, parse_dotenv
|
|
15
|
+
from simple_module_core.module_settings import module_settings_registry
|
|
16
|
+
from simple_module_core.settings_hydrate import value_type_for_field
|
|
17
|
+
from simple_module_core.stored_settings import parse_stored_value
|
|
18
|
+
|
|
19
|
+
from settings.contracts.schemas import SettingUpsert, SettingValueType
|
|
20
|
+
from settings.core.env_vars import env_prefix_for
|
|
21
|
+
from settings.module_settings.store import SettingsStore
|
|
22
|
+
|
|
23
|
+
app = typer.Typer(help="Settings module administration.", no_args_is_help=True)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@app.callback()
|
|
27
|
+
def settings_commands() -> None:
|
|
28
|
+
"""Keep the command group when used standalone or mounted under smpy."""
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _validate_import(
|
|
32
|
+
package: str,
|
|
33
|
+
cls: type[BaseSettings],
|
|
34
|
+
existing: dict[str, tuple[str, str]],
|
|
35
|
+
candidates: dict[str, tuple[str, str]],
|
|
36
|
+
) -> bool:
|
|
37
|
+
"""Check stored payloads and the merged model before any writes."""
|
|
38
|
+
prefix = env_prefix_for(package)
|
|
39
|
+
merged = {}
|
|
40
|
+
valid = True
|
|
41
|
+
for field_name, (raw, vtype) in {**existing, **candidates}.items():
|
|
42
|
+
if field_name not in cls.model_fields:
|
|
43
|
+
continue
|
|
44
|
+
env_name = f"{prefix}{field_name.upper()}"
|
|
45
|
+
try:
|
|
46
|
+
merged[field_name] = parse_stored_value(raw, vtype)
|
|
47
|
+
if field_name in candidates:
|
|
48
|
+
SettingUpsert(value=raw, value_type=SettingValueType(vtype))
|
|
49
|
+
except ValidationError as exc:
|
|
50
|
+
valid = False
|
|
51
|
+
for error in exc.errors(include_input=False, include_context=False, include_url=False):
|
|
52
|
+
typer.echo(f"Error {env_name}: invalid stored value ({error['type']}).", err=True)
|
|
53
|
+
except ValueError:
|
|
54
|
+
valid = False
|
|
55
|
+
typer.echo(f"Error {env_name}: cannot parse as {vtype}.", err=True)
|
|
56
|
+
if not valid:
|
|
57
|
+
return False
|
|
58
|
+
try:
|
|
59
|
+
# Hydration skips env-pinned fields; imports must validate their future DB values too.
|
|
60
|
+
# Bypass BaseSettings sources: unselected env/dotenv must not validate this batch.
|
|
61
|
+
cls.__pydantic_validator__.validate_python(merged, self_instance=cls.__new__(cls))
|
|
62
|
+
except ValidationError as exc:
|
|
63
|
+
for error in exc.errors(include_input=False, include_context=False, include_url=False):
|
|
64
|
+
loc = error["loc"]
|
|
65
|
+
fields = [str(loc[0])] if loc and loc[0] in cls.model_fields else list(candidates)
|
|
66
|
+
# Like stored_settings, omit messages: validators can embed transformed secrets.
|
|
67
|
+
for field_name in fields:
|
|
68
|
+
typer.echo(
|
|
69
|
+
f"Error {prefix}{field_name.upper()}: validation failed ({error['type']}).",
|
|
70
|
+
err=True,
|
|
71
|
+
)
|
|
72
|
+
return False
|
|
73
|
+
return True
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
async def import_from_env_impl(
|
|
77
|
+
app_inst: FastAPI,
|
|
78
|
+
store: SettingsStore,
|
|
79
|
+
environ: Mapping[str, str] | None = None,
|
|
80
|
+
*,
|
|
81
|
+
only: Sequence[str] = (),
|
|
82
|
+
prefixes: Sequence[str] = (),
|
|
83
|
+
) -> int:
|
|
84
|
+
"""Validate a selected batch, then write SYSTEM overrides and print names.
|
|
85
|
+
|
|
86
|
+
The project .env is overlaid by process env (real env wins). Filters are
|
|
87
|
+
additive. Only registered DB settings fields are eligible: there is no
|
|
88
|
+
general env-only field marker. Any validation failure aborts all writes.
|
|
89
|
+
"""
|
|
90
|
+
if environ is None:
|
|
91
|
+
environ = {**parse_dotenv(find_env_file()), **os.environ}
|
|
92
|
+
registry = module_settings_registry(app_inst)
|
|
93
|
+
selected = {name.lower() for name in only}
|
|
94
|
+
known = {name.lower() for name in registry.all_packages()}
|
|
95
|
+
if unknown := selected - known:
|
|
96
|
+
raise typer.BadParameter(
|
|
97
|
+
f"Unknown module(s): {', '.join(sorted(unknown))}. "
|
|
98
|
+
f"Known modules: {', '.join(registry.all_packages())}",
|
|
99
|
+
param_hint="--only",
|
|
100
|
+
)
|
|
101
|
+
prefixes = tuple(prefix.upper() for prefix in prefixes)
|
|
102
|
+
|
|
103
|
+
def matches(package: str, env_name: str) -> bool:
|
|
104
|
+
return (
|
|
105
|
+
not (selected or prefixes)
|
|
106
|
+
or package.lower() in selected
|
|
107
|
+
or env_name.startswith(prefixes)
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
known_vars: set[str] = set()
|
|
111
|
+
pending: list[tuple[str, str, str, str]] = []
|
|
112
|
+
failed = False
|
|
113
|
+
for package, cls in registry.items():
|
|
114
|
+
prefix = env_prefix_for(package)
|
|
115
|
+
candidates = {}
|
|
116
|
+
for field_name in cls.model_fields:
|
|
117
|
+
env_name = f"{prefix}{field_name.upper()}"
|
|
118
|
+
known_vars.add(env_name)
|
|
119
|
+
if env_name in environ and matches(package, env_name):
|
|
120
|
+
candidates[field_name] = (environ[env_name], value_type_for_field(cls, field_name))
|
|
121
|
+
if not candidates:
|
|
122
|
+
continue
|
|
123
|
+
existing = await store.get_overrides(package)
|
|
124
|
+
if not _validate_import(package, cls, existing, candidates):
|
|
125
|
+
failed = True
|
|
126
|
+
continue
|
|
127
|
+
pending.extend((package, name, raw, vtype) for name, (raw, vtype) in candidates.items())
|
|
128
|
+
|
|
129
|
+
selected_prefixes = tuple(env_prefix_for(name) for name in known if name in selected)
|
|
130
|
+
for env_name in sorted(environ):
|
|
131
|
+
if (
|
|
132
|
+
env_name.startswith("SM_")
|
|
133
|
+
and env_name not in known_vars
|
|
134
|
+
and (not (selected or prefixes) or env_name.startswith(selected_prefixes + prefixes))
|
|
135
|
+
):
|
|
136
|
+
typer.echo(
|
|
137
|
+
f"Skipped {env_name}: no registered DB settings field (env-only or unknown)."
|
|
138
|
+
)
|
|
139
|
+
if failed:
|
|
140
|
+
raise typer.Exit(code=1)
|
|
141
|
+
for package, field_name, raw, vtype in pending:
|
|
142
|
+
await store.set_override(package, field_name, raw, vtype)
|
|
143
|
+
typer.echo(f"Stored {package}.{field_name}")
|
|
144
|
+
return len(pending)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
@app.command("import-from-env")
|
|
148
|
+
def import_from_env(
|
|
149
|
+
only: Annotated[
|
|
150
|
+
list[str] | None, typer.Option("--only", help="Settings package to import; repeatable.")
|
|
151
|
+
] = None,
|
|
152
|
+
prefix: Annotated[
|
|
153
|
+
list[str] | None,
|
|
154
|
+
typer.Option("--prefix", help="Environment variable prefix to import; repeatable."),
|
|
155
|
+
] = None,
|
|
156
|
+
) -> None:
|
|
157
|
+
"""Validate and import selected SM_<PREFIX>_<FIELD> variables into the DB."""
|
|
158
|
+
from simple_module_hosting.app_builder import create_app
|
|
159
|
+
from simple_module_hosting.settings import Settings
|
|
160
|
+
|
|
161
|
+
from settings.core.service import SettingService
|
|
162
|
+
|
|
163
|
+
fastapi_app = create_app(Settings())
|
|
164
|
+
|
|
165
|
+
async def run() -> int:
|
|
166
|
+
async with (
|
|
167
|
+
fastapi_app.router.lifespan_context(fastapi_app),
|
|
168
|
+
fastapi_app.state.sm.db.session_factory() as session,
|
|
169
|
+
):
|
|
170
|
+
store = SettingsStore(SettingService(session))
|
|
171
|
+
try:
|
|
172
|
+
n = await import_from_env_impl(
|
|
173
|
+
fastapi_app, store, only=only or (), prefixes=prefix or ()
|
|
174
|
+
)
|
|
175
|
+
except typer.Exit:
|
|
176
|
+
typer.echo("Imported 0 override(s) from environment.")
|
|
177
|
+
raise
|
|
178
|
+
await session.commit()
|
|
179
|
+
typer.echo(f"Imported {n} override(s) from environment.")
|
|
180
|
+
if n == 0 and find_env_file().is_file():
|
|
181
|
+
typer.echo(
|
|
182
|
+
"Hint: variables must be named SM_<MODULE>_<FIELD> "
|
|
183
|
+
"(e.g. SM_MAIL_SMTP_PORT); none in the environment or .env matched the filters."
|
|
184
|
+
)
|
|
185
|
+
return 0
|
|
186
|
+
|
|
187
|
+
raise typer.Exit(code=asyncio.run(run()))
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""`python -m settings` works in a production image without simple_module_cli (#1056)."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import subprocess
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _plain_help_env(tmp_path):
|
|
11
|
+
# Typer forces a Rich terminal under GITHUB_ACTIONS/FORCE_COLOR/PY_COLORS, which splits
|
|
12
|
+
# option names with escape codes.
|
|
13
|
+
env = {
|
|
14
|
+
k: v
|
|
15
|
+
for k, v in os.environ.items()
|
|
16
|
+
if k not in {"GITHUB_ACTIONS", "FORCE_COLOR", "PY_COLORS"}
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
**env,
|
|
20
|
+
"SM_PROJECT_ROOT": str(tmp_path),
|
|
21
|
+
"NO_COLOR": "1",
|
|
22
|
+
"_TYPER_FORCE_DISABLE_TERMINAL": "1",
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@pytest.mark.parametrize("args", [["-m", "settings", "import-from-env", "--help"], None])
|
|
27
|
+
def test_python_module_runs_without_developer_cli(tmp_path, args):
|
|
28
|
+
(tmp_path / "templates").mkdir()
|
|
29
|
+
# Block the optional CLI even if it happens to be installed in this checkout.
|
|
30
|
+
code = """
|
|
31
|
+
import runpy
|
|
32
|
+
import sys
|
|
33
|
+
sys.modules["simple_module_cli"] = None
|
|
34
|
+
from simple_module_hosting.app_builder import create_app
|
|
35
|
+
from simple_module_hosting.settings import Settings
|
|
36
|
+
create_app(Settings(environment="testing", modules_enabled=["ep:settings"],
|
|
37
|
+
database_url="sqlite+aiosqlite:///:memory:", secret_key="unit-test-key"))
|
|
38
|
+
sys.argv = ["settings", "import-from-env", "--help"]
|
|
39
|
+
runpy.run_module("settings", run_name="__main__")
|
|
40
|
+
"""
|
|
41
|
+
result = subprocess.run(
|
|
42
|
+
[sys.executable, *(args or ["-c", code])],
|
|
43
|
+
capture_output=True,
|
|
44
|
+
text=True,
|
|
45
|
+
timeout=30,
|
|
46
|
+
env=_plain_help_env(tmp_path),
|
|
47
|
+
)
|
|
48
|
+
assert result.returncode == 0, result.stderr
|
|
49
|
+
assert "--only" in result.stdout
|
|
50
|
+
assert "--prefix" in result.stdout
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"""Importer filters, validation and production CLI contracts without a database."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from contextlib import asynccontextmanager
|
|
6
|
+
from types import SimpleNamespace
|
|
7
|
+
|
|
8
|
+
import pytest
|
|
9
|
+
import typer
|
|
10
|
+
from fastapi import FastAPI
|
|
11
|
+
from pydantic import Field, field_validator, model_validator
|
|
12
|
+
from settings.cli import app, import_from_env_impl
|
|
13
|
+
from simple_module_core.module_settings import module_settings_registry
|
|
14
|
+
from simple_module_core.settings_base import DbBackedSettings
|
|
15
|
+
from typer.testing import CliRunner
|
|
16
|
+
from users.core.settings import UsersSettings
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class StorageSettings(DbBackedSettings):
|
|
20
|
+
bucket: str = ""
|
|
21
|
+
limit: int = Field(default=10, ge=1)
|
|
22
|
+
tags: list[str] = Field(default_factory=list)
|
|
23
|
+
minimum: int = 1
|
|
24
|
+
maximum: int = 10
|
|
25
|
+
|
|
26
|
+
@field_validator("bucket")
|
|
27
|
+
@classmethod
|
|
28
|
+
def check_bucket(cls, value: str) -> str:
|
|
29
|
+
if value.startswith("bad"):
|
|
30
|
+
raise ValueError(f"Invalid bucket {value.title()!r}")
|
|
31
|
+
return value
|
|
32
|
+
|
|
33
|
+
@model_validator(mode="after")
|
|
34
|
+
def check_limits(self):
|
|
35
|
+
if self.minimum > self.maximum:
|
|
36
|
+
raise ValueError("minimum must not exceed maximum")
|
|
37
|
+
return self
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class MemoryStore:
|
|
41
|
+
def __init__(self):
|
|
42
|
+
self.rows = {}
|
|
43
|
+
self.committed = False
|
|
44
|
+
|
|
45
|
+
async def get_overrides(self, package):
|
|
46
|
+
return {name: row for (pkg, name), row in self.rows.items() if pkg == package}
|
|
47
|
+
|
|
48
|
+
async def set_override(self, package, field, raw, vtype):
|
|
49
|
+
self.rows[package, field] = (raw, vtype)
|
|
50
|
+
|
|
51
|
+
async def commit(self):
|
|
52
|
+
self.committed = True
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@pytest.fixture
|
|
56
|
+
def importer(monkeypatch, tmp_path):
|
|
57
|
+
monkeypatch.setenv("SM_PROJECT_ROOT", str(tmp_path))
|
|
58
|
+
api = FastAPI()
|
|
59
|
+
registry = module_settings_registry(api)
|
|
60
|
+
registry.register("file_storage", StorageSettings)
|
|
61
|
+
registry.register("users", UsersSettings)
|
|
62
|
+
registry.register("background_tasks", StorageSettings)
|
|
63
|
+
return api, MemoryStore()
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@pytest.mark.parametrize(
|
|
67
|
+
("options", "expected"),
|
|
68
|
+
[
|
|
69
|
+
({}, {"file_storage", "users", "background_tasks"}),
|
|
70
|
+
({"only": ["FiLe_StOrAgE"]}, {"file_storage"}),
|
|
71
|
+
({"only": ["users", "background_tasks"]}, {"users", "background_tasks"}),
|
|
72
|
+
({"prefixes": ["sm_file_storage_"]}, {"file_storage"}),
|
|
73
|
+
({"prefixes": ["SM_USERS_", "SM_BG_TASKS_"]}, {"users", "background_tasks"}),
|
|
74
|
+
({"prefixes": ["sm_"]}, {"file_storage", "users", "background_tasks"}),
|
|
75
|
+
({"only": ["users"], "prefixes": ["SM_FILE_STORAGE_"]}, {"users", "file_storage"}),
|
|
76
|
+
],
|
|
77
|
+
)
|
|
78
|
+
async def test_filters_select_only_matching_variables(importer, options, expected):
|
|
79
|
+
api, store = importer
|
|
80
|
+
count = await import_from_env_impl(
|
|
81
|
+
api,
|
|
82
|
+
store,
|
|
83
|
+
environ={
|
|
84
|
+
"SM_FILE_STORAGE_BUCKET": "storage-value",
|
|
85
|
+
"SM_USERS_BASE_URL": "users-value",
|
|
86
|
+
"SM_BG_TASKS_BUCKET": "bg-value",
|
|
87
|
+
},
|
|
88
|
+
**options,
|
|
89
|
+
)
|
|
90
|
+
assert {package for package, _ in store.rows} == expected
|
|
91
|
+
assert count == len(expected)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def test_unknown_module_lists_known_names_before_writes(cli_importer):
|
|
95
|
+
result = CliRunner().invoke(app, ["import-from-env", "--only", "typo"])
|
|
96
|
+
assert result.exit_code == 2
|
|
97
|
+
for name in ("typo", "file_storage", "users", "background_tasks"):
|
|
98
|
+
assert name in result.output
|
|
99
|
+
assert cli_importer.rows == {}
|
|
100
|
+
assert not cli_importer.committed
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
async def test_prints_setting_names_never_values(importer, capsys):
|
|
104
|
+
api, store = importer
|
|
105
|
+
await import_from_env_impl(api, store, environ={"SM_FILE_STORAGE_BUCKET": "private-value"})
|
|
106
|
+
output = capsys.readouterr().out
|
|
107
|
+
assert "file_storage.bucket" in output
|
|
108
|
+
assert "private-value" not in output
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
@pytest.mark.parametrize(
|
|
112
|
+
"environ, name, message",
|
|
113
|
+
[
|
|
114
|
+
({"SM_USERS_SIGNUP_DEFAULT_ROLE": "ADMIN"}, "SM_USERS_SIGNUP_DEFAULT_ROLE", "value_error"),
|
|
115
|
+
({"SM_FILE_STORAGE_LIMIT": "-17"}, "SM_FILE_STORAGE_LIMIT", "greater_than_equal"),
|
|
116
|
+
({"SM_FILE_STORAGE_LIMIT": "not-an-int"}, "SM_FILE_STORAGE_LIMIT", "int"),
|
|
117
|
+
({"SM_USERS_ALLOW_SIGNUP": "not-a-bool"}, "SM_USERS_ALLOW_SIGNUP", "bool"),
|
|
118
|
+
({"SM_FILE_STORAGE_TAGS": "not-json"}, "SM_FILE_STORAGE_TAGS", "json"),
|
|
119
|
+
({"SM_FILE_STORAGE_BUCKET": "bad-private"}, "SM_FILE_STORAGE_BUCKET", "value_error"),
|
|
120
|
+
({"SM_FILE_STORAGE_BUCKET": "x" * 4001}, "SM_FILE_STORAGE_BUCKET", "string_too_long"),
|
|
121
|
+
(
|
|
122
|
+
{"SM_FILE_STORAGE_MINIMUM": "24", "SM_FILE_STORAGE_MAXIMUM": "18"},
|
|
123
|
+
"SM_FILE_STORAGE_MINIMUM",
|
|
124
|
+
"value_error",
|
|
125
|
+
),
|
|
126
|
+
],
|
|
127
|
+
)
|
|
128
|
+
async def test_invalid_batch_writes_nothing(importer, capsys, environ, name, message):
|
|
129
|
+
api, store = importer
|
|
130
|
+
# Also catches writing valid variables before discovering a later invalid one.
|
|
131
|
+
environ = {
|
|
132
|
+
"SM_BG_TASKS_BUCKET": "valid-private-bucket",
|
|
133
|
+
"SM_USERS_BASE_URL": "valid-private-url",
|
|
134
|
+
**environ,
|
|
135
|
+
}
|
|
136
|
+
with pytest.raises(typer.Exit) as exc:
|
|
137
|
+
await import_from_env_impl(api, store, environ=environ)
|
|
138
|
+
assert exc.value.exit_code != 0
|
|
139
|
+
assert store.rows == {}
|
|
140
|
+
output = capsys.readouterr().err
|
|
141
|
+
assert name in output
|
|
142
|
+
assert message in output
|
|
143
|
+
for value in environ.values():
|
|
144
|
+
assert value not in output
|
|
145
|
+
assert value.upper() not in output
|
|
146
|
+
assert value.title() not in output
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
async def test_validates_candidates_together_with_existing_overrides(importer):
|
|
150
|
+
api, store = importer
|
|
151
|
+
store.rows["file_storage", "maximum"] = ("30", "int")
|
|
152
|
+
assert (
|
|
153
|
+
await import_from_env_impl(
|
|
154
|
+
api, store, environ={"SM_FILE_STORAGE_MINIMUM": "24", "SM_FILE_STORAGE_TAGS": '["one"]'}
|
|
155
|
+
)
|
|
156
|
+
== 2
|
|
157
|
+
)
|
|
158
|
+
assert store.rows["file_storage", "minimum"] == ("24", "int")
|
|
159
|
+
assert store.rows["file_storage", "tags"] == ('["one"]', "json")
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
@pytest.mark.parametrize("source", ["process", "dotenv"])
|
|
163
|
+
async def test_filtered_batch_cannot_borrow_unselected_environment(
|
|
164
|
+
importer, monkeypatch, tmp_path, source
|
|
165
|
+
):
|
|
166
|
+
from simple_module_hosting.host_settings import HostSettings
|
|
167
|
+
|
|
168
|
+
api, store = importer
|
|
169
|
+
module_settings_registry(api).register("host", HostSettings)
|
|
170
|
+
if source == "process":
|
|
171
|
+
monkeypatch.setenv("SM_I18N_SUPPORTED_LOCALES", '["en", "de"]')
|
|
172
|
+
else:
|
|
173
|
+
(tmp_path / ".env").write_text('SM_I18N_SUPPORTED_LOCALES=["en", "de"]\n')
|
|
174
|
+
with pytest.raises(typer.Exit):
|
|
175
|
+
await import_from_env_impl(
|
|
176
|
+
api, store, environ={"SM_I18N_DEFAULT_LOCALE": "de"}, prefixes=["SM_I18N_DEFAULT_"]
|
|
177
|
+
)
|
|
178
|
+
assert store.rows == {}
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
async def test_skips_variables_outside_db_settings_registry(importer, capsys):
|
|
182
|
+
from simple_module_hosting.host_settings import HostSettings
|
|
183
|
+
|
|
184
|
+
api, store = importer
|
|
185
|
+
module_settings_registry(api).register("host", HostSettings)
|
|
186
|
+
names = (
|
|
187
|
+
"SM_USERS_RESET_PASSWORD_TOKEN_SECRET",
|
|
188
|
+
"SM_USERS_VERIFICATION_TOKEN_SECRET",
|
|
189
|
+
"SM_USERS_BOOTSTRAP_PASSWORD",
|
|
190
|
+
"SM_DATABASE_URL",
|
|
191
|
+
"SM_BG_TASKS_UNKNOWN",
|
|
192
|
+
"SM_KEYCLOAK_UNKNOWN",
|
|
193
|
+
)
|
|
194
|
+
count = await import_from_env_impl(api, store, environ=dict.fromkeys(names, "sensitive-value"))
|
|
195
|
+
assert count == 0
|
|
196
|
+
assert store.rows == {}
|
|
197
|
+
output = capsys.readouterr().out
|
|
198
|
+
for name in names:
|
|
199
|
+
assert name in output
|
|
200
|
+
assert "skip" in output.lower()
|
|
201
|
+
assert "DB" in output
|
|
202
|
+
assert "sensitive-value" not in output
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
@pytest.mark.parametrize(
|
|
206
|
+
"field, raw, vtype",
|
|
207
|
+
[("limit", "private-invalid-int", "int"), ("bucket", "bad-private", "string")],
|
|
208
|
+
)
|
|
209
|
+
async def test_existing_malformed_override_aborts_without_echoing_value(
|
|
210
|
+
importer, capsys, field, raw, vtype
|
|
211
|
+
):
|
|
212
|
+
api, store = importer
|
|
213
|
+
store.rows["file_storage", field] = (raw, vtype)
|
|
214
|
+
with pytest.raises(typer.Exit):
|
|
215
|
+
await import_from_env_impl(api, store, environ={"SM_FILE_STORAGE_MAXIMUM": "20"})
|
|
216
|
+
assert len(store.rows) == 1
|
|
217
|
+
output = capsys.readouterr().err
|
|
218
|
+
assert f"SM_FILE_STORAGE_{field.upper()}" in output
|
|
219
|
+
assert all(value not in output for value in (raw, raw.upper(), raw.title()))
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
@pytest.fixture
|
|
223
|
+
def cli_importer(importer, monkeypatch):
|
|
224
|
+
api, store = importer
|
|
225
|
+
|
|
226
|
+
@asynccontextmanager
|
|
227
|
+
async def session_factory():
|
|
228
|
+
yield store
|
|
229
|
+
|
|
230
|
+
api.state.sm = SimpleNamespace(db=SimpleNamespace(session_factory=session_factory))
|
|
231
|
+
monkeypatch.setattr("simple_module_hosting.settings.Settings", lambda: None)
|
|
232
|
+
monkeypatch.setattr("simple_module_hosting.app_builder.create_app", lambda _: api)
|
|
233
|
+
monkeypatch.setattr("settings.core.service.SettingService", lambda session: session)
|
|
234
|
+
monkeypatch.setattr("settings.cli.SettingsStore", lambda service: service)
|
|
235
|
+
# Supply only this test's env instead of inheriting the workstation environment.
|
|
236
|
+
monkeypatch.setattr("settings.cli.os.environ", {})
|
|
237
|
+
return store
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
@pytest.mark.parametrize("mounted", [False, True])
|
|
241
|
+
def test_typer_subcommand_executes_filters(cli_importer, monkeypatch, mounted):
|
|
242
|
+
monkeypatch.setenv("SM_FILE_STORAGE_BUCKET", "bucket-private")
|
|
243
|
+
monkeypatch.setenv("SM_USERS_BASE_URL", "users-private")
|
|
244
|
+
monkeypatch.setenv("SM_BG_TASKS_BUCKET", "background-private")
|
|
245
|
+
cli = app
|
|
246
|
+
args = ["import-from-env", "--only", "FILE_STORAGE", "--only", "users"]
|
|
247
|
+
args.extend(["--prefix", "SM_BG_TASKS_"])
|
|
248
|
+
if mounted:
|
|
249
|
+
cli = typer.Typer()
|
|
250
|
+
cli.add_typer(app, name="settings")
|
|
251
|
+
args.insert(0, "settings")
|
|
252
|
+
result = CliRunner().invoke(cli, args)
|
|
253
|
+
assert result.exit_code == 0, result.output
|
|
254
|
+
assert len(cli_importer.rows) == 3
|
|
255
|
+
assert cli_importer.committed
|
|
256
|
+
assert "Imported 3 override(s)" in result.output
|
|
257
|
+
assert "file_storage.bucket" in result.output
|
|
258
|
+
assert "private" not in result.output
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def test_cli_invalid_value_exits_without_commit(cli_importer, monkeypatch):
|
|
262
|
+
monkeypatch.setenv("SM_USERS_SIGNUP_DEFAULT_ROLE", "ADMIN")
|
|
263
|
+
result = CliRunner().invoke(app, ["import-from-env"])
|
|
264
|
+
assert result.exit_code == 1
|
|
265
|
+
assert not cli_importer.committed
|
|
266
|
+
assert not cli_importer.rows
|
|
267
|
+
assert "SM_USERS_SIGNUP_DEFAULT_ROLE" in result.output
|
|
268
|
+
assert "ADMIN" not in result.output
|
|
269
|
+
assert "Imported 0 override(s)" in result.output
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"""``smpy settings`` plugin — currently only ``import-from-env``.
|
|
2
|
-
|
|
3
|
-
One-shot migration: walks every registered module's BaseSettings and
|
|
4
|
-
writes a SYSTEM-scoped override for each ``SM_<PREFIX>_<FIELD>`` env
|
|
5
|
-
var that is set.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from __future__ import annotations
|
|
9
|
-
|
|
10
|
-
import asyncio
|
|
11
|
-
import os
|
|
12
|
-
from collections.abc import Mapping
|
|
13
|
-
|
|
14
|
-
import typer
|
|
15
|
-
from fastapi import FastAPI
|
|
16
|
-
from simple_module_core.dotenv import find_env_file, parse_dotenv
|
|
17
|
-
from simple_module_core.module_settings import module_settings_registry
|
|
18
|
-
from simple_module_core.settings_hydrate import value_type_for_field
|
|
19
|
-
|
|
20
|
-
from settings.core.env_vars import env_prefix_for
|
|
21
|
-
from settings.module_settings.store import SettingsStore
|
|
22
|
-
|
|
23
|
-
app = typer.Typer(help="Settings module administration.", no_args_is_help=True)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
async def import_from_env_impl(
|
|
27
|
-
app_inst: FastAPI,
|
|
28
|
-
store: SettingsStore,
|
|
29
|
-
environ: Mapping[str, str] | None = None,
|
|
30
|
-
) -> int:
|
|
31
|
-
"""Write a SYSTEM override for every ``SM_<PREFIX>_<FIELD>`` var set.
|
|
32
|
-
|
|
33
|
-
Default source is the project ``.env`` overlaid by the process environment
|
|
34
|
-
(real env wins). ``os.environ`` is never mutated.
|
|
35
|
-
"""
|
|
36
|
-
if environ is None:
|
|
37
|
-
environ = {**parse_dotenv(find_env_file()), **os.environ}
|
|
38
|
-
registry = module_settings_registry(app_inst)
|
|
39
|
-
count = 0
|
|
40
|
-
for package, cls in registry.items():
|
|
41
|
-
prefix = env_prefix_for(package)
|
|
42
|
-
for field_name in cls.model_fields:
|
|
43
|
-
raw = environ.get(f"{prefix}{field_name.upper()}")
|
|
44
|
-
if raw is None:
|
|
45
|
-
continue
|
|
46
|
-
vtype = value_type_for_field(cls, field_name)
|
|
47
|
-
await store.set_override(package, field_name, raw, vtype)
|
|
48
|
-
count += 1
|
|
49
|
-
return count
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
@app.command("import-from-env")
|
|
53
|
-
def import_from_env() -> None:
|
|
54
|
-
"""Write SYSTEM overrides for every SM_<PREFIX>_<FIELD> env var set."""
|
|
55
|
-
from simple_module_hosting.app_builder import create_app
|
|
56
|
-
from simple_module_hosting.settings import Settings
|
|
57
|
-
|
|
58
|
-
from settings.core.service import SettingService
|
|
59
|
-
|
|
60
|
-
fastapi_app = create_app(Settings())
|
|
61
|
-
|
|
62
|
-
async def run() -> int:
|
|
63
|
-
async with (
|
|
64
|
-
fastapi_app.router.lifespan_context(fastapi_app),
|
|
65
|
-
fastapi_app.state.sm.db.session_factory() as session,
|
|
66
|
-
):
|
|
67
|
-
store = SettingsStore(SettingService(session))
|
|
68
|
-
n = await import_from_env_impl(fastapi_app, store)
|
|
69
|
-
await session.commit()
|
|
70
|
-
typer.echo(f"Imported {n} override(s) from environment.")
|
|
71
|
-
if n == 0 and find_env_file().is_file():
|
|
72
|
-
typer.echo(
|
|
73
|
-
"Hint: variables must be named SM_<MODULE>_<FIELD> "
|
|
74
|
-
"(e.g. SM_MAIL_SMTP_PORT); none in the environment or .env matched."
|
|
75
|
-
)
|
|
76
|
-
return 0
|
|
77
|
-
|
|
78
|
-
raise typer.Exit(code=asyncio.run(run()))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/contracts/__init__.py
RENAMED
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/contracts/accessor.py
RENAMED
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/contracts/events.py
RENAMED
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/contracts/invalidation.py
RENAMED
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/contracts/registry.py
RENAMED
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/contracts/schemas.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/core/_managed_keys.py
RENAMED
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/core/_row_masking.py
RENAMED
|
File without changes
|
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/core/_unique_write.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/core/invalidation.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/core/tenant_scope.py
RENAMED
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/core/tenant_view.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/module_settings/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/module_settings/props.py
RENAMED
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/module_settings/reload.py
RENAMED
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/module_settings/store.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/pages/ModulesEdit.tsx
RENAMED
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/pages/api.generated.ts
RENAMED
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/pages/i18n.generated.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/ui/components/JsonInput.tsx
RENAMED
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/ui/components/KeyField.tsx
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/ui/components/ScopeTabs.tsx
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/ui/components/last-test.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/web/browse_query.py
RENAMED
|
File without changes
|
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/web/endpoints/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/web/endpoints/api.py
RENAMED
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/web/endpoints/module_api.py
RENAMED
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/web/endpoints/tenant_api.py
RENAMED
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/settings/web/endpoints/views.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests/web/api/test_settings_api.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests-js/JsonFields.test.tsx
RENAMED
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests-js/ModuleForm.test.tsx
RENAMED
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests-js/ModulesEdit.test.tsx
RENAMED
|
File without changes
|
{simple_module_settings-0.0.48 → simple_module_settings-0.0.49}/tests-js/RestartHint.test.tsx
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|