-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
75 lines (58 loc) · 1.88 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""
Configurations for application. These are global variables that the app will use in its entire
lifetime
"""
from functools import lru_cache
from typing import Optional, AnyStr
from pydantic import BaseSettings
from dotenv import load_dotenv
load_dotenv()
def load_from_file(path: str, mode: str, encoding: str) -> AnyStr:
"""
Convenience function that reads contents of a file
@param path file path
@param mode file mode to use when opening file
@param encoding file encoding
@returns contents of the file
"""
with open(file=path, mode=mode, encoding=encoding) as file:
return file.read()
# pylint: disable=too-few-public-methods
class Config(BaseSettings):
"""
Application settings
You can overwrite any of these settings by having an environment
variable with the uppercased version of the name
"""
server_name: str = "Barua Pepe"
description: str = "Simple RESTful Email Server"
base_url: str = "/api/v1/baruapepe"
environment: str = "development"
docs_disabled: bool = False
# smtp settings
mail_smtp_enabled: bool = True
mail_server: str = "localhost"
mail_port: int = 1025
mail_use_tls: bool = False
mail_use_ssl: bool = False
mail_username: str = "baruapepe"
mail_password: str = "password"
# mail api settings
mail_api_token: str = ""
mail_api_url: str = ""
result_backend: Optional[str] = "rpc://"
# sentry settings
sentry_dsn: str = ""
sentry_enabled: bool = False
sentry_traces_sample_rate: float = 0.5
sentry_debug_enabled: bool = False
# security settings
username: str = "barua-pepe-user"
password: str = "barua-pepe-password"
config = Config()
@lru_cache()
def get_config():
"""
Gets configuration This is wrapped with lru_cache to ensure we don't continuously read from .env file on restarts
"""
return Config()