-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
51 lines (39 loc) · 1.7 KB
/
config.py
File metadata and controls
51 lines (39 loc) · 1.7 KB
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
"""
Configuration management for the Minecraft Dashboard.
This module loads sensitive configuration (like RCON passwords) from environment variables.
The .env file is git-ignored, so your secrets stay local and don't get pushed to GitHub.
"""
import os
from dotenv import load_dotenv
# Load environment variables from .env file
# This reads the .env file and makes those values available via os.getenv()
load_dotenv()
class Config:
"""
Configuration settings loaded from environment variables.
If you need to change these values, edit the .env file, not this file.
"""
# Minecraft server connection details
MC_SERVER_HOST: str = os.getenv("MC_SERVER_HOST", "localhost")
MC_RCON_PORT: int = int(os.getenv("MC_RCON_PORT", "25575"))
MC_RCON_PASSWORD: str = os.getenv("MC_RCON_PASSWORD", "")
# Database configuration
DB_PATH: str = os.getenv("DB_PATH", "data/minecraft_dashboard.db")
# SSH configuration for remote metrics collection
SSH_HOST: str = os.getenv("SSH_HOST", "localhost")
SSH_PORT: int = int(os.getenv("SSH_PORT", "22"))
SSH_USER: str = os.getenv("SSH_USER", "ubuntu")
SSH_KEY_PATH: str = os.getenv("SSH_KEY_PATH", "~/.ssh/mc_dashboard_key")
MC_SERVER_DIR: str = os.getenv("MC_SERVER_DIR", "/home/ubuntu/minecraft")
@classmethod
def validate(cls) -> None:
"""
Check that required configuration is present.
Raises an error if RCON password is not set.
"""
if not cls.MC_RCON_PASSWORD or cls.MC_RCON_PASSWORD == "changeme":
raise ValueError(
"MC_RCON_PASSWORD not set! Please edit .env file with your RCON password."
)
# Create a global config instance
config = Config()