Die Hostseite listet, welche Public und Private Keys sshkv dort verwaltet - direkt oder ueber eine Hostgruppe - mit Zustand als Punkt und Text. Ein Dry-Run je Host zeigt das Diff aller Benutzer dieses Hosts und rollt nach Bestaetigung aus. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
import { prisma } from "@/lib/db";
|
|
|
|
/** Auswahl fuer „Public Key ausrollen auf …“ (#016): Hosts mit Bootstrap und Hostgruppen. */
|
|
export async function zielAuswahl() {
|
|
const [hosts, gruppen] = await Promise.all([
|
|
prisma.host.findMany({
|
|
where: { archiviertAm: null },
|
|
select: { id: true, name: true, bootstrapAm: true },
|
|
orderBy: { name: "asc" },
|
|
}),
|
|
prisma.hostgruppe.findMany({
|
|
select: { id: true, name: true, _count: { select: { mitglieder: true } } },
|
|
orderBy: { name: "asc" },
|
|
}),
|
|
]);
|
|
return {
|
|
hosts: hosts.map((h) => ({ id: h.id, name: h.name, bereit: h.bootstrapAm !== null })),
|
|
gruppen: gruppen.map((g) => ({ id: g.id, name: g.name, mitglieder: g._count.mitglieder })),
|
|
};
|
|
}
|
|
|
|
export type ZielAuswahl = Awaited<ReturnType<typeof zielAuswahl>>;
|
|
|
|
/** Was sshkv auf einem Host verwaltet (#016): Public Keys direkt und ueber Gruppen. */
|
|
export async function verwendungenAufHost(hostId: string) {
|
|
const [oeffentlich, privat] = await Promise.all([
|
|
prisma.publicVerwendung.findMany({
|
|
where: {
|
|
zustand: { not: "ENTFERNT" },
|
|
OR: [{ hostId }, { hostgruppe: { mitglieder: { some: { hostId } } } }],
|
|
},
|
|
select: {
|
|
id: true,
|
|
zielbenutzer: true,
|
|
optionen: true,
|
|
zustand: true,
|
|
hostgruppe: { select: { name: true } },
|
|
schluessel: { select: { id: true, name: true, typ: true, fingerprint: true } },
|
|
},
|
|
orderBy: [{ zielbenutzer: "asc" }, { angelegtAm: "asc" }],
|
|
}),
|
|
prisma.privateVerwendung.findMany({
|
|
where: { hostId, zustand: { not: "ENTFERNT" } },
|
|
select: {
|
|
id: true,
|
|
zielbenutzer: true,
|
|
pfad: true,
|
|
zustand: true,
|
|
schluessel: { select: { id: true, name: true, typ: true, fingerprint: true } },
|
|
},
|
|
orderBy: [{ zielbenutzer: "asc" }, { pfad: "asc" }],
|
|
}),
|
|
]);
|
|
return { oeffentlich, privat };
|
|
}
|