feat(node-agent): add /containers and /sidecar/:id/logs endpoints
This commit is contained in:
parent
8efcf5c545
commit
a90adb5b52
1 changed files with 18 additions and 0 deletions
|
|
@ -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) {
|
||||
try {
|
||||
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);
|
||||
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') {
|
||||
if (!checkAgentAuth(req)) return jsonResponse(res, 401, { error: 'Unauthorized' });
|
||||
handleDriverStatus(res);
|
||||
|
|
|
|||
Loading…
Reference in a new issue