Skip to content
Merged
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
Binary file modified docs/config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions docs/config.puml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class "PostgreSQLDatabaseConfiguration" as src.models.config.PostgreSQLDatabaseC
host : str
namespace : Optional[str]
password : str
port : int
port : Annotated
ssl_mode : str
user : str
check_postgres_configuration() -> Self
Expand All @@ -87,9 +87,9 @@ class "ServiceConfiguration" as src.models.config.ServiceConfiguration {
color_log : bool
cors
host : str
port : int
port : Annotated
tls_config
workers : int
workers : Annotated
check_service_configuration() -> Self
}
class "TLSConfiguration" as src.models.config.TLSConfiguration {
Expand Down
14 changes: 4 additions & 10 deletions src/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path
from typing import Optional

from pydantic import BaseModel, model_validator, FilePath, AnyHttpUrl
from pydantic import BaseModel, model_validator, FilePath, AnyHttpUrl, PositiveInt
from typing_extensions import Self, Literal

import constants
Expand Down Expand Up @@ -58,7 +58,7 @@ class PostgreSQLDatabaseConfiguration(BaseModel):
"""PostgreSQL database configuration."""

host: str = "localhost"
port: int = 5432
port: PositiveInt = 5432
db: str
user: str
password: str
Expand All @@ -70,8 +70,6 @@ class PostgreSQLDatabaseConfiguration(BaseModel):
@model_validator(mode="after")
def check_postgres_configuration(self) -> Self:
"""Check PostgreSQL configuration."""
if self.port <= 0:
raise ValueError("Port value should not be negative")
if self.port > 65535:
raise ValueError("Port value should be less than 65536")
if self.ca_cert_path is not None and not self.ca_cert_path.exists():
Expand Down Expand Up @@ -124,9 +122,9 @@ class ServiceConfiguration(BaseModel):
"""Service configuration."""

host: str = "localhost"
port: int = 8080
port: PositiveInt = 8080
auth_enabled: bool = False
workers: int = 1
workers: PositiveInt = 1
color_log: bool = True
access_log: bool = True
tls_config: TLSConfiguration = TLSConfiguration()
Expand All @@ -135,12 +133,8 @@ class ServiceConfiguration(BaseModel):
@model_validator(mode="after")
def check_service_configuration(self) -> Self:
"""Check service configuration."""
if self.port <= 0:
raise ValueError("Port value should not be negative")
if self.port > 65535:
raise ValueError("Port value should be less than 65536")
if self.workers < 1:
raise ValueError("Workers must be set to at least 1")
return self


Expand Down
4 changes: 2 additions & 2 deletions tests/unit/models/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_service_configuration_constructor() -> None:

def test_service_configuration_port_value() -> None:
"""Test the ServiceConfiguration port value validation."""
with pytest.raises(ValueError, match="Port value should not be negative"):
with pytest.raises(ValidationError, match="Input should be greater than 0"):
ServiceConfiguration(port=-1)

with pytest.raises(ValueError, match="Port value should be less than 65536"):
Expand All @@ -57,7 +57,7 @@ def test_service_configuration_port_value() -> None:

def test_service_configuration_workers_value() -> None:
"""Test the ServiceConfiguration workers value validation."""
with pytest.raises(ValueError, match="Workers must be set to at least 1"):
with pytest.raises(ValidationError, match="Input should be greater than 0"):
ServiceConfiguration(workers=-1)


Expand Down