Skip to content

rss.config

rss.config

Config

Bases: BaseModel

Configuration of rss

Source code in rss/config.py
class Config(BaseModel):
    """Configuration of rss"""

    base_url: str = "http://rss"
    """The base url the server is running on"""

    amqp_uri: str = "amqp://guest:guest@rabbitmq"
    """The amqp uri of the RabbitMQ broker"""

    db_uri: str = "sqlite://rss.db"
    """The database connection string"""

    cattle_drive_uri: str = "amqp://guest:guest@rabbitmq"
    """Connection to cattle grid"""

    testing_mode: bool = False
    """Enables testing mode"""

    @property
    def domain(self):
        """Returns the domain

        ```pycon
        >>> Config().domain
        'rss'

        ```
        """
        return urlparse(self.base_url).netloc

    @property
    def object_url(self):
        """Returns the URL start where objects will be server at

        ```pycon
        >>> Config().object_url
        'http://rss/objects/'

        ```
        """
        return urljoin(self.base_url, "/objects/")

amqp_uri: str = 'amqp://guest:guest@rabbitmq' class-attribute instance-attribute

The amqp uri of the RabbitMQ broker

base_url: str = 'http://rss' class-attribute instance-attribute

The base url the server is running on

cattle_drive_uri: str = 'amqp://guest:guest@rabbitmq' class-attribute instance-attribute

Connection to cattle grid

db_uri: str = 'sqlite://rss.db' class-attribute instance-attribute

The database connection string

domain property

Returns the domain

>>> Config().domain
'rss'

object_url property

Returns the URL start where objects will be server at

>>> Config().object_url
'http://rss/objects/'

testing_mode: bool = False class-attribute instance-attribute

Enables testing mode

load_config(filename='rss.toml')

Loads the configuration from filename

Parameters:

Name Type Description Default
filename str
'rss.toml'

Returns:

Type Description
Config
Source code in rss/config.py
def load_config(filename: str = "rss.toml") -> Config:
    """Loads the configuration from filename

    :param filename:
    :returns:
    """
    config = Config()

    if os.path.exists(filename):
        with open(filename, "rb") as fp:
            config = Config.model_validate(tomllib.load(fp))

    return config