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
feat(secret-sync): add the recursive sync option
Calvind71e5bb8127d
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.tsindex d0e6548b54..40114921d5 100644--- a/backend/src/lib/api-docs/constants.ts+++ b/backend/src/lib/api-docs/constants.ts@@ -3101,7 +3101,8 @@ export const SecretSyncs = {return {initialSyncBehavior: `Specify how Infisical should resolve the initial sync to the ${destinationName} destination.`,keySchema: `Specify the format to use for structuring secret keys in the ${destinationName} destination.`,- disableSecretDeletion: `Enable this flag to prevent removal of secrets from the ${destinationName} destination when syncing.`+ disableSecretDeletion: `Enable this flag to prevent removal of secrets from the ${destinationName} destination when syncing.`,+ recursive: `Whether to sync secrets from folders beneath the source path as well.`};},ADDITIONAL_SYNC_OPTIONS: {diff --git a/backend/src/services/secret-sync/secret-sync-schemas.test.ts b/backend/src/services/secret-sync/secret-sync-schemas.test.tsnew file mode 100644index 0000000000..a8948f39f3--- /dev/null+++ b/backend/src/services/secret-sync/secret-sync-schemas.test.ts@@ -0,0 +1,31 @@+import { SecretSync, SecretSyncInitialSyncBehavior } from "./secret-sync-enums";+import { BaseSecretSyncSchema } from "./secret-sync-schemas";++const schema = BaseSecretSyncSchema(SecretSync.Render, { canImportSecrets: true }).shape.syncOptions;++describe("BaseSyncOptionsSchema recursive", () => {+ test("defaults to absent, which means non-recursive", () => {+ const result = schema.safeParse({ initialSyncBehavior: SecretSyncInitialSyncBehavior.OverwriteDestination });++ expect(result.success).toBe(true);+ expect(result.success && result.data.recursive).toBeUndefined();+ });++ test("accepts recursive with the overwrite behavior", () => {+ const result = schema.safeParse({+ initialSyncBehavior: SecretSyncInitialSyncBehavior.OverwriteDestination,+ recursive: true+ });++ expect(result.success).toBe(true);+ });++ test("rejects recursive combined with importing from the destination", () => {+ const result = schema.safeParse({+ initialSyncBehavior: SecretSyncInitialSyncBehavior.ImportPrioritizeSource,+ recursive: true+ });++ expect(result.success).toBe(false);+ });+});diff --git a/backend/src/services/secret-sync/secret-sync-schemas.ts b/backend/src/services/secret-sync/secret-sync-schemas.tsindex 977b362587..6f7865f339 100644--- a/backend/src/services/secret-sync/secret-sync-schemas.ts+++ b/backend/src/services/secret-sync/secret-sync-schemas.ts@@ -63,16 +63,29 @@ const BaseSyncOptionsSchema = <T extends AnyZodObject | undefined = undefined>({.describe(`Not supported for ${syncName} syncs.`),disableSecretDeletion: supportsDisableSecretDeletion? z.boolean().optional().describe(SecretSyncs.SYNC_OPTIONS(destination).disableSecretDeletion)- : z.literal(false).or(z.undefined()).describe(`Not supported for ${syncName} syncs.`)+ : z.literal(false).or(z.undefined()).describe(`Not supported for ${syncName} syncs.`),+ recursive: z.boolean().optional().describe(SecretSyncs.SYNC_OPTIONS(destination).recursive)});const schema = merge ? baseSchema.merge(merge) : baseSchema;+ const refinedSchema = (schema as AnyZodObject).refine(+ (options) =>+ !options.recursive || options.initialSyncBehavior === SecretSyncInitialSyncBehavior.OverwriteDestination,+ {+ path: ["recursive"],+ message:+ "A sync that includes subfolders cannot also import existing secrets from the destination, because there is no single folder to import them into. Turn off subfolders, or set the first sync to overwrite the destination."+ }+ );+return (isUpdateSchema- ? schema.describe(SecretSyncs.UPDATE(destination).syncOptions).optional()- : schema.describe(SecretSyncs.CREATE(destination).syncOptions)- ) as T extends AnyZodObject ? z.ZodObject<z.objectUtil.MergeShapes<typeof schema.shape, T["shape"]>> : typeof schema;+ ? refinedSchema.describe(SecretSyncs.UPDATE(destination).syncOptions).optional()+ : refinedSchema.describe(SecretSyncs.CREATE(destination).syncOptions)+ ) as unknown as T extends AnyZodObject+ ? z.ZodObject<z.objectUtil.MergeShapes<typeof schema.shape, T["shape"]>>+ : typeof schema;};export const BaseSecretSyncSchema = <T extends AnyZodObject | undefined = undefined>(