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:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,5 +1,7 @@
|
|||||||
backend/venv/
|
backend/venv/
|
||||||
backend/data/
|
backend/data/
|
||||||
|
backend/logs/
|
||||||
|
frontend/logs/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.pyc
|
*.pyc
|
||||||
.env
|
.env
|
||||||
@@ -7,4 +9,3 @@ __pycache__/
|
|||||||
aInventory-PROD*
|
aInventory-PROD*
|
||||||
aInventory-PROD*.zip
|
aInventory-PROD*.zip
|
||||||
logs/
|
logs/
|
||||||
backend/logs/
|
|
||||||
|
|||||||
1
backend/config/ldap_config.json
Normal file
1
backend/config/ldap_config.json
Normal 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"}]}
|
||||||
@@ -14,7 +14,9 @@ router = APIRouter(prefix="/users", tags=["users"])
|
|||||||
pwd_context = CryptContext(schemes=["pbkdf2_sha256"], deprecated="auto")
|
pwd_context = CryptContext(schemes=["pbkdf2_sha256"], deprecated="auto")
|
||||||
|
|
||||||
def get_ldap_config():
|
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):
|
if os.path.exists(config_path):
|
||||||
with open(config_path, "r") as f:
|
with open(config_path, "r") as f:
|
||||||
return json.load(f)
|
return json.load(f)
|
||||||
@@ -268,9 +270,12 @@ def update_ldap_settings(
|
|||||||
current_user: auth.TokenData = Depends(auth.get_current_admin)
|
current_user: auth.TokenData = Depends(auth.get_current_admin)
|
||||||
):
|
):
|
||||||
"""[C-01] Update LDAP config — admin only."""
|
"""[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:
|
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"}
|
return {"message": "Config saved"}
|
||||||
|
|
||||||
@router.post("/test-ldap")
|
@router.post("/test-ldap")
|
||||||
|
|||||||
Reference in New Issue
Block a user