Build [v1.14.22]
This commit is contained in:
@@ -15,6 +15,7 @@ import socket
|
||||
import subprocess
|
||||
from .. import models, schemas, database, auth
|
||||
from ..config_loader import get_config
|
||||
from ..config_manager import ConfigManager
|
||||
from ..logger import log
|
||||
|
||||
router = APIRouter(prefix="/users", tags=["auth"])
|
||||
@@ -265,14 +266,27 @@ def update_ldap_settings(
|
||||
current_user: auth.TokenData = Depends(auth.get_current_admin)
|
||||
):
|
||||
"""[C-01] Update LDAP config — admin only."""
|
||||
root_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
config_dir = os.path.join(root_dir, "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, indent=2)
|
||||
log.info(f"LDAP config updated by {current_user.username}")
|
||||
return {"message": "Config saved"}
|
||||
# Map frontend keys back to backend YAML structure
|
||||
updates = {
|
||||
"auth": {
|
||||
"ldap_enabled": config.get("ldap_enabled", False),
|
||||
"ldap_server": config.get("server_uri", ""),
|
||||
"ldap_base_dn": config.get("base_dn", ""),
|
||||
"ldap_user_template": config.get("user_template", ""),
|
||||
"ldap_groups_dn": config.get("groups_dn", ""),
|
||||
"ldap_use_tls": config.get("use_tls", True),
|
||||
"ldap_ignore_cert": config.get("ignore_cert", False),
|
||||
"ldap_role_mappings": config.get("role_mappings", [])
|
||||
}
|
||||
}
|
||||
|
||||
try:
|
||||
ConfigManager.update_config(updates)
|
||||
log.info(f"LDAP config updated in backend.yaml by {current_user.username}")
|
||||
return {"message": "Config saved successfully"}
|
||||
except Exception as e:
|
||||
log.error(f"Failed to update LDAP config: {e}")
|
||||
raise HTTPException(status_code=500, detail=f"Failed to save configuration: {str(e)}")
|
||||
|
||||
|
||||
@router.post("/test-ldap")
|
||||
|
||||
Reference in New Issue
Block a user