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
This commit is contained in:
Daniel Bedeleanu
2026-04-11 15:06:56 +03:00
parent ac1703e6c2
commit 02a4951901
3 changed files with 11 additions and 4 deletions

3
.gitignore vendored
View File

@@ -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/

View File

@@ -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"}]}

View File

@@ -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")