-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
57 lines (48 loc) · 1.68 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
import os
from dotenv import load_dotenv
class Config:
def __init__(self, env_file=".env"):
"""
Initializes the Config object by loading environment
variables from the .env file.
"""
load_dotenv(env_file)
self.__port = int(os.getenv("PORT", 5000))
self.__kafka_conf = {
"bootstrap.servers": os.getenv("KAFKA_BOOTSTRAP_SERVERS", "localhost:9092"),
"client.id": os.getenv("KAFKA_CLIENT_ID", "mini-redis-app"),
}
self.__kafka_topic = os.getenv("KAFKA_TOPIC", "mini_redis_changes")
self.__data_storage_file = os.getenv("DATA_STORAGE_FILE", "data.json")
self.__update_message_broker = bool(os.getenv("UPDATE_MESSAGE_BROKER", False))
self.__debug = bool(os.getenv("DEBUG", False))
def get_port(self) -> int:
"""
Gets the port number from the configuration.
"""
return self.__port
def get_kafka_conf(self) -> dict:
"""
Gets the Kafka configuration dictionary.
"""
return self.__kafka_conf
def get_kafka_topic(self) -> str:
"""
Gets the Kafka topic name where the latest shall be sent.
"""
return self.__kafka_topic
def get_data_storage_file(self) -> str:
"""
Gets the file path for data storage.
"""
return self.__data_storage_file
def get_update_message_broker(self) -> bool:
"""
Checks if message broker updates should be make.
"""
return self.__update_message_broker
def get_debug(self) -> bool:
"""
Checks whether to run the server in DEBUG mode or not
"""
return self.__debug