Files
TDI-Dashboard/Tool/config.py
T
Yan Xell 956f8aec56
ci/woodpecker/push/ci Pipeline failed
ci/woodpecker/tag/ci Pipeline failed
ci/woodpecker/tag/deploy-test Pipeline was successful
prevedi un postgres sql
2026-05-19 15:34:27 +02:00

64 lines
1.9 KiB
Python

import os
from collections import deque
from enum import StrEnum
from pathlib import Path
from dotenv import load_dotenv
# Tool/ is one level below RPA_dashboard/
REPORTS_DIR = Path(__file__).resolve().parent.parent
load_dotenv(REPORTS_DIR / '.env')
TMPL_DIR = REPORTS_DIR / "templates"
CSS_PATH = REPORTS_DIR / "static" / "css" / "style.css"
PAGES_CSS_DIR = REPORTS_DIR / "static" / "css"
JS_DIR = REPORTS_DIR / "static" / "js"
class DbType(StrEnum):
REG_LOMB = 'reg_Lomb'
INTRAZ = 'Intraz'
UNKNOWN = 'unknown'
class ConnType(StrEnum):
SQLITE = 'sqlite'
POSTGRES = 'postgres'
_db_dir_env = os.environ.get('RPA_DB_DIR', '')
DB_DEFAULT_DIR = Path(_db_dir_env) if _db_dir_env else REPORTS_DIR.parent / "data_rpa" / "db"
try:
LOGS_PER_PAGE = max(1, int(os.environ.get('LOGS_ROWS', '30').strip()))
except (ValueError, TypeError):
LOGS_PER_PAGE = 30
try:
STEPS_ROWS = max(1, int(os.environ.get('STEPS_ROWS', '15').strip()))
except (ValueError, TypeError):
STEPS_ROWS = 15
_access_log: deque = deque(maxlen=200)
_state: dict = {'db_path': '', 'db_type': DbType.UNKNOWN}
# Authentication — mutable so settings can be updated at runtime
_auth: dict = {
'enabled': os.environ.get('LOGIN', 'true').strip().lower() != 'false',
'user': os.environ.get('DASHBOARD_USER', ''),
'password': os.environ.get('DASHBOARD_PASSWORD', ''),
}
_sessions: set = set() # active session tokens
# Database connection — mutable so settings can be updated at runtime
_conn_type_raw = os.environ.get('RPA_CONN_TYPE', 'sqlite').strip().lower()
_conn: dict = {
'type': ConnType.POSTGRES if _conn_type_raw == 'postgres' else ConnType.SQLITE,
'pg_host': os.environ.get('PG_HOST', 'localhost'),
'pg_port': os.environ.get('PG_PORT', '5432'),
'pg_db': os.environ.get('PG_DB', ''),
'pg_user': os.environ.get('PG_USER', ''),
'pg_password': os.environ.get('PG_PASSWORD', ''),
}