refactor(shared): explode config into multiple files (#1987)
This commit is contained in:
parent
c395fd7f0a
commit
e75426bc4c
3 changed files with 75 additions and 63 deletions
65
shared/libretime_shared/config/_models.py
Normal file
65
shared/libretime_shared/config/_models.py
Normal file
|
@ -0,0 +1,65 @@
|
|||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
# pylint: disable=no-name-in-module
|
||||
from pydantic import AnyHttpUrl, BaseModel, validator
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pydantic.typing import AnyClassMethod
|
||||
|
||||
|
||||
def no_trailing_slash_validator(key: str) -> "AnyClassMethod":
|
||||
# pylint: disable=unused-argument
|
||||
def strip_trailing_slash(cls: Any, value: str) -> str:
|
||||
return value.rstrip("/")
|
||||
|
||||
return validator(key, pre=True, allow_reuse=True)(strip_trailing_slash)
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class GeneralConfig(BaseModel):
|
||||
public_url: AnyHttpUrl
|
||||
api_key: str
|
||||
|
||||
# Validators
|
||||
_public_url_no_trailing_slash = no_trailing_slash_validator("public_url")
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class StorageConfig(BaseModel):
|
||||
path: str = "/srv/libretime"
|
||||
|
||||
# Validators
|
||||
_path_no_trailing_slash = no_trailing_slash_validator("path")
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class DatabaseConfig(BaseModel):
|
||||
host: str = "localhost"
|
||||
port: int = 5432
|
||||
name: str = "libretime"
|
||||
user: str = "libretime"
|
||||
password: str = "libretime"
|
||||
|
||||
@property
|
||||
def url(self) -> str:
|
||||
return (
|
||||
f"postgresql://{self.user}:{self.password}"
|
||||
f"@{self.host}:{self.port}/{self.name}"
|
||||
)
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class RabbitMQConfig(BaseModel):
|
||||
host: str = "localhost"
|
||||
port: int = 5672
|
||||
name: str = "libretime"
|
||||
user: str = "libretime"
|
||||
password: str = "libretime"
|
||||
vhost: str = "/libretime"
|
||||
|
||||
@property
|
||||
def url(self) -> str:
|
||||
return (
|
||||
f"amqp://{self.user}:{self.password}"
|
||||
f"@{self.host}:{self.port}/{self.vhost}"
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue