From 02a495190146781eb4518f4b3214fe7033ef8eaf Mon Sep 17 00:00:00 2001 From: Daniel Bedeleanu Date: Sat, 11 Apr 2026 15:06:56 +0300 Subject: [PATCH] refactor: centralize configuration in backend/config/ and frontend/config/ - Move ldap_config.json from ./data/ to backend/config/ - Update users.py to read LDAP config from backend/config/ldap_config.json - Create frontend/config/ directory for future frontend configs - DATA_DIR still used for database and runtime files in ./data/ - Update .gitignore to track backend/config/ but ignore runtime data dirs --- .gitignore | 3 ++- backend/config/ldap_config.json | 1 + backend/routers/users.py | 11 ++++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 backend/config/ldap_config.json diff --git a/.gitignore b/.gitignore index 2b97914f..ff109556 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ backend/venv/ backend/data/ +backend/logs/ +frontend/logs/ __pycache__/ *.pyc .env @@ -7,4 +9,3 @@ __pycache__/ aInventory-PROD* aInventory-PROD*.zip logs/ -backend/logs/ diff --git a/backend/config/ldap_config.json b/backend/config/ldap_config.json new file mode 100644 index 00000000..85fb8642 --- /dev/null +++ b/backend/config/ldap_config.json @@ -0,0 +1 @@ +{"ldap_enabled": true, "server_uri": "ldap://192.168.84.107:3890", "base_dn": "dc=example,dc=com", "user_template": "cn={username},ou=people,dc=example,dc=com", "groups_dn": "ou=groups", "use_tls": false, "role_mappings": [{"group": "inventory_admins", "role": "admin"}, {"group": "inventory_users", "role": "user"}]} diff --git a/backend/routers/users.py b/backend/routers/users.py index d4ad135a..f10c724e 100644 --- a/backend/routers/users.py +++ b/backend/routers/users.py @@ -14,7 +14,9 @@ router = APIRouter(prefix="/users", tags=["users"]) pwd_context = CryptContext(schemes=["pbkdf2_sha256"], deprecated="auto") def get_ldap_config(): - config_path = os.path.join(database.DATA_DIR, "ldap_config.json") + # Read from backend/config/ directory + config_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "config") + config_path = os.path.join(config_dir, "ldap_config.json") if os.path.exists(config_path): with open(config_path, "r") as f: return json.load(f) @@ -268,9 +270,12 @@ def update_ldap_settings( current_user: auth.TokenData = Depends(auth.get_current_admin) ): """[C-01] Update LDAP config — admin only.""" - config_path = os.path.join(database.DATA_DIR, "ldap_config.json") + config_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "config") + os.makedirs(config_dir, exist_ok=True) + config_path = os.path.join(config_dir, "ldap_config.json") with open(config_path, "w") as f: - json.dump(config, f) + json.dump(config, f, indent=2) + log.info(f"LDAP config updated by {current_user.username}") return {"message": "Config saved"} @router.post("/test-ldap")