svc-infra 0.1.184__tar.gz → 0.1.185__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.
- {svc_infra-0.1.184 → svc_infra-0.1.185}/PKG-INFO +1 -1
- {svc_infra-0.1.184 → svc_infra-0.1.185}/pyproject.toml +1 -1
- svc_infra-0.1.185/src/svc_infra/auth/user_default.py +81 -0
- svc_infra-0.1.184/src/svc_infra/auth/user_default.py +0 -53
- {svc_infra-0.1.184 → svc_infra-0.1.185}/README.md +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/__init__.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/__init__.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/__init__.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/db/README.md +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/db/__init__.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/db/add.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/db/crud_router.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/db/health.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/db/http.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/db/management.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/db/repository.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/db/resource.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/db/service.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/db/service_hooks.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/db/session.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/db/uniq.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/middleware/__init__.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/middleware/errors/__init__.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/middleware/errors/catchall.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/middleware/errors/error_handlers.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/middleware/errors/exceptions.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/routers/__init__.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/routers/ping.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/settings.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/app/__init__.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/app/env.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/app/logging.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/app/root.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/app/settings.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/auth/__init__.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/auth/integration.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/auth/oauth_router.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/auth/providers.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/auth/settings.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/auth/users.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/cli/__init__.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/cli/cmds/__init__.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/cli/cmds/alembic_cmds.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/cli/cmds/help.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/cli/cmds/scaffold_cmds.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/cli/foundation/__init__.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/cli/foundation/runner.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/cli/foundation/typer_bootstrap.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/db/README.md +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/db/__init__.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/db/base.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/db/constants.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/db/core.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/db/scaffold.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/db/templates/__init__.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/db/templates/models_schemas/__init__.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/db/templates/models_schemas/auth/models.py.tmpl +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/db/templates/models_schemas/auth/schemas.py.tmpl +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/db/templates/models_schemas/entity/models.py.tmpl +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/db/templates/models_schemas/entity/schemas.py.tmpl +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/db/templates/setup/__init__.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/db/templates/setup/alembic.ini.tmpl +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/db/templates/setup/env_async.py.tmpl +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/db/templates/setup/env_sync.py.tmpl +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/db/templates/setup/script.py.mako.tmpl +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/db/uniq.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/db/utils.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/mcp/__init__.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/mcp/svc_infra_mcp.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/observability/README.md +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/observability/__init__.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/observability/metrics/__init__.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/observability/metrics/asgi.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/observability/metrics/base.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/observability/metrics/http.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/observability/metrics/sqlalchemy.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/observability/settings.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/observability/templates/grafana_dashboard.json +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/observability/templates/otel-collector.yaml +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/observability/templates/prometheus_rules.yml +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/observability/tracing/__init__.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/observability/tracing/setup.py +0 -0
- {svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/py.typed +0 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
from typing import Any, Dict
|
2
|
+
from fastapi import HTTPException
|
3
|
+
from fastapi_users.password import PasswordHelper
|
4
|
+
from sqlalchemy import func
|
5
|
+
|
6
|
+
from svc_infra.api.fastapi.db.service_hooks import ServiceWithHooks
|
7
|
+
from svc_infra.api.fastapi.db.repository import Repository
|
8
|
+
|
9
|
+
_pwd = PasswordHelper()
|
10
|
+
|
11
|
+
def make_default_user_service(repo: Repository):
|
12
|
+
Model = repo.model # <-- capture the actual mapped model from the repo
|
13
|
+
|
14
|
+
def _user_pre_create(data: Dict[str, Any]) -> Dict[str, Any]:
|
15
|
+
data = dict(data)
|
16
|
+
# normalize + map fields
|
17
|
+
if "password" in data:
|
18
|
+
data["password_hash"] = _pwd.hash(data.pop("password"))
|
19
|
+
if "metadata" in data:
|
20
|
+
data["extra"] = data.pop("metadata")
|
21
|
+
data.setdefault("roles", [])
|
22
|
+
|
23
|
+
# BEFORE insert: app-level guard (nice 409) aligned with DB uniqueness
|
24
|
+
email = data.get("email")
|
25
|
+
tenant_id = data.get("tenant_id")
|
26
|
+
if email is not None:
|
27
|
+
# case-insensitive email; scope by tenant (NULL => global)
|
28
|
+
where = [func.lower(Model.email) == func.lower(email)]
|
29
|
+
if hasattr(Model, "tenant_id"):
|
30
|
+
if tenant_id is None:
|
31
|
+
where.append(Model.tenant_id.is_(None))
|
32
|
+
else:
|
33
|
+
where.append(Model.tenant_id == tenant_id)
|
34
|
+
|
35
|
+
async def _exists(session):
|
36
|
+
return await repo.exists(session, where=where)
|
37
|
+
|
38
|
+
# stash the callback so Service.create can await it (has session)
|
39
|
+
data["_precreate_exists_check"] = _exists
|
40
|
+
|
41
|
+
return data
|
42
|
+
|
43
|
+
def _user_pre_update(data: Dict[str, Any]) -> Dict[str, Any]:
|
44
|
+
data = dict(data)
|
45
|
+
if "password" in data:
|
46
|
+
data["password_hash"] = _pwd.hash(data.pop("password"))
|
47
|
+
if "metadata" in data:
|
48
|
+
data["extra"] = data.pop("metadata")
|
49
|
+
|
50
|
+
# Optional: also protect email change from creating dupes
|
51
|
+
email = data.get("email")
|
52
|
+
tenant_id = data.get("tenant_id")
|
53
|
+
if email is not None:
|
54
|
+
where = [func.lower(Model.email) == func.lower(email)]
|
55
|
+
if hasattr(Model, "tenant_id"):
|
56
|
+
if tenant_id is None:
|
57
|
+
where.append(Model.tenant_id.is_(None))
|
58
|
+
else:
|
59
|
+
where.append(Model.tenant_id == tenant_id)
|
60
|
+
|
61
|
+
async def _exists(session):
|
62
|
+
return await repo.exists(session, where=where)
|
63
|
+
|
64
|
+
data["_precreate_exists_check"] = _exists # reuse same key
|
65
|
+
|
66
|
+
return data
|
67
|
+
|
68
|
+
class _Svc(ServiceWithHooks):
|
69
|
+
async def create(self, session, data):
|
70
|
+
exists_cb = data.pop("_precreate_exists_check", None)
|
71
|
+
if exists_cb and await exists_cb(session):
|
72
|
+
raise HTTPException(status_code=409, detail="User with this email already exists.")
|
73
|
+
return await super().create(session, data)
|
74
|
+
|
75
|
+
async def update(self, session, id_value, data):
|
76
|
+
exists_cb = data.pop("_precreate_exists_check", None)
|
77
|
+
if exists_cb and await exists_cb(session):
|
78
|
+
raise HTTPException(status_code=409, detail="User with this email already exists.")
|
79
|
+
return await super().update(session, id_value, data)
|
80
|
+
|
81
|
+
return _Svc(repo, pre_create=_user_pre_create, pre_update=_user_pre_update)
|
@@ -1,53 +0,0 @@
|
|
1
|
-
from typing import Any, Dict
|
2
|
-
from fastapi import HTTPException
|
3
|
-
from fastapi_users.password import PasswordHelper
|
4
|
-
from sqlalchemy import func
|
5
|
-
|
6
|
-
from svc_infra.api.fastapi.db.service_hooks import ServiceWithHooks
|
7
|
-
from svc_infra.api.fastapi.db.repository import Repository
|
8
|
-
|
9
|
-
_pwd = PasswordHelper()
|
10
|
-
|
11
|
-
def _user_pre_create(data: Dict[str, Any]) -> Dict[str, Any]:
|
12
|
-
data = dict(data)
|
13
|
-
# normalize + map fields
|
14
|
-
if "password" in data:
|
15
|
-
data["password_hash"] = _pwd.hash(data.pop("password"))
|
16
|
-
if "metadata" in data:
|
17
|
-
data["extra"] = data.pop("metadata")
|
18
|
-
|
19
|
-
# BEFORE insert: application-level guard (nice error)
|
20
|
-
# case-insensitive email; handle tenant/null logic the same way as your unique index
|
21
|
-
email = data.get("email")
|
22
|
-
tenant_id = data.get("tenant_id")
|
23
|
-
if email:
|
24
|
-
where = [func.lower(Repository.model.email) == func.lower(email)]
|
25
|
-
if tenant_id is None:
|
26
|
-
where.append(Repository.model.tenant_id.is_(None))
|
27
|
-
else:
|
28
|
-
where.append(Repository.model.tenant_id == tenant_id)
|
29
|
-
|
30
|
-
# use a small “exists” helper on the repo if you have it
|
31
|
-
async def _exists(session):
|
32
|
-
return await Repository.exists(session, where=where)
|
33
|
-
|
34
|
-
data["_precreate_exists_check"] = _exists # stash callable for service.create to run
|
35
|
-
|
36
|
-
return data
|
37
|
-
|
38
|
-
def _user_pre_update(data: Dict[str, Any]) -> Dict[str, Any]:
|
39
|
-
data = dict(data)
|
40
|
-
if "password" in data:
|
41
|
-
data["password_hash"] = _pwd.hash(data.pop("password"))
|
42
|
-
if "metadata" in data:
|
43
|
-
data["extra"] = data.pop("metadata")
|
44
|
-
return data
|
45
|
-
|
46
|
-
def make_default_user_service(repo: Repository):
|
47
|
-
class _Svc(ServiceWithHooks):
|
48
|
-
async def create(self, session, data):
|
49
|
-
exists_cb = data.pop("_precreate_exists_check", None)
|
50
|
-
if exists_cb and await exists_cb(session):
|
51
|
-
raise HTTPException(status_code=409, detail="User with this email already exists.")
|
52
|
-
return await super().create(session, data)
|
53
|
-
return _Svc(repo, pre_create=_user_pre_create, pre_update=_user_pre_update)
|
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
|
{svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/middleware/errors/__init__.py
RENAMED
File without changes
|
{svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/middleware/errors/catchall.py
RENAMED
File without changes
|
File without changes
|
{svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/api/fastapi/middleware/errors/exceptions.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
|
{svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/db/templates/models_schemas/__init__.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
|
{svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/db/templates/setup/script.py.mako.tmpl
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
|
{svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/observability/templates/grafana_dashboard.json
RENAMED
File without changes
|
{svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/observability/templates/otel-collector.yaml
RENAMED
File without changes
|
{svc_infra-0.1.184 → svc_infra-0.1.185}/src/svc_infra/observability/templates/prometheus_rules.yml
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|