fix: unable to update integration when encryption key changed (#2133)

This commit is contained in:
Meier Lukas
2025-01-27 20:36:03 +01:00
committed by GitHub
parent 7cb0aa70f1
commit 93dc3ae97e
3 changed files with 23 additions and 5 deletions

View File

@@ -45,6 +45,7 @@
"@trpc/server": "next",
"lodash.clonedeep": "^4.5.0",
"next": "15.1.6",
"pretty-print-error": "^1.1.2",
"react": "19.0.0",
"react-dom": "19.0.0",
"superjson": "2.2.2",

View File

@@ -1,8 +1,11 @@
import { formatError } from "pretty-print-error";
import { decryptSecret } from "@homarr/common/server";
import type { Integration } from "@homarr/db/schema";
import type { IntegrationKind, IntegrationSecretKind } from "@homarr/definitions";
import { getAllSecretKindOptions } from "@homarr/definitions";
import { integrationCreator, IntegrationTestConnectionError } from "@homarr/integrations";
import { logger } from "@homarr/log";
type FormIntegration = Integration & {
secrets: {
@@ -28,11 +31,22 @@ export const testConnectionAsync = async (
source: "form" as const,
}));
const decryptedDbSecrets = dbSecrets.map((secret) => ({
...secret,
value: decryptSecret(secret.value),
source: "db" as const,
}));
const decryptedDbSecrets = dbSecrets
.map((secret) => {
try {
return {
...secret,
value: decryptSecret(secret.value),
source: "db" as const,
};
} catch (error) {
logger.warn(
`Failed to decrypt secret from database integration="${integration.name}" secretKind="${secret.kind}"\n${formatError(error)}`,
);
return null;
}
})
.filter((secret) => secret !== null);
const sourcedSecrets = [...formSecrets, ...decryptedDbSecrets];
const secretKinds = getSecretKindOption(integration.kind, sourcedSecrets);

3
pnpm-lock.yaml generated
View File

@@ -578,6 +578,9 @@ importers:
next:
specifier: 15.1.6
version: 15.1.6(@babel/core@7.26.0)(@playwright/test@1.49.1)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(sass@1.83.4)
pretty-print-error:
specifier: ^1.1.2
version: 1.1.2(patch_hash=4arrfgbz7em6s4gqywse7esg4u)
react:
specifier: 19.0.0
version: 19.0.0