Use saved SMB credentials for AI structure
CI / python (push) Has been cancelled
CI / rust (push) Has been cancelled

This commit is contained in:
2026-05-21 23:43:40 +03:00
parent 9ea2ff5518
commit 65a1437c7c
7 changed files with 300 additions and 15 deletions
+42 -1
View File
@@ -284,6 +284,40 @@ _neo4j_user = os.environ.get("NEO4J_USER", "neo4j")
_neo4j_password = os.environ.get("NEO4J_PASSWORD", "password")
_EVENT_SUBSCRIPTION_KIND = getattr(NodeKind, "EVENT_SUBSCRIPTION", None)
def _load_ai_structure_smb_credentials(project_id: str) -> dict[str, str] | None:
try:
payload = _storage.read_document("ai_structure_smb_credentials", project_id)
except FileNotFoundError:
return None
password_value = str(payload.get("password_b64") or "")
try:
password = base64.b64decode(password_value.encode("ascii")).decode("utf-8") if password_value else ""
except (ValueError, UnicodeDecodeError):
password = ""
username = str(payload.get("username") or "")
if not username and not password:
return None
return {
"username": username,
"domain": str(payload.get("domain") or ""),
"password": password,
}
def _save_ai_structure_smb_credentials(project_id: str, credentials: dict[str, str]) -> None:
password = str(credentials.get("password") or "")
_storage.write_document(
"ai_structure_smb_credentials",
project_id,
{
"project_id": project_id,
"username": str(credentials.get("username") or ""),
"domain": str(credentials.get("domain") or ""),
"password_b64": base64.b64encode(password.encode("utf-8")).decode("ascii"),
},
)
_ACCESS_TARGET_KINDS = {
NodeKind.CATALOG,
NodeKind.DOCUMENT,
@@ -1585,7 +1619,11 @@ async def html5_project_access(project_id: str, profile: str | None = None) -> R
@app.get("/html5/projects/{project_id}/ai-structure")
async def html5_project_ai_structure(project_id: str) -> Response:
return _html5_response(
_html5_ai_structure_page(project_id=project_id, project_summaries=_project_summaries)
_html5_ai_structure_page(
project_id=project_id,
project_summaries=_project_summaries,
load_credentials=_load_ai_structure_smb_credentials,
)
)
@@ -1597,6 +1635,9 @@ async def html5_project_ai_structure_run(project_id: str, request: Request) -> R
project_id=project_id,
form=form,
prepare=_prepare_ai_structure,
work_root=_storage.root / "ai_structure_work",
load_credentials=_load_ai_structure_smb_credentials,
save_credentials=_save_ai_structure_smb_credentials,
)
)