Skip to content

Commit b82e2d2

Browse files
authored
chore: align identity settings with pydantic v2 (#425)
1 parent 4540967 commit b82e2d2

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed

services/identity/__init__.py

Whitespace-only changes.

services/identity/app/__init__.py

Whitespace-only changes.

services/identity/app/core/__init__.py

Whitespace-only changes.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""Application settings for the identity service."""
2+
3+
from functools import lru_cache
4+
from typing import Any
5+
6+
from pydantic import Field, PostgresDsn, RedisDsn, field_validator
7+
from pydantic_settings import BaseSettings, SettingsConfigDict
8+
9+
10+
class Settings(BaseSettings):
11+
"""Configuration values loaded from the environment."""
12+
13+
database_dsn: PostgresDsn = Field(
14+
default="postgresql://postgres:postgres@localhost:5432/identity",
15+
description="PostgreSQL DSN used for the identity service database.",
16+
)
17+
redis_dsn: RedisDsn = Field(
18+
default="redis://localhost:6379/0",
19+
description="Redis DSN used for caching and rate limiting.",
20+
)
21+
22+
model_config = SettingsConfigDict(
23+
env_file=(".env", ".env.local"),
24+
env_file_encoding="utf-8",
25+
case_sensitive=False,
26+
extra="allow",
27+
)
28+
29+
@field_validator("database_dsn", "redis_dsn", mode="before")
30+
@classmethod
31+
def _strip_whitespace(cls, value: Any) -> Any:
32+
"""Normalize DSN values by trimming extraneous whitespace."""
33+
34+
if isinstance(value, str):
35+
return value.strip()
36+
return value
37+
38+
39+
@lru_cache
40+
def get_settings() -> Settings:
41+
"""Return a cached :class:`Settings` instance."""
42+
43+
return Settings()

services/identity/pyproject.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[tool.poetry]
2+
name = "identity-service"
3+
version = "0.1.0"
4+
description = "Identity service"
5+
authors = ["Example <example@example.com>"]
6+
7+
[tool.poetry.dependencies]
8+
python = "^3.11"
9+
fastapi = "^0.111.0"
10+
pydantic = "^2.6.0"
11+
pydantic-settings = "^2.2.1"
12+
uvicorn = { extras = ["standard"], version = "^0.29.0" }
13+
14+
[tool.poetry.group.dev.dependencies]
15+
pytest = "^8.1.0"
16+
httpx = "^0.27.0"
17+
18+
[build-system]
19+
requires = ["poetry-core"]
20+
build-backend = "poetry.core.masonry.api"

0 commit comments

Comments
 (0)