Merge branch 'phase/010-bootstrap'
This commit is contained in:
@@ -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,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user