[rewrite] Work on user registration, slightly polished schemas structure
This commit is contained in:
1 parent
5d12391635
commit
9e56eeca3f
12 files changed
+381
-39
No files matched your search
@@ -35,7 +35,7 @@ class EnvConfigField():
|
||||
regex: Optional[str] = None,
|
||||
parser: Optional[Callable[[str], Any]] = None,
|
||||
):
|
||||
self.value = None
|
||||
self.env_value = None
|
||||
self.env_name = env_name
|
||||
self.data_type = data_type
|
||||
self.default = default
|
||||
@@ -56,7 +56,7 @@ class EnvConfigField():
|
||||
env_name=self.env_name,
|
||||
)
|
||||
|
||||
self.value = self.validate(raw_value)
|
||||
self.env_value = self.validate(raw_value)
|
||||
|
||||
def validate(self, value: Any) -> Any:
|
||||
"""Validates the value based on provided constraints."""
|
||||
@@ -90,7 +90,7 @@ class EnvConfigField():
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
return self.value
|
||||
return self.env_value
|
||||
|
||||
@value.setter
|
||||
def value(self, new):
|
||||
@@ -155,7 +155,17 @@ class EnvConfigField():
|
||||
value=value)
|
||||
|
||||
|
||||
class EnvConfig():
|
||||
class EnvConfig:
|
||||
"""Singleton configuration loader for environment variables."""
|
||||
|
||||
_instance = None
|
||||
|
||||
def __new__(cls):
|
||||
"""Ensures only one instance of EnvConfig is created."""
|
||||
if cls._instance is None:
|
||||
cls._instance = super().__new__(cls)
|
||||
return cls._instance
|
||||
|
||||
def __init__(self):
|
||||
self.logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -172,13 +182,13 @@ class EnvConfig():
|
||||
|
||||
for field in self.fields.values():
|
||||
try:
|
||||
field.load
|
||||
field.load()
|
||||
except ConfigError as e:
|
||||
self.logger.error("Configuration error: %s", e)
|
||||
raise
|
||||
|
||||
def __getitem__(self, key: str):
|
||||
return self.fields["key"].value
|
||||
return self.fields[key].value
|
||||
|
||||
def __contains__(self, key: str) -> bool:
|
||||
return key in self.fields
|
||||
|
||||
Reference in new issue
Block a user