feat(integrations): allow changing secret kinds of existing integration (#4254)

This commit is contained in:
Meier Lukas
2025-10-10 19:59:23 +02:00
committed by GitHub
parent 50a23d76e3
commit 3b708c5ebd
4 changed files with 148 additions and 86 deletions

View File

@@ -4,7 +4,7 @@ import { z } from "zod/v4";
import { createId, objectEntries } from "@homarr/common";
import { decryptSecret, encryptSecret } from "@homarr/common/server";
import type { Database } from "@homarr/db";
import { and, asc, eq, handleTransactionsAsync, inArray, like } from "@homarr/db";
import { and, asc, eq, handleTransactionsAsync, inArray, like, or } from "@homarr/db";
import {
groupMembers,
groupPermissions,
@@ -386,6 +386,21 @@ export const integrationRouter = createTRPCRouter({
}
}
const removedSecrets = integration.secrets.filter(
(dbSecret) => !input.secrets.some((secret) => dbSecret.kind === secret.kind),
);
if (removedSecrets.length >= 1) {
await ctx.db
.delete(integrationSecrets)
.where(
or(
...removedSecrets.map((secret) =>
and(eq(integrationSecrets.integrationId, input.id), eq(integrationSecrets.kind, secret.kind)),
),
),
);
}
logger.info("Updated integration", {
id: input.id,
name: input.name,