From 784b9fb225c119df42eb8db45de6d8c99572bde3 Mon Sep 17 00:00:00 2001 From: Jonas L Date: Wed, 2 Feb 2022 08:04:48 +0100 Subject: [PATCH] feat(shared): add url/dsn property to config classes (#1553) --- shared/libretime_shared/config.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/shared/libretime_shared/config.py b/shared/libretime_shared/config.py index abb49729c..18de14728 100644 --- a/shared/libretime_shared/config.py +++ b/shared/libretime_shared/config.py @@ -107,6 +107,13 @@ class DatabaseConfig(BaseModel): 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): @@ -116,3 +123,10 @@ class RabbitMQConfig(BaseModel): 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.lstrip('/')}" + )