feat: add YAML configuration with defaults
This commit is contained in:
parent
829e842d09
commit
4d398654cb
@ -7,5 +7,6 @@ COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY src /app
|
||||
COPY config/config.yaml /app
|
||||
|
||||
CMD ["python", "main.py"]
|
@ -0,0 +1,2 @@
|
||||
host: 0.0.0.0
|
||||
port: 9999
|
@ -1,2 +1,3 @@
|
||||
loguru
|
||||
SQLAlchemy
|
||||
PyYAML
|
||||
SQLAlchemy
|
@ -3,6 +3,7 @@ import socket
|
||||
import threading
|
||||
import database
|
||||
from database.models import Agent
|
||||
from utils.config import load_yaml_config
|
||||
from loguru import logger
|
||||
from datetime import datetime
|
||||
|
||||
@ -162,5 +163,8 @@ class Server:
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
server = Server("0.0.0.0", 9999)
|
||||
# Load config.yaml if it exists
|
||||
config = load_yaml_config("config.yaml")
|
||||
|
||||
server = Server(config.get("host", "0.0.0.0"), config.get("port", 9999))
|
||||
server.start()
|
||||
|
28
server/src/utils/config.py
Normal file
28
server/src/utils/config.py
Normal file
@ -0,0 +1,28 @@
|
||||
import yaml
|
||||
|
||||
|
||||
def load_yaml_config(file_path):
|
||||
"""
|
||||
Loads a YAML configuration file.
|
||||
|
||||
This function loads a YAML configuration file and returns the
|
||||
configuration data as a dictionary. If the file does not exist,
|
||||
or there is an error loading the file, the function will return
|
||||
a default configuration.
|
||||
|
||||
Args:
|
||||
file_path (str): The path to the YAML configuration file.
|
||||
|
||||
Returns:
|
||||
dict: A dictionary containing the configuration data.
|
||||
"""
|
||||
try:
|
||||
with open(file_path, "r") as f:
|
||||
config = yaml.safe_load(f)
|
||||
except Exception as e:
|
||||
config = {
|
||||
"host": "0.0.0.0",
|
||||
"port": 9999
|
||||
}
|
||||
|
||||
return config
|
Loading…
Reference in New Issue
Block a user