Skip to content

feat(config): unify environment-backed settings across backend (#13) - #35

Open
2022117144 wants to merge 1 commit into
PiLab-Indonesia:mainfrom
2022117144:feat-centralized-env-config-issue13
Open

2022117144 wants to merge 1 commit into
PiLab-Indonesia:mainfrom
2022117144:feat-centralized-env-config-issue13

Conversation

@2022117144

Copy link
Copy Markdown

Summary

Closes #13.

Finish wiring the already-present Pydantic BaseSettings configuration through the actual backend. Previously the primary API still hard-coded its database path and title, discovery and alerts repeated hard-coded database defaults, and app/config.py imported BaseSettings directly from pydantic (which raises on Pydantic v2).

Code changes

  • Use settings.app_name and settings.db_path in the real app.main entry point, and remove the invalid Device import from app.models.
  • Use the same DB path from settings in ARP discovery and alert rules while preserving optional explicit caller overrides. Alert rules use configured Telegram destination by default.
  • Support pydantic.v1.BaseSettings (available under Pydantic 2 and recent Pydantic 1) with a fallback for older v1 installs.
  • Add .env.example, .gitignore (prevents real local secrets, SQLite files and caches from being committed), requirements.txt (also fills a file expected by the existing Dockerfile), and docs/CONFIGURATION.md.
  • Add six focused regression tests covering defaults, typed environment variables, bad values, .env vs env precedence, API configuration and ARP discovery DB path overrides.

Verification

Windows / Python 3.10 / Pydantic 2.13.4, with python-dotenv installed:

  • python -m pytest -q -p no:cacheprovider tests/test_config.py: 6 passed, four existing FastAPI on_event deprecation warnings (not introduced by this patch).
  • python -m flake8 app/config.py app/main.py app/autodiscover.py app/alertrules.py tests/test_config.py --select=E9,F63,F7,F82 --show-source: exit 0.
  • git diff --cached --check: exit 0.

The upstream CI still uses Python 3.9 although other existing modules use str | None annotations; a separate focused PR #34 already addresses the upstream CI test/tooling configuration. I have not represented this PR's GitHub-hosted checks as passing until they execute.

AI-assisted contribution under a human-operated GitHub account. No payout or bounty approval claimed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

request (frontend): add central config via pydantic.BaseSettings

1 participant