Coverage for filip/config.py: 100%
13 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-11-20 16:54 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-11-20 16:54 +0000
1"""
2Settings module to set url from .env.filip file. This can also seen as an
3example for other applications such as webapp that use the library. Using
4`*.env` belongs to best practices in containerized applications. Pydantic
5provides a convenient and clean way to manage environments.
6"""
7from pydantic import Field, AnyHttpUrl, AliasChoices, AnyUrl
8from pydantic_settings import BaseSettings, SettingsConfigDict
9from pathlib import Path
10import os
11from dotenv import find_dotenv
12ROOT_DIR = os.path.realpath(os.path.join(os.path.dirname(__file__), '..'))
15class Settings(BaseSettings):
16 """
17 Settings class that reads environment variables from a local `.env.filip`
18 file or environment variables. The `.env.filip` can be located anywhere
19 in the FiLiP repository.
20 """
21 model_config = SettingsConfigDict(env_file=find_dotenv(Path(ROOT_DIR) / '.env.filip'),
22 env_file_encoding='utf-8',
23 case_sensitive=False, extra="ignore")
25 CB_URL: AnyHttpUrl = Field(default="http://127.0.0.1:1026",
26 validation_alias=AliasChoices(
27 'ORION_URL', 'CB_URL', 'CB_HOST',
28 'CONTEXTBROKER_URL', 'OCB_URL'))
30 IOTA_URL: AnyHttpUrl = Field(default="http://127.0.0.1:4041",
31 validation_alias='IOTA_URL')
33 QL_URL: AnyHttpUrl = Field(default="http://127.0.0.1:8668",
34 validation_alias=AliasChoices('QUANTUMLEAP_URL', 'QL_URL'))
36 MQTT_BROKER_URL: AnyUrl = Field(default="mqtt://127.0.0.1:1883",
37 validation_alias=AliasChoices(
38 'MQTT_BROKER_URL',
39 'MQTT_URL',
40 'MQTT_BROKER'))
42# create settings object
43settings = Settings()