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

@@ -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);