Skip to content

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

template seeding helper

Andreydb0d0363e089
diff --git a/frontend/src/pages/pam/PamTemplatesPage/PamTemplatesPage.tsx b/frontend/src/pages/pam/PamTemplatesPage/PamTemplatesPage.tsx
index 80c390227a..f53fa09482 100644
--- a/frontend/src/pages/pam/PamTemplatesPage/PamTemplatesPage.tsx
+++ b/frontend/src/pages/pam/PamTemplatesPage/PamTemplatesPage.tsx
@@ -56,6 +56,7 @@ import { PAM_TEMPLATE_TABS } from "../components/pamResourceTabs";
import { PamDocsUrls } from "../pam-docs-urls";
import { CreateTemplateModal } from "./components/CreateTemplateModal";
import { DeleteTemplateModal } from "./components/DeleteTemplateModal";
+import { MissingTemplatesCallout } from "./components/MissingTemplatesCallout";
import { TemplateDetailSheet } from "./components/TemplateDetailSheet";
const TemplateRow = ({
@@ -187,6 +188,8 @@ export const PamTemplatesPage = () => {
description="Define the rules that apply when users connect to accounts."
/>
+ <MissingTemplatesCallout templates={templates} accountTypes={accountTypes} />
+
<Card className="mt-4">
<CardHeader>
<CardTitle>
diff --git a/frontend/src/pages/pam/PamTemplatesPage/components/MissingTemplatesCallout.tsx b/frontend/src/pages/pam/PamTemplatesPage/components/MissingTemplatesCallout.tsx
new file mode 100644
index 0000000000..1c085da0e9
--- /dev/null
+++ b/frontend/src/pages/pam/PamTemplatesPage/components/MissingTemplatesCallout.tsx
@@ -0,0 +1,72 @@
+import { useMemo } from "react";
+import { InfoIcon } from "lucide-react";
+
+import { createNotification } from "@app/components/notifications";
+import { AlertDescription, AlertTitle, DismissableAlert } from "@app/components/v3";
+import { useCreatePamAccountTemplate } from "@app/hooks/api/pam";
+import type {
+ TPamAccountTemplateWithCount,
+ TPamAccountTypeMetadata
+} from "@app/hooks/api/pam/types";
+
+type Props = {
+ templates?: TPamAccountTemplateWithCount[];
+ accountTypes: TPamAccountTypeMetadata[];
+};
+
+export const MissingTemplatesCallout = ({ templates, accountTypes }: Props) => {
+ const createTemplate = useCreatePamAccountTemplate();
+
+ const missing = useMemo(() => {
+ if (!templates) return [];
+ const covered = new Set(templates.map((template) => template.type));
+ return accountTypes.filter((meta) => !covered.has(meta.type));
+ }, [templates, accountTypes]);
+
+ if (missing.length === 0) return null;
+
+ const handleAdd = async () => {
+ const results = await Promise.allSettled(
+ missing.map((meta) => createTemplate.mutateAsync({ name: meta.type, type: meta.type }))
+ );
+
+ const failed = results.filter((result) => result.status === "rejected").length;
+ if (failed === results.length) return;
+
+ createNotification({
+ type: failed ? "warning" : "success",
+ text: failed
+ ? `Added ${results.length - failed} of ${results.length} default templates`
+ : `Added ${results.length} default template${results.length === 1 ? "" : "s"}`
+ });
+ };
+
+ return (
+ <DismissableAlert
+ variant="info"
+ className="mt-4"
+ actionKey={`pam_missing_templates_${missing.map((meta) => meta.type).join("_")}`}
+ >
+ <InfoIcon />
+ <AlertTitle>
+ {missing.length} account type{missing.length === 1 ? "" : "s"} without a template
+ </AlertTitle>
+ <AlertDescription>
+ <p>
+ Accounts can&apos;t be created for {missing.map((meta) => meta.name).join(", ")} until a
+ template exists.{" "}
+ <button
+ type="button"
+ disabled={createTemplate.isPending}
+ onClick={handleAdd}
+ className="inline cursor-pointer underline hover:opacity-80 disabled:cursor-default disabled:opacity-60"
+ >
+ {createTemplate.isPending
+ ? "Adding..."
+ : `Add default template${missing.length === 1 ? "" : "s"}`}
+ </button>
+ </p>
+ </AlertDescription>
+ </DismissableAlert>
+ );
+};