feat(node-agent): add /containers and /sidecar/:id/logs endpoints

This commit is contained in:
Wild Dragon Dev 2026-06-04 01:40:44 +00:00
parent 8efcf5c545
commit a90adb5b52

View file

@ -856,6 +856,15 @@ async function handleSidecarStop(containerId, res) {
} }
} }
async function handleSidecarLogs(containerId, res) {
try {
const logs = await fetchContainerLogs(containerId);
jsonResponse(res, 200, { logs: logs || '(no logs)' });
} catch (err) {
jsonResponse(res, 500, { error: err.message });
}
}
async function handleSidecarStatus(containerId, res) { async function handleSidecarStatus(containerId, res) {
try { try {
const inspectRes = await dockerApi('GET', `/containers/${containerId}/json`); const inspectRes = await dockerApi('GET', `/containers/${containerId}/json`);
@ -1458,6 +1467,15 @@ const server = http.createServer((req, res) => {
const id = pathname.slice('/sidecar/'.length, -'/status'.length); const id = pathname.slice('/sidecar/'.length, -'/status'.length);
handleSidecarStatus(id, res); handleSidecarStatus(id, res);
} else if (req.method === 'GET' && pathname === '/containers') {
if (!checkAgentAuth(req)) return jsonResponse(res, 401, { error: 'Unauthorized' });
const cRes = await dockerApi('GET', '/containers/json?all=true');
jsonResponse(res, cRes.status, cRes.data);
} else if (req.method === 'GET' && /^\/sidecar\/[^/]+\/logs$/.test(pathname)) {
const id = pathname.slice('/sidecar/'.length, -'/logs'.length);
handleSidecarLogs(id, res);
} else if (req.method === 'GET' && pathname === '/driver/status') { } else if (req.method === 'GET' && pathname === '/driver/status') {
if (!checkAgentAuth(req)) return jsonResponse(res, 401, { error: 'Unauthorized' }); if (!checkAgentAuth(req)) return jsonResponse(res, 401, { error: 'Unauthorized' });
handleDriverStatus(res); handleDriverStatus(res);