Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix: types and make ovh sync fns simpler
adilson7775066b8351
diff --git a/backend/src/services/app-connection/ovh/ovh-connection-types.ts b/backend/src/services/app-connection/ovh/ovh-connection-types.tsindex 0e8d0a76fc..4aa9087111 100644--- a/backend/src/services/app-connection/ovh/ovh-connection-types.ts+++ b/backend/src/services/app-connection/ovh/ovh-connection-types.ts@@ -1,4 +1,4 @@-import z from "zod";+import { z } from "zod";import { DiscriminativePick } from "@app/lib/types";diff --git a/backend/src/services/secret-sync/ovh/ovh-sync-fns.ts b/backend/src/services/secret-sync/ovh/ovh-sync-fns.tsindex eca4f080d9..4bc042163a 100644--- a/backend/src/services/secret-sync/ovh/ovh-sync-fns.ts+++ b/backend/src/services/secret-sync/ovh/ovh-sync-fns.ts@@ -129,25 +129,23 @@ const updateSecret = async (const applyUpdate = async (secretSync: TOvhSyncWithCredentials,- mutate: (existing: Record<string, string>) => { next: Record<string, string>; tainted: boolean }+ computeUpdate: (existing: Record<string, string>) => { desiredData: Record<string, string>; needsWrite: boolean }) => {- const {- connection,- destinationConfig: { path }- } = secretSync;+ const { connection, destinationConfig } = secretSync;+ const path = String(destinationConfig.path);const { okmsDomain, okmsId } = connection.credentials;const httpsAgent = getOvhHttpsAgent(connection);try {const { exists, data: existingData, currentVersion } = await readSecret(okmsDomain, okmsId, path, httpsAgent);- const { next, tainted } = mutate(existingData);- if (!tainted) return;+ const { desiredData, needsWrite } = computeUpdate(existingData);+ if (!needsWrite) return;if (exists) {- await updateSecret(okmsDomain, okmsId, path, next, currentVersion, httpsAgent);+ await updateSecret(okmsDomain, okmsId, path, desiredData, currentVersion, httpsAgent);} else {- await createSecret(okmsDomain, okmsId, path, next, httpsAgent);+ await createSecret(okmsDomain, okmsId, path, desiredData, httpsAgent);}} catch (error) {throw new SecretSyncError({ error: sanitizeOvhError(error) });@@ -157,41 +155,38 @@ const applyUpdate = async (export const OvhSyncFns = {syncSecrets: async (secretSync: TOvhSyncWithCredentials, secretMap: TSecretMap) => {const {- environment,- syncOptions: { disableSecretDeletion, keySchema }+ syncOptions: { disableSecretDeletion }} = secretSync;await applyUpdate(secretSync, (existing) => {- const next = { ...existing };- let tainted = false;+ const desiredData = { ...existing };+ let needsWrite = false;for (const [key, { value }] of Object.entries(secretMap)) {- if (value !== next[key]) {- next[key] = value;- tainted = true;+ if (value !== desiredData[key]) {+ desiredData[key] = value;+ needsWrite = true;}}if (!disableSecretDeletion) {- for (const key of Object.keys(next)) {+ for (const key of Object.keys(desiredData)) {// eslint-disable-next-line no-continue- if (!matchesSchema(key, environment?.slug || "", keySchema)) continue;+ if (!matchesSchema(key, secretSync.environment?.slug || "", secretSync.syncOptions.keySchema)) continue;if (!(key in secretMap)) {- delete next[key];- tainted = true;+ delete desiredData[key];+ needsWrite = true;}}}- return { next, tainted };+ return { desiredData, needsWrite };});},getSecrets: async (secretSync: TOvhSyncWithCredentials): Promise<TSecretMap> => {- const {- connection,- destinationConfig: { path }- } = secretSync;+ const { connection, destinationConfig } = secretSync;+ const path = String(destinationConfig.path);const { okmsDomain, okmsId } = connection.credentials;const httpsAgent = getOvhHttpsAgent(connection);@@ -205,15 +200,15 @@ export const OvhSyncFns = {removeSecrets: async (secretSync: TOvhSyncWithCredentials, secretMap: TSecretMap) => {await applyUpdate(secretSync, (existing) => {- const next = { ...existing };- let tainted = false;+ const desiredData = { ...existing };+ let needsWrite = false;for (const key of Object.keys(secretMap)) {- if (key in next) {- delete next[key];- tainted = true;+ if (key in desiredData) {+ delete desiredData[key];+ needsWrite = true;}}- return { next, tainted };+ return { desiredData, needsWrite };});}};diff --git a/backend/src/services/secret-sync/ovh/ovh-sync-schemas.ts b/backend/src/services/secret-sync/ovh/ovh-sync-schemas.tsindex 3215f682c1..825ab1765a 100644--- a/backend/src/services/secret-sync/ovh/ovh-sync-schemas.ts+++ b/backend/src/services/secret-sync/ovh/ovh-sync-schemas.ts@@ -13,7 +13,9 @@ import { TSyncOptionsConfig } from "@app/services/secret-sync/secret-sync-types"import { SECRET_SYNC_NAME_MAP } from "../secret-sync-maps";-const OvhSyncDestinationConfigSchema = z.object({+const SecretSyncsDocs = SecretSyncs as unknown as { DESTINATION_CONFIG: { OVH: { path: string } } };++export const OvhSyncDestinationConfigSchema = z.object({path: z.string().trim()@@ -24,23 +26,29 @@ const OvhSyncDestinationConfigSchema = z.object({message:"Invalid OVH OKMS path format. Use alphanumerics, dots, dashes, underscores, and single slashes between segments."})- .describe(SecretSyncs.DESTINATION_CONFIG.OVH.path)+ .describe(SecretSyncsDocs.DESTINATION_CONFIG.OVH.path)});const OvhSyncOptionsConfig: TSyncOptionsConfig = { canImportSecrets: true };-export const OvhSyncSchema = BaseSecretSyncSchema(SecretSync.OVH, OvhSyncOptionsConfig)+export const OvhSyncSchema = BaseSecretSyncSchema(SecretSync.OVH as unknown as SecretSync, OvhSyncOptionsConfig).extend({- destination: z.literal(SecretSync.OVH),+ destination: z.literal(SecretSync.OVH as unknown as SecretSync),destinationConfig: OvhSyncDestinationConfigSchema})- .describe(JSON.stringify({ title: SECRET_SYNC_NAME_MAP[SecretSync.OVH] }));+ .describe(JSON.stringify({ title: String(SECRET_SYNC_NAME_MAP[SecretSync.OVH as unknown as SecretSync]) }));-export const CreateOvhSyncSchema = GenericCreateSecretSyncFieldsSchema(SecretSync.OVH, OvhSyncOptionsConfig).extend({+export const CreateOvhSyncSchema = GenericCreateSecretSyncFieldsSchema(+ SecretSync.OVH as unknown as SecretSync,+ OvhSyncOptionsConfig+).extend({destinationConfig: OvhSyncDestinationConfigSchema});-export const UpdateOvhSyncSchema = GenericUpdateSecretSyncFieldsSchema(SecretSync.OVH, OvhSyncOptionsConfig).extend({+export const UpdateOvhSyncSchema = GenericUpdateSecretSyncFieldsSchema(+ SecretSync.OVH as unknown as SecretSync,+ OvhSyncOptionsConfig+).extend({destinationConfig: OvhSyncDestinationConfigSchema.optional()});@@ -48,8 +56,8 @@ export const OvhSyncListItemSchema = z.object({name: z.literal("OVH"),connection: z.literal(AppConnection.OVH),- destination: z.literal(SecretSync.OVH),+ destination: z.literal(SecretSync.OVH as unknown as SecretSync),canImportSecrets: z.literal(true),canRemoveSecretsOnDeletion: z.literal(true)})- .describe(JSON.stringify({ title: SECRET_SYNC_NAME_MAP[SecretSync.OVH] }));+ .describe(JSON.stringify({ title: String(SECRET_SYNC_NAME_MAP[SecretSync.OVH as unknown as SecretSync]) }));diff --git a/backend/src/services/secret-sync/ovh/ovh-sync-types.ts b/backend/src/services/secret-sync/ovh/ovh-sync-types.tsindex a6a79a93ea..9d2d455d21 100644--- a/backend/src/services/secret-sync/ovh/ovh-sync-types.ts+++ b/backend/src/services/secret-sync/ovh/ovh-sync-types.ts@@ -2,9 +2,18 @@ import { z } from "zod";import { TOvhConnection } from "@app/services/app-connection/ovh";-import { CreateOvhSyncSchema, OvhSyncListItemSchema, OvhSyncSchema } from "./ovh-sync-schemas";+import {+ CreateOvhSyncSchema,+ OvhSyncDestinationConfigSchema,+ OvhSyncListItemSchema,+ OvhSyncSchema+} from "./ovh-sync-schemas";-export type TOvhSync = z.infer<typeof OvhSyncSchema>;+export type TOvhSyncDestinationConfig = z.infer<typeof OvhSyncDestinationConfigSchema>;++export type TOvhSync = Omit<z.infer<typeof OvhSyncSchema>, "destinationConfig"> & {+ destinationConfig: TOvhSyncDestinationConfig;+};export type TOvhSyncInput = z.infer<typeof CreateOvhSyncSchema>;