33from pathlib import Path
44from typing import Optional
55
6- from pydantic import BaseModel , model_validator , FilePath , AnyHttpUrl
6+ from pydantic import BaseModel , model_validator , FilePath , AnyHttpUrl , PositiveInt
77from typing_extensions import Self , Literal
88
99import constants
@@ -58,7 +58,7 @@ class PostgreSQLDatabaseConfiguration(BaseModel):
5858 """PostgreSQL database configuration."""
5959
6060 host : str = "localhost"
61- port : int = 5432
61+ port : PositiveInt = 5432
6262 db : str
6363 user : str
6464 password : str
@@ -70,8 +70,6 @@ class PostgreSQLDatabaseConfiguration(BaseModel):
7070 @model_validator (mode = "after" )
7171 def check_postgres_configuration (self ) -> Self :
7272 """Check PostgreSQL configuration."""
73- if self .port <= 0 :
74- raise ValueError ("Port value should not be negative" )
7573 if self .port > 65535 :
7674 raise ValueError ("Port value should be less than 65536" )
7775 if self .ca_cert_path is not None and not self .ca_cert_path .exists ():
@@ -124,9 +122,9 @@ class ServiceConfiguration(BaseModel):
124122 """Service configuration."""
125123
126124 host : str = "localhost"
127- port : int = 8080
125+ port : PositiveInt = 8080
128126 auth_enabled : bool = False
129- workers : int = 1
127+ workers : PositiveInt = 1
130128 color_log : bool = True
131129 access_log : bool = True
132130 tls_config : TLSConfiguration = TLSConfiguration ()
@@ -135,12 +133,8 @@ class ServiceConfiguration(BaseModel):
135133 @model_validator (mode = "after" )
136134 def check_service_configuration (self ) -> Self :
137135 """Check service configuration."""
138- if self .port <= 0 :
139- raise ValueError ("Port value should not be negative" )
140136 if self .port > 65535 :
141137 raise ValueError ("Port value should be less than 65536" )
142- if self .workers < 1 :
143- raise ValueError ("Workers must be set to at least 1" )
144138 return self
145139
146140
0 commit comments