Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

UI: add new field and preview

adilson2b391c12f583
diff --git a/frontend/src/components/external-migrations/VaultImportPreview.tsx b/frontend/src/components/external-migrations/VaultImportPreview.tsx
new file mode 100644
index 0000000000..2a16d1b817
--- /dev/null
+++ b/frontend/src/components/external-migrations/VaultImportPreview.tsx
@@ -0,0 +1,52 @@
+import { FolderIcon, KeyIcon } from "lucide-react";
+
+import { TVaultImportPreview } from "./VaultImportPreview.utils";
+
+type Props = {
+ preview: TVaultImportPreview;
+};
+
+const ROW_INDENT_PX = 18;
+
+export const VaultImportPreview = ({ preview }: Props) => (
+ <div className="flex flex-col gap-2" aria-hidden="true">
+ <span className="text-[10px] font-medium tracking-wider text-muted uppercase">Preview</span>
+ <div className="rounded-lg border border-border bg-card">
+ <div className="border-b border-border px-3.5 py-2.5 text-xs text-label">
+ {preview.headline}
+ </div>
+ <div className="max-h-64 overflow-y-auto px-3.5 py-2.5">
+ {preview.rows.map((row) => (
+ <div
+ key={row.key}
+ className="flex h-7 items-center gap-2"
+ style={{ paddingLeft: row.depth * ROW_INDENT_PX }}
+ >
+ {row.kind === "folder" ? (
+ <FolderIcon className="size-3.5 shrink-0 text-folder" />
+ ) : (
+ <KeyIcon className="size-3.5 shrink-0 text-secret" />
+ )}
+ <span
+ title={row.title ?? row.name}
+ className={`truncate font-mono text-[12.5px] ${
+ row.kind === "folder" ? "text-foreground" : "text-label"
+ }`}
+ >
+ {row.name}
+ </span>
+ {row.source && (
+ <span
+ title={row.source}
+ className="ml-auto truncate pl-2 font-mono text-[11px] text-muted"
+ >
+ {row.source}
+ </span>
+ )}
+ </div>
+ ))}
+ </div>
+ </div>
+ <p className="text-[11px] text-muted">Secrets displayed on the preview are placeholders.</p>
+ </div>
+);
diff --git a/frontend/src/components/external-migrations/VaultImportPreview.utils.test.ts b/frontend/src/components/external-migrations/VaultImportPreview.utils.test.ts
new file mode 100644
index 0000000000..68f0256879
--- /dev/null
+++ b/frontend/src/components/external-migrations/VaultImportPreview.utils.test.ts
@@ -0,0 +1,190 @@
+import assert from "node:assert/strict";
+import { describe, it } from "node:test";
+
+import { buildVaultImportPreview } from "./VaultImportPreview.utils";
+
+const folderNames = (rows: { kind: string; name: string }[]) =>
+ rows.filter((row) => row.kind === "folder").map((row) => row.name);
+
+describe("Vault import preview", () => {
+ it("drops the secrets engine and mirrors the remaining path", () => {
+ const { rows, invalidPaths } = buildVaultImportPreview({
+ selectedPaths: ["kv/prod/db"],
+ destinationPath: "/newww",
+ keepVaultStructure: true
+ });
+
+ assert.deepEqual(folderNames(rows), ["/newww", "prod/", "db/"]);
+ assert.deepEqual(invalidPaths, []);
+ });
+
+ it("creates a shared parent only once for sibling paths", () => {
+ const { rows } = buildVaultImportPreview({
+ selectedPaths: ["kv/new-path", "kv/new-path/api"],
+ destinationPath: "/newww",
+ keepVaultStructure: true
+ });
+
+ assert.deepEqual(folderNames(rows), ["/newww", "new-path/", "api/"]);
+ });
+
+ it("nests each path under its own parent and sorts siblings", () => {
+ const { rows } = buildVaultImportPreview({
+ selectedPaths: ["kv/teste/belinha", "kv/prod/db"],
+ destinationPath: "/",
+ keepVaultStructure: true
+ });
+
+ assert.deepEqual(folderNames(rows), ["/", "prod/", "db/", "teste/", "belinha/"]);
+ });
+
+ it("hangs placeholder secrets off the folder the path maps to", () => {
+ const { rows } = buildVaultImportPreview({
+ selectedPaths: ["kv/new-path", "kv/new-path/api"],
+ destinationPath: "/newww",
+ keepVaultStructure: true
+ });
+
+ assert.deepEqual(
+ rows
+ .filter((row) => row.kind === "secret")
+ .map((row) => ({ name: row.name, depth: row.depth, source: row.source })),
+ [
+ { name: "secret_1", depth: 2, source: "kv/new-path" },
+ { name: "secret_2", depth: 2, source: "kv/new-path" },
+ { name: "secret_1", depth: 3, source: "kv/new-path/api" },
+ { name: "secret_2", depth: 3, source: "kv/new-path/api" }
+ ]
+ );
+ });
+
+ it("flattens every path into the destination when the structure is not preserved", () => {
+ const { rows, headline, invalidPaths } = buildVaultImportPreview({
+ selectedPaths: ["kv/prod/db", "kv/teste"],
+ destinationPath: "/newww",
+ keepVaultStructure: false
+ });
+
+ assert.deepEqual(folderNames(rows), ["/newww"]);
+ assert.ok(rows.slice(1).every((row) => row.depth === 1));
+ assert.equal(
+ headline,
+ "All secrets are flattened into /newww. Vault path structure is not preserved."
+ );
+ assert.deepEqual(invalidPaths, []);
+ });
+
+ it("never repeats a placeholder name when flattening, since duplicates fail on import", () => {
+ const { rows } = buildVaultImportPreview({
+ selectedPaths: ["kv/prod/db", "kv/teste", "kv/new-path"],
+ destinationPath: "/newww",
+ keepVaultStructure: false
+ });
+
+ const names = rows.filter((row) => row.kind === "secret").map((row) => row.name);
+
+ assert.deepEqual(names, [
+ "secret_1",
+ "secret_2",
+ "secret_3",
+ "secret_4",
+ "secret_5",
+ "secret_6"
+ ]);
+ assert.equal(new Set(names).size, names.length);
+ });
+
+ it("restarts placeholder numbering per folder when the structure is preserved", () => {
+ const { rows } = buildVaultImportPreview({
+ selectedPaths: ["kv/prod/db", "kv/teste"],
+ destinationPath: "/newww",
+ keepVaultStructure: true
+ });
+
+ assert.deepEqual(
+ rows.filter((row) => row.kind === "secret").map((row) => row.name),
+ ["secret_1", "secret_2", "secret_1", "secret_2"]
+ );
+ });
+
+ it("matches the headline verb to the number of source paths", () => {
+ const onePath = buildVaultImportPreview({
+ selectedPaths: ["kv/prod/db"],
+ destinationPath: "/newww",
+ keepVaultStructure: true
+ });
+ const manyPaths = buildVaultImportPreview({
+ selectedPaths: ["kv/prod", "kv/teste"],
+ destinationPath: "/newww",
+ keepVaultStructure: true
+ });
+
+ assert.equal(onePath.headline, "The Vault path becomes 2 folders under /newww.");
+ assert.equal(manyPaths.headline, "The Vault paths become 2 folders under /newww.");
+ });
+
+ it("counts only the paths that reached the tree when picking the headline verb", () => {
+ const { headline } = buildVaultImportPreview({
+ selectedPaths: ["kv/prod", "kv/my.app"],
+ destinationPath: "/newww",
+ keepVaultStructure: true
+ });
+
+ assert.equal(headline, "The Vault path becomes 1 folder under /newww.");
+ });
+
+ it("elides the middle of a deep destination path", () => {
+ const { rows, headline } = buildVaultImportPreview({
+ selectedPaths: ["kv/prod"],
+ destinationPath: "/one/two/three/four/five",
+ keepVaultStructure: false
+ });
+
+ assert.equal(rows[0].name, "/one/.../five");
+ assert.equal(
+ headline,
+ "All secrets are flattened into /one/.../five. Vault path structure is not preserved."
+ );
+ });
+
+ it("keeps a destination path short enough to read intact", () => {
+ const { rows } = buildVaultImportPreview({
+ selectedPaths: ["kv/prod"],
+ destinationPath: "/one/two/three",
+ keepVaultStructure: true
+ });
+
+ assert.equal(rows[0].name, "/one/two/three");
+ });
+
+ it("rejects paths that hold only a mount", () => {
+ const { rows, invalidPaths } = buildVaultImportPreview({
+ selectedPaths: ["kv", "kv/prod"],
+ destinationPath: "/newww",
+ keepVaultStructure: true
+ });
+
+ assert.deepEqual(invalidPaths, ["kv"]);
+ assert.deepEqual(folderNames(rows), ["/newww", "prod/"]);
+ });
+
+ it("rejects segments that cannot become folder names", () => {
+ const { invalidPaths } = buildVaultImportPreview({
+ selectedPaths: ["kv/my.app", "kv/my app", "kv/my-app_1"],
+ destinationPath: "/newww",
+ keepVaultStructure: true
+ });
+
+ assert.deepEqual(invalidPaths, ["kv/my.app", "kv/my app"]);
+ });
+
+ it("keeps invalid paths out of the flattened preview", () => {
+ const { invalidPaths } = buildVaultImportPreview({
+ selectedPaths: ["kv/my.app"],
+ destinationPath: "/newww",
+ keepVaultStructure: false
+ });
+
+ assert.deepEqual(invalidPaths, []);
+ });
+});
diff --git a/frontend/src/components/external-migrations/VaultImportPreview.utils.ts b/frontend/src/components/external-migrations/VaultImportPreview.utils.ts
new file mode 100644
index 0000000000..003e5455bb
--- /dev/null
+++ b/frontend/src/components/external-migrations/VaultImportPreview.utils.ts
@@ -0,0 +1,158 @@
+export type TVaultImportPreviewRow = {
+ key: string;
+ depth: number;
+ kind: "folder" | "secret";
+ name: string;
+ source?: string;
+ title?: string;
+};
+
+export type TVaultImportPreview = {
+ rows: TVaultImportPreviewRow[];
+ headline: string;
+ invalidPaths: string[];
+};
+
+type TBuildVaultImportPreviewArgs = {
+ selectedPaths: string[];
+ destinationPath: string;
+ keepVaultStructure: boolean;
+};
+
+type TFolderNode = {
+ children: Map<string, TFolderNode>;
+ sources: string[];
+};
+
+// Vault only exposes paths at this stage, so leaf rows stand in for the real keys
+const PLACEHOLDER_SECRET_COUNT = 2;
+
+const VALID_FOLDER_SEGMENT = /^[a-zA-Z0-9_-]+$/;
+
+const toSegments = (path: string) => path.split("/").filter(Boolean);
+
+// a deep destination would otherwise push the source column off the row and bloat the headline
+const MAX_VISIBLE_PATH_SEGMENTS = 3;
+
+const formatDestination = (path: string) => {
+ const segments = toSegments(path);
+
+ if (segments.length <= MAX_VISIBLE_PATH_SEGMENTS) return `/${segments.join("/")}`;
+
+ return `/${[segments[0], "...", segments[segments.length - 1]].join("/")}`;
+};
+
+const pluralizeFolders = (count: number) => `${count} folder${count === 1 ? "" : "s"}`;
+
+const placeholderNames = (offset: number) =>
+ Array.from({ length: PLACEHOLDER_SECRET_COUNT }, (_, index) => `secret_${offset + index + 1}`);
+
+const createNode = (): TFolderNode => ({ children: new Map(), sources: [] });
+
+export const buildVaultImportPreview = ({
+ selectedPaths,
+ destinationPath,
+ keepVaultStructure
+}: TBuildVaultImportPreviewArgs): TVaultImportPreview => {
+ const fullDestination = `/${toSegments(destinationPath).join("/")}`;
+ const destination = formatDestination(destinationPath);
+ const rows: TVaultImportPreviewRow[] = [
+ {
+ key: "destination",
+ depth: 0,
+ kind: "folder",
+ name: destination,
+ title: fullDestination
+ }
+ ];
+
+ if (!keepVaultStructure) {
+ selectedPaths.forEach((vaultPath, pathIndex) => {
+ placeholderNames(pathIndex * PLACEHOLDER_SECRET_COUNT).forEach((name, index) => {
+ rows.push({
+ key: `secret:${vaultPath}:${index}`,
+ depth: 1,
+ kind: "secret",
+ name,
+ source: vaultPath
+ });
+ });
+ });
+
+ return {
+ rows,
+ headline: `All secrets are flattened into ${destination}. Vault path structure is not preserved.`,
+ invalidPaths: []
+ };
+ }
+
+ const invalidPaths: string[] = [];
+ const root = createNode();
+ let folderCount = 0;
+
+ selectedPaths.forEach((vaultPath) => {
+ // the secrets engine leads the path and is dropped, matching buildVaultFolderImportPlan
+ const [, ...relativeSegments] = toSegments(vaultPath);
+
+ if (
+ !relativeSegments.length ||
+ relativeSegments.some((segment) => !VALID_FOLDER_SEGMENT.test(segment))
+ ) {
+ invalidPaths.push(vaultPath);
+ return;
+ }
+
+ let node = root;
+ relativeSegments.forEach((segment) => {
+ let child = node.children.get(segment);
+
+ if (!child) {
+ child = createNode();
+ node.children.set(segment, child);
+ folderCount += 1;
+ }
+
+ node = child;
+ });
+ node.sources.push(vaultPath);
+ });
+
+ const walk = (node: TFolderNode, depth: number, prefix: string) => {
+ [...node.children.entries()]
+ .sort(([left], [right]) => left.localeCompare(right))
+ .forEach(([name, child]) => {
+ const path = `${prefix}/${name}`;
+
+ rows.push({
+ key: `folder:${path}`,
+ depth,
+ kind: "folder",
+ name: `${name}/`
+ });
+
+ child.sources.forEach((source, sourceIndex) => {
+ placeholderNames(sourceIndex * PLACEHOLDER_SECRET_COUNT).forEach((secretName, index) => {
+ rows.push({
+ key: `secret:${path}:${source}:${index}`,
+ depth: depth + 1,
+ kind: "secret",
+ name: secretName,
+ source
+ });
+ });
+ });
+
+ walk(child, depth + 1, path);
+ });
+ };
+
+ walk(root, 1, "");
+
+ const mirroredPathCount = selectedPaths.length - invalidPaths.length;
+
+ return {
+ rows,
+ headline: `The Vault path${mirroredPathCount === 1 ? " becomes" : "s become"} ${pluralizeFolders(folderCount)} under ${destination}.`,
+ invalidPaths
+ };
+};
diff --git a/frontend/src/components/external-migrations/index.ts b/frontend/src/components/external-migrations/index.ts
index e47c432afe..147bf1be09 100644
--- a/frontend/src/components/external-migrations/index.ts
+++ b/frontend/src/components/external-migrations/index.ts
@@ -1,3 +1,5 @@
export * from "./VaultConnectionAndNamespaceFields";
+export * from "./VaultImportPreview";
+export * from "./VaultImportPreview.utils";
export * from "./VaultRoleImportModal";
export * from "./VaultRoleImportModal.utils";
diff --git a/frontend/src/hooks/api/migration/mutations.tsx b/frontend/src/hooks/api/migration/mutations.tsx
index ff9cec2813..6775b8352c 100644
--- a/frontend/src/hooks/api/migration/mutations.tsx
+++ b/frontend/src/hooks/api/migration/mutations.tsx
@@ -2,13 +2,14 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { dashboardKeys } from "@app/hooks/api/dashboard/queries";
+import { folderQueryKeys } from "@app/hooks/api/secretFolders/queries";
import { secretKeys } from "@app/hooks/api/secrets/queries";
import { projectKeys } from "../projects";
import {
- ExternalMigrationImportStatus,
TImportDopplerSecretsDTO,
- TImportVaultSecretsDTO
+ TImportVaultSecretsDTO,
+ TImportVaultSecretsResponse
} from "./types";
export const useImportEnvKey = () => {
@@ -76,9 +77,9 @@ export const useImportVault = () => {
export const useImportVaultSecrets = () => {
const queryClient = useQueryClient();
- return useMutation<{ status: ExternalMigrationImportStatus }, object, TImportVaultSecretsDTO>({
+ return useMutation<TImportVaultSecretsResponse, object, TImportVaultSecretsDTO>({
mutationFn: async (dto) => {
- const { data } = await apiRequest.post<{ status: ExternalMigrationImportStatus }>(
+ const { data } = await apiRequest.post<TImportVaultSecretsResponse>(
"/api/v3/external-migration/vault/import-secrets",
dto
);
@@ -93,6 +94,13 @@ export const useImportVaultSecrets = () => {
secretPath
})
});
+ queryClient.invalidateQueries({
+ queryKey: folderQueryKeys.getSecretFolders({
+ projectId,
+ environment,
+ path: secretPath
+ })
+ });
}
});
};
diff --git a/frontend/src/hooks/api/migration/types.ts b/frontend/src/hooks/api/migration/types.ts
index 39aca20410..e591ffa86b 100644
--- a/frontend/src/hooks/api/migration/types.ts
+++ b/frontend/src/hooks/api/migration/types.ts
@@ -47,6 +47,13 @@ export type TImportVaultSecretsDTO = {
vaultNamespace: string;
vaultSecretPaths: string[];
connectionId: string;
+ keepVaultStructure: boolean;
+};
+
+export type TImportVaultSecretsResponse = {
+ status: ExternalMigrationImportStatus;
+ importedPaths?: string[];
+ approvalRequiredPaths?: string[];
};
export type VaultKubernetesAuthRole = {
diff --git a/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx b/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx
index eceac51578..1c3e4769be 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx
@@ -207,7 +207,10 @@ import { CreateSecretImportForm } from "../SecretDashboardPage/components/Action
import { DopplerSecretImportModal } from "../SecretDashboardPage/components/ActionBar/DopplerSecretImportModal";
import { FolderForm } from "../SecretDashboardPage/components/ActionBar/FolderForm";
import { ReplicateFolderFromBoard } from "../SecretDashboardPage/components/ActionBar/ReplicateFolderFromBoard/ReplicateFolderFromBoard";
-import { VaultSecretImportModal } from "../SecretDashboardPage/components/ActionBar/VaultSecretImportModal";
+import {
+ TVaultSecretImportArgs,
+ VaultSecretImportModal
+} from "../SecretDashboardPage/components/ActionBar/VaultSecretImportModal";
import { CommitForm } from "../SecretDashboardPage/components/CommitForm";
import { CreateDynamicSecretLease } from "../SecretDashboardPage/components/DynamicSecretListView/CreateDynamicSecretLease";
import { DynamicSecretLease } from "../SecretDashboardPage/components/DynamicSecretListView/DynamicSecretLease";
@@ -1072,35 +1075,43 @@ const OverviewPageContent = () => {
handlePopUpOpen("addSecretImport");
};
- const handleVaultImport = async (
- vaultPaths: string[],
- namespace: string,
- connectionId: string
- ) => {
- const { status } = await importVaultSecrets({
+ const handleVaultImport = async ({
+ vaultPaths,
+ namespace,
+ connectionId,
+ keepVaultStructure
+ }: TVaultSecretImportArgs) => {
+ const { status, importedPaths, approvalRequiredPaths } = await importVaultSecrets({
projectId,
environment: singleEnvSlug,
secretPath,
vaultNamespace: namespace,
vaultSecretPaths: vaultPaths,
- connectionId
+ connectionId,
+ keepVaultStructure
});
if (status === ExternalMigrationImportStatus.ApprovalRequired) {
+ const pendingCount = approvalRequiredPaths?.length ?? vaultPaths.length;
+
createNotification({
type: "info",
text:
- vaultPaths.length > 1
- ? `Secret change request created for ${vaultPaths.length} Vault paths. Awaiting approval.`
+ pendingCount > 1
+ ? `Secret change request created for ${pendingCount} Vault paths. Awaiting approval.`
: "Secret change request created successfully. Awaiting approval."
});
} else {
+ const folderCount = importedPaths?.length ?? 0;
+ const source =
+ vaultPaths.length > 1 ? `${vaultPaths.length} HashiCorp Vault paths` : "HashiCorp Vault";
+
createNotification({
type: "success",
text:
- vaultPaths.length > 1
- ? `Successfully imported secrets from ${vaultPaths.length} HashiCorp Vault paths`
- : "Successfully imported secrets from HashiCorp Vault"
+ folderCount > 1
+ ? `Imported secrets from ${source} into ${folderCount} folders`
+ : `Imported secrets from ${source}`
});
}
};
@@ -4057,6 +4068,7 @@ const OverviewPageContent = () => {
isOpen={popUp.importFromVault.isOpen}
onOpenChange={(isOpen) => handlePopUpToggle("importFromVault", isOpen)}
appConnections={vaultAppConnections}
+ destinationPath={secretPath}
onImport={handleVaultImport}
/>
{hasDopplerConnection && (
diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/VaultSecretImportModal.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/VaultSecretImportModal.tsx
index 4419a525d4..5a3ba2eafc 100644
--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/VaultSecretImportModal.tsx
+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/VaultSecretImportModal.tsx
@@ -1,9 +1,11 @@
-import { useReducer, useRef } from "react";
+import { useMemo, useReducer, useRef, useState } from "react";
import { TriangleAlertIcon } from "lucide-react";
import {
+ buildVaultImportPreview,
VaultConnectionAndNamespaceFields,
- VaultFieldLabel
+ VaultFieldLabel,
+ VaultImportPreview
} from "@app/components/external-migrations";
import {
createVaultImportSelection,
@@ -16,9 +18,12 @@ import {
AlertTitle,
Badge,
Button,
+ Checkbox,
Combobox,
Field,
+ FieldContent,
FieldDescription,
+ FieldLabel,
Sheet,
SheetClose,
SheetContent,
@@ -34,17 +39,26 @@ import { useBadgeOverflow } from "@app/components/v3/generic/DataGrid/hooks/use-
import { TAvailableAppConnection } from "@app/hooks/api/appConnections/types";
import { useGetVaultMounts, useGetVaultSecretPaths } from "@app/hooks/api/migration/queries";
+export type TVaultSecretImportArgs = {
+ vaultPaths: string[];
+ namespace: string;
+ connectionId: string;
+ keepVaultStructure: boolean;
+};
+
type Props = {
isOpen: boolean;
onOpenChange: (isOpen: boolean) => void;
appConnections: TAvailableAppConnection[];
- onImport: (vaultPaths: string[], namespace: string, connectionId: string) => void;
+ destinationPath: string;
+ onImport: (args: TVaultSecretImportArgs) => void;
};
type ContentProps = {
onClose: () => void;
appConnections: TAvailableAppConnection[];
- onImport: (vaultPaths: string[], namespace: string, connectionId: string) => void;
+ destinationPath: string;
+ onImport: (args: TVaultSecretImportArgs) => void;
};
const MAX_PATH_LENGTH = 30;
@@ -76,15 +90,16 @@ const renderWildcardPath = (path: string) => {
);
};
-const Content = ({ onClose, appConnections, onImport }: ContentProps) => {
+const Content = ({ onClose, appConnections, destinationPath, onImport }: ContentProps) => {
const hasAppConnections = appConnections.length > 0;
+ const [keepVaultStructure, setKeepVaultStructure] = useState(false);
const [state, dispatch] = useReducer(
vaultImportSelectionReducer<string[]>,
appConnections.map(({ id }) => id),
createVaultImportSelection<string[]>
);
const { connectionId, mountPath, namespace } = state;
- const selectedPaths = state.selection ?? [];
+ const selectedPaths = useMemo(() => state.selection ?? [], [state.selection]);
const activeConnectionId = hasAppConnections ? (connectionId ?? undefined) : undefined;
const shouldFetchMounts = Boolean(namespace && activeConnectionId);
const shouldFetchPaths = Boolean(namespace && mountPath && activeConnectionId);
@@ -118,6 +133,12 @@ const Content = ({ onClose, appConnections, onImport }: ContentProps) => {
});
const hiddenSkippedPaths = skippedWildcardPaths.slice(visibleSkippedPaths.length);
+ const preview = useMemo(
+ () => buildVaultImportPreview({ selectedPaths, destinationPath, keepVaultStructure }),
+ [selectedPaths, destinationPath, keepVaultStructure]
+ );
+ const { invalidPaths } = preview;
+
const handleImport = () => {
if (!selectedPaths.length) {
createNotification({
@@ -142,7 +163,7 @@ const Content = ({ onClose, appConnections, onImport }: ContentProps) => {
return;
}
- onImport(selectedPaths, namespace, connectionId);
+ onImport({ vaultPaths: selectedPaths, namespace, connectionId, keepVaultStructure });
onClose();
};
@@ -230,6 +251,57 @@ const Content = ({ onClose, appConnections, onImport }: ContentProps) => {
</FieldDescription>
</Field>
+ <Field
+ orientation="horizontal"
+ className="rounded-md border border-border bg-container px-3.5 py-3"
+ >
+ <Checkbox
+ id="vault-secret-import-keep-structure"
+ variant="project"
+ isChecked={keepVaultStructure}
+ onCheckedChange={(checked) => setKeepVaultStructure(checked === true)}
+ />
+ <FieldContent>
+ <FieldLabel htmlFor="vault-secret-import-keep-structure" className="cursor-pointer">
+ Preserve folder structure
+ </FieldLabel>
+ <FieldDescription>
+ Create folders inside Infisical, matching the selected Vault secret&apos;s path.
+ </FieldDescription>
+ </FieldContent>
+ </Field>
+
+ {invalidPaths.length > 0 && (
+ <Alert variant="warning">
+ <TriangleAlertIcon />
+ <AlertTitle>
+ {invalidPaths.length} secret path
+ {invalidPaths.length > 1 ? "s cannot become folders" : " cannot become a folder"}
+ </AlertTitle>
+ <AlertDescription>
+ <p>
+ Infisical folder names allow only letters, numbers, dashes and underscores. Rename
+ the following {invalidPaths.length > 1 ? "paths" : "path"} in Vault, or import
+ without preserving the folder structure.
+ </p>
+ <div className="mt-2 flex flex-wrap items-start gap-1">
+ {invalidPaths.map((path) => (
+ <Badge
+ isTruncatable
+ key={path}
+ variant="warning"
+ className="font-mono text-foreground/80"
+ >
+ {path}
+ </Badge>
+ ))}
+ </div>
+ </AlertDescription>
+ </Alert>
+ )}
+
+ {selectedPaths.length > 0 && <VaultImportPreview preview={preview} />}
+
{skippedWildcardPaths.length > 0 && (
<Alert variant="warning">
<TriangleAlertIcon />
@@ -295,7 +367,10 @@ const Content = ({ onClose, appConnections, onImport }: ContentProps) => {
variant="project"
onClick={handleImport}
isDisabled={
- !selectedPaths.length || mountsQuery.isLoading || vaultSecretPathsQuery.isLoading
+ !selectedPaths.length ||
+ invalidPaths.length > 0 ||
+ mountsQuery.isLoading ||
+ vaultSecretPathsQuery.isLoading
}
>
Import Secrets
@@ -309,6 +384,7 @@ export const VaultSecretImportModal = ({
isOpen,
onOpenChange,
appConnections,
+ destinationPath,
onImport
}: Props) => (
<Sheet open={isOpen} onOpenChange={onOpenChange}>
@@ -329,6 +405,7 @@ export const VaultSecretImportModal = ({
<Content
onClose={() => onOpenChange(false)}
appConnections={appConnections}
+ destinationPath={destinationPath}
onImport={onImport}
/>
</SheetContent>