Merge branch 'phase/010-bootstrap'

This commit is contained in:
2026-10-12 09:52:00 +02:00
13 changed files with 602 additions and 3 deletions
+35
View File
@@ -0,0 +1,35 @@
import { prisma } from "@/lib/db";
import { bootstrapBefehl } from "@/lib/ssh/bootstrap-skript";
/**
* Der Befehl zum Kopieren (#010). Er enthaelt nur den Public Key des Deployment-Keys und
* darf deshalb in die Oberflaeche.
*/
export async function bootstrapBefehlFuer(hostId: string): Promise<string | undefined> {
const host = await prisma.host.findUnique({
where: { id: hostId },
select: {
anmeldeart: true,
deploymentSchluessel: { select: { publicKey: true } },
gruppen: {
select: { hostgruppe: { select: { deploymentSchluessel: { select: { publicKey: true } } } } },
},
},
});
if (!host) return undefined;
const standard = await prisma.schluessel.findFirst({
where: { kategorie: "DEPLOYMENT", instanzStandard: true, status: "AKTIV" },
select: { publicKey: true },
});
// Dieselbe Reihenfolge wie im Worker (deploymentKeyIdFuer): Host, Gruppe, Instanz.
const publicKey =
host.deploymentSchluessel?.publicKey ??
host.gruppen.find((g) => g.hostgruppe.deploymentSchluessel)?.hostgruppe.deploymentSchluessel?.publicKey ??
standard?.publicKey;
if (!publicKey) return undefined;
return bootstrapBefehl({
benutzer: host.anmeldeart === "ROOT" ? "root" : "sshkv",
dienstbenutzerAnlegen: host.anmeldeart === "DIENSTBENUTZER",
deploymentKey: publicKey,
});
}