update FDISK sync

This commit is contained in:
Matthias Hochmeister
2026-03-13 10:27:57 +01:00
parent 501b697ca2
commit 11fb533ad6
6 changed files with 273 additions and 1 deletions

View File

@@ -13,6 +13,7 @@
import { Router, Request, Response } from 'express';
import { z } from 'zod';
import axios from 'axios';
import { authenticate } from '../middleware/auth.middleware';
import { requirePermission } from '../middleware/rbac.middleware';
import { auditExport } from '../middleware/audit.middleware';
@@ -167,3 +168,49 @@ router.get(
);
export default router;
// ---------------------------------------------------------------------------
// FDISK Sync proxy — forwards to the fdisk-sync sidecar service
// ---------------------------------------------------------------------------
const FDISK_SYNC_URL = process.env.FDISK_SYNC_URL ?? '';
router.get(
'/fdisk-sync/logs',
authenticate,
requirePermission('admin:access'),
async (_req: Request, res: Response): Promise<void> => {
if (!FDISK_SYNC_URL) {
res.status(503).json({ success: false, message: 'FDISK sync service not configured' });
return;
}
try {
const response = await axios.get(`${FDISK_SYNC_URL}/logs`, { timeout: 5000 });
res.json({ success: true, data: response.data });
} catch {
res.status(502).json({ success: false, message: 'Could not reach sync service' });
}
}
);
router.post(
'/fdisk-sync/trigger',
authenticate,
requirePermission('admin:access'),
async (_req: Request, res: Response): Promise<void> => {
if (!FDISK_SYNC_URL) {
res.status(503).json({ success: false, message: 'FDISK sync service not configured' });
return;
}
try {
const response = await axios.post(`${FDISK_SYNC_URL}/trigger`, {}, { timeout: 5000 });
res.json({ success: true, data: response.data });
} catch (err: unknown) {
if (axios.isAxiosError(err) && err.response?.status === 409) {
res.status(409).json({ success: false, message: 'Sync already in progress' });
return;
}
res.status(502).json({ success: false, message: 'Could not reach sync service' });
}
}
);