Skip to content
Open
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
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,13 @@ repos:
rev: v0.8.1
hooks:
- id: ruff-format

- repo: local
hooks:
- id: pydantic-settings-export
name: Generate config documentation
entry: bash -c 'PYTHONPATH=$PWD pydantic-settings-export && python -c "import re; content = open(\"CONFIGURATION.md\").read(); content = re.sub(r\"/home/[^/]+/[^|]+/app\", \"./app\", content); open(\"CONFIGURATION.md\", \"w\").write(content)"'
language: system
# only run this hook if settings have changed
files: ^app/core/config\.py$
pass_filenames: false
27 changes: 27 additions & 0 deletions CONFIGURATION.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ docker compose build
docker compose up
```

See [CONFIGURATION.md](./CONFIGURATION.md) for available environment settings.

The application will be served on http://127.0.0.1:8009 (I.E. typing localhost/docs in your browser will load the swagger documentation)

Full list of APIs available you can check [here](https://editor.swagger.io/?url=https://gist.githubusercontent.com/JoleVLF/7f5771b23a44e508b82e47d5fafd9f9c/raw/)
Expand Down
34 changes: 28 additions & 6 deletions app/core/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic import AnyHttpUrl, field_validator
from pydantic import field_validator, ConfigDict, Field
from pydantic_settings import BaseSettings
from password_validator import PasswordValidator
from typing import Optional, Any
Expand All @@ -7,7 +7,10 @@


class Settings(BaseSettings):
PROJECT_ROOT: str = path.dirname(path.dirname(path.realpath(__file__)))
PROJECT_ROOT: str = Field(
default=path.dirname(path.dirname(path.realpath(__file__))),
description="The project directory. Used to find project files (e.g., assets). Auto-generated by default, but can be overridden if needed.",
)

REPORTING_GATEKEEPER_USERNAME: str
REPORTING_GATEKEEPER_PASSWORD: str
Expand Down Expand Up @@ -37,7 +40,7 @@ class Settings(BaseSettings):
"animals": "/FarmAnimals/",
"materials": "/AddRawMaterialOperations/",
"machines": "/AgriculturalMachines/",
"farm": "/Farm/"
"farm": "/Farm/",
}

PDF_DIRECTORY: str = "user_reports/"
Expand All @@ -59,11 +62,30 @@ def assemble_db_connection(cls, v: Optional[str], values) -> Any:
return url

PASSWORD_SCHEMA_OBJ: PasswordValidator = PasswordValidator()
PASSWORD_SCHEMA_OBJ.min(8).max(
100
).has().uppercase().has().lowercase().has().digits().has().no().spaces()
PASSWORD_SCHEMA_OBJ: PasswordValidator = Field(
default_factory=lambda: PasswordValidator()
.min(8)
.max(100)
.has()
.uppercase()
.has()
.lowercase()
.has()
.digits()
.has()
.no()
.spaces(),
exclude=True,
)
JWT_ACCESS_TOKEN_EXPIRATION_TIME: int
JWT_SIGNING_KEY: str

# https://docs.pydantic.dev/latest/concepts/config/
model_config = ConfigDict(
# allows PasswordValidator to be used as a field in the Settings class
arbitrary_types_allowed=True,
env_file=".env",
)


settings = Settings()
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[tool.pydantic_settings_export]
project_dir = "."
default_settings = ["app.core.config:Settings"]

[[tool.pydantic_settings_export.generators.markdown]]
paths = ["CONFIGURATION.md"]
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ alembic==1.13.1 # DB migrations
requests==2.32.3
psycopg2==2.9.9 # PSQL driver
password-validator==1.0 # Enforceable rules for passwords
pydantic-settings==2.2.1 # Pydantic settings options [donated to the python-org, not part of the main package anymore]
pydantic-settings==2.8.1 # Pydantic settings options [donated to the python-org, not part of the main package anymore]
passlib==1.7.4 # For password managment
PyJWT==2.8.0 # Instead of jose (has a CVE)
argon2_cffi==23.1.0 # Backend for Argon encryption
Expand All @@ -25,4 +25,4 @@ httpx==0.27.2
black==24.10.0 # Python formatter
ruff==0.8.1
pre-commit==4.0.1

pydantic-settings-export==1.0.3