Watch
0
0
Fork
You've already forked hyperhive
0

make squid's allowed domains editable at runtime in the swarm ui

This commit is contained in:
atlas 2026-10-28 20:39:22 +01:00 • committed by mara
commit c9abc2a42b

View file

@ -0,0 +1,52 @@
// The detail panel's allowed-domains editor: which entries one agent's panel
// shows and the bodies it sends. Kept out of the component so `npm test` can
// run it.
/** One entry as `GET /api/egress/allowed-domains` carries it. */
export interface AllowedDomain {
domain: string;
/** Absent for an entry that holds for every agent in the swarm. */
agent?: string;
}
export const ALLOWED_DOMAINS_URL = "/api/egress/allowed-domains";
/**
* The entries that apply to `agent`: the swarm-wide ones first, then the ones
* for this agent alone. Entries for other agents are not shown on this panel.
*/
export function entriesFor(
entries: AllowedDomain[],
agent: string,
): AllowedDomain[] {
const swarmWide = entries.filter((e) => e.agent === undefined);
const own = entries.filter((e) => e.agent === agent);
return [...swarmWide, ...own];
}
/** What the panel says about a list of entries. */
export function allowedSummary(shown: AllowedDomain[]): string {
if (shown.length === 0) return "none added";
const swarmWide = shown.filter((e) => e.agent === undefined).length;
const own = shown.length - swarmWide;
return [
swarmWide > 0 ? `${swarmWide} swarm-wide` : null,
own > 0 ? `${own} for this agent` : null,
]
.filter((part) => part !== null)
.join(", ");
}
/**
* The body that adds or removes `domain`, as typed: the route lower-cases it
* and refuses what is not a name. `forSwarm` makes it hold for every agent;
* otherwise it is for `agent` alone.
*/
export function entryBody(
domain: string,
forSwarm: boolean,
agent: string,
): AllowedDomain {
const name = domain.trim();
return forSwarm ? { domain: name } : { domain: name, agent };
}