mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-18 22:36:19 +00:00
1803512f70
* feat(labels): drop tier gate to Community for organization endpoints Stack Labels CRUD and per-stack assignment are now Community-tier features: list, create, update, delete labels, and assign labels to a single stack. The two automation surfaces stay Skipper+: per-label bulk deploy / stop / restart (POST /api/labels/:id/action) and the Fleet Actions tab's bulk-assign card (POST /api/fleet-actions/labels/bulk-assign). Tier story is now organize free, automate paid. Add a route-level test that proves the CRUD endpoints succeed on a Community license while the bulk-action endpoint still returns 403. Update overview, licensing, and stack-labels docs to reflect the new tier placement and to note that bulk actions on a label still require Skipper or Admiral. * feat(topology): drop tier gate to Community for network topology view The Resources tab's Networks > Topology view is now available on every tier. Drops requirePaid from GET /api/system/networks/topology, removes the isPaid wrapper around the List | Topology toggle in ResourcesView, and removes the PaidGate around the topology graph. CapabilityGate stays in place so a node running on a build without the network-topology capability still renders its lock card instead of the graph. Add a route-level test that proves the endpoint returns 200 on a Community license. Update licensing and resources docs to reflect the new tier placement. * fix(labels): expose Settings > Labels tab on Community tier The settings registry entry for the Labels tab still carried tier: 'skipper', which kept the tab hidden in the Settings sidebar even though the underlying CRUD endpoints now serve Community. Drop the tier flag so Community users can discover and reach the section that backs the already-Community-tier label endpoints.
69 lines
3.3 KiB
TypeScript
69 lines
3.3 KiB
TypeScript
import { Router, type Request, type Response } from 'express';
|
|
import { DatabaseService } from '../services/DatabaseService';
|
|
import { authMiddleware } from '../middleware/auth';
|
|
import { requirePaid, requireAdmin, requireBody } from '../middleware/tierGates';
|
|
import { isValidStackName } from '../utils/validation';
|
|
import { getErrorMessage } from '../utils/errors';
|
|
|
|
// Per-node fleet-action endpoints. Mounted under `/api/fleet-actions/`, which
|
|
// is NOT in `PROXY_EXEMPT_PREFIXES`, so when `x-node-id` targets a remote node
|
|
// the gateway proxies the call and the remote Sencho instance runs its own
|
|
// local handler. Multi-node orchestration endpoints live in `routes/fleet.ts`
|
|
// because their path must sit behind the `/api/fleet/` proxy-exempt prefix.
|
|
export const fleetActionsRouter = Router();
|
|
|
|
// Hard cap to bound a single bulk-assign request. A node typically has tens of
|
|
// stacks, not thousands; the cap protects against accidental or malicious
|
|
// payloads that would force thousands of DB writes in one handler.
|
|
const MAX_ASSIGNMENTS = 1000;
|
|
|
|
// Bulk label assignment for many stacks on a single node. The single-stack
|
|
// endpoint at `PUT /api/stacks/:stackName/labels` covers one stack at a time;
|
|
// this wrapper applies the same operation to many stacks atomically per HTTP
|
|
// request. Tier: requirePaid + requireAdmin. The per-stack endpoint is
|
|
// Community-tier organization metadata; this multi-stack wrapper is an
|
|
// automation surface exposed only inside the Skipper+ Fleet Actions tab.
|
|
fleetActionsRouter.post(
|
|
'/labels/bulk-assign',
|
|
authMiddleware,
|
|
async (req: Request, res: Response): Promise<void> => {
|
|
if (!requirePaid(req, res)) return;
|
|
if (!requireAdmin(req, res)) return;
|
|
if (!requireBody(req, res)) return;
|
|
const { assignments } = req.body as { assignments?: unknown };
|
|
if (!Array.isArray(assignments)) {
|
|
res.status(400).json({ error: 'assignments must be an array' });
|
|
return;
|
|
}
|
|
if (assignments.length > MAX_ASSIGNMENTS) {
|
|
res.status(400).json({ error: `assignments may not exceed ${MAX_ASSIGNMENTS} entries` });
|
|
return;
|
|
}
|
|
const nodeId = req.nodeId ?? 0;
|
|
const db = DatabaseService.getInstance();
|
|
const results: { stackName: string; success: boolean; error?: string }[] = [];
|
|
for (const entry of assignments as unknown[]) {
|
|
if (!entry || typeof entry !== 'object') {
|
|
results.push({ stackName: '', success: false, error: 'Invalid assignment entry' });
|
|
continue;
|
|
}
|
|
const { stackName, labelIds } = entry as { stackName?: unknown; labelIds?: unknown };
|
|
if (typeof stackName !== 'string' || !isValidStackName(stackName)) {
|
|
results.push({ stackName: typeof stackName === 'string' ? stackName : '', success: false, error: 'Invalid stack name' });
|
|
continue;
|
|
}
|
|
if (!Array.isArray(labelIds) || !labelIds.every(id => typeof id === 'number')) {
|
|
results.push({ stackName, success: false, error: 'labelIds must be an array of numbers' });
|
|
continue;
|
|
}
|
|
try {
|
|
db.setStackLabels(stackName, nodeId, labelIds);
|
|
results.push({ stackName, success: true });
|
|
} catch (err) {
|
|
results.push({ stackName, success: false, error: getErrorMessage(err, 'Failed to set stack labels') });
|
|
}
|
|
}
|
|
res.json({ results });
|
|
},
|
|
);
|