Skip to content

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

feat(secrets): offer Share in the toast after creating secrets (#9044)

Andrew Huang0b8e306b7d54
diff --git a/frontend/src/pages/organization/SecretSharingPage/components/ShareSecret/AddShareSecretModal.tsx b/frontend/src/pages/organization/SecretSharingPage/components/ShareSecret/AddShareSecretModal.tsx
index 566b3ded79..f07510510e 100644
--- a/frontend/src/pages/organization/SecretSharingPage/components/ShareSecret/AddShareSecretModal.tsx
+++ b/frontend/src/pages/organization/SecretSharingPage/components/ShareSecret/AddShareSecretModal.tsx
@@ -55,6 +55,7 @@ export const AddShareSecretModal = ({ popUp, handlePopUpToggle }: Props) => {
<ShareSecretForm
isPublic={false}
value={(popUp.createSharedSecret.data as { value?: string })?.value}
+ secretKey={(popUp.createSharedSecret.data as { name?: string })?.name}
allowSecretSharingOutsideOrganization={
currentOrg?.allowSecretSharingOutsideOrganization ?? true
}
diff --git a/frontend/src/pages/public/ShareSecretPage/components/ShareSecretForm.tsx b/frontend/src/pages/public/ShareSecretPage/components/ShareSecretForm.tsx
index f6f8fba081..d3f7080b60 100644
--- a/frontend/src/pages/public/ShareSecretPage/components/ShareSecretForm.tsx
+++ b/frontend/src/pages/public/ShareSecretPage/components/ShareSecretForm.tsx
@@ -142,6 +142,7 @@ const formatExpiry = (expiresIn: string) => {
type Props = {
isPublic: boolean; // whether or not this is a public (non-authenticated) secret sharing form
value?: string;
+ secretKey?: string;
allowSecretSharingOutsideOrganization?: boolean;
maxSharedSecretLifetime?: number;
maxSharedSecretViewLimit?: number | null;
@@ -152,6 +153,7 @@ type Props = {
export const ShareSecretForm = ({
isPublic,
value,
+ secretKey,
allowSecretSharingOutsideOrganization = true,
maxSharedSecretLifetime,
maxSharedSecretViewLimit,
@@ -159,6 +161,7 @@ export const ShareSecretForm = ({
onDirtyChange
}: Props) => {
const [result, setResult] = useState<ShareResult | null>(null);
+ const [isSharingKeyValue, setIsSharingKeyValue] = useState(true);
const [isPasswordVisible, setIsPasswordVisible] = useToggle(false);
const subOrganization = useSearch({
strict: false,
@@ -177,6 +180,9 @@ export const ShareSecretForm = ({
const isLifetimeCapped = expiresInOptions.length !== filteredExpiresInOptions.length;
const isViewLimitEnforced = Boolean(maxSharedSecretViewLimit);
+ const formatSharedValue = (includeKey: boolean) =>
+ secretKey && includeKey ? `${secretKey}=${value ?? ""}` : (value ?? "");
+
const schema = useMemo(() => buildSchema(maxSharedSecretViewLimit), [maxSharedSecretViewLimit]);
const {
@@ -189,7 +195,7 @@ export const ShareSecretForm = ({
} = useForm<FormData>({
resolver: zodResolver(schema),
defaultValues: {
- secret: value || "",
+ secret: formatSharedValue(true),
viewLimit: maxSharedSecretViewLimit?.toString() ?? "1",
shouldLimitView: isViewLimitEnforced,
accessType: isPublic ? undefined : SecretSharingAccessType.Organization,
@@ -284,6 +290,7 @@ export const ShareSecretForm = ({
}
reset();
+ setIsSharingKeyValue(true);
};
const renderLayout = (body: ReactNode, actions: ReactNode) =>
@@ -405,10 +412,28 @@ export const ShareSecretForm = ({
isError={Boolean(error)}
/>
{isValueLocked && (
- <FieldDescription>
- Locked to the stored value, so the link shares exactly what is saved in
- Infisical.
- </FieldDescription>
+ <div className="flex items-center justify-between gap-4">
+ <FieldDescription>
+ {secretKey
+ ? "Locked to the stored value. Turn off Include Key to share the value alone."
+ : "Locked so the link shares the saved contents without edits."}
+ </FieldDescription>
+ {secretKey && (
+ <div className="flex shrink-0 items-center gap-2">
+ <Toggle
+ size="sm"
+ variant="project"
+ id="share-secret-include-key"
+ checked={isSharingKeyValue}
+ onCheckedChange={(isChecked) => {
+ setIsSharingKeyValue(isChecked);
+ setValue("secret", formatSharedValue(isChecked));
+ }}
+ />
+ <FieldLabel htmlFor="share-secret-include-key">Include Key</FieldLabel>
+ </div>
+ )}
+ </div>
)}
{error && <FieldError>{error.message}</FieldError>}
</Field>
diff --git a/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx b/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx
index c909062ed6..b7512ea3b1 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx
@@ -241,6 +241,7 @@ import {
} from "@app/hooks/utils";
import { analytics, AnalyticsEvent } from "@app/lib/analytics";
import { OverviewFlowProperties, OverviewScopeProperties } from "@app/lib/analytics/events";
+import { AddShareSecretModal } from "@app/pages/organization/SecretSharingPage/components/ShareSecret/AddShareSecretModal";
import { RequestAccessModal } from "@app/pages/secret-manager/SecretApprovalsPage/components/AccessApprovalRequest/components/RequestAccessModal";
import { AddEnvironmentModal } from "@app/pages/secret-manager/SettingsPage/components/EnvironmentSection/AddEnvironmentModal";
@@ -316,6 +317,7 @@ import {
overviewResponsePhase,
withOverviewTelemetry
} from "./OverviewTelemetry";
+import { useNotifySecretsCreated } from "./useNotifySecretsCreated";
export enum EntryType {
FOLDER = "folder",
@@ -1602,7 +1604,8 @@ const OverviewPageContent = () => {
"importFromDoppler",
"editHoneyToken",
"revokeHoneyToken",
- "createEnvironment"
+ "createEnvironment",
+ "createSharedSecret"
] as const);
const popupFlows = useMemo<
Partial<Record<keyof typeof popUp, Omit<OverviewFlowProperties, "phase">>>
@@ -1659,6 +1662,21 @@ const OverviewPageContent = () => {
if (flow) overviewTelemetry.flow({ ...flow, phase: opening ? "opened" : "canceled" });
togglePopUp(name, isOpen);
};
+ const isShareSheetOpenRef = useRef(false);
+ useEffect(() => {
+ isShareSheetOpenRef.current = popUp.createSharedSecret.isOpen;
+ }, [popUp.createSharedSecret.isOpen]);
+ const notifySecretsCreated = useNotifySecretsCreated(
+ secretPath,
+ useCallback(
+ (share) => {
+ if (isShareSheetOpenRef.current) return false;
+ handlePopUpOpen("createSharedSecret", share);
+ return true;
+ },
+ [handlePopUpOpen]
+ )
+ );
const { openUpgradeGate: openSharedUpgradeGate, upgradeGate } = useUpgradeGate();
const [commitHistoryEnv, setCommitHistoryEnv] = useState<{ slug: string; name: string } | null>(
null
@@ -2320,10 +2338,7 @@ const OverviewPageContent = () => {
text: "Requested change has been sent for review"
});
} else {
- createNotification({
- type: "success",
- text: "Successfully created secret"
- });
+ notifySecretsCreated(1, type === SecretType.Shared ? [{ environment: env, key, value }] : []);
// The user just created a secret: check whether to surface the activation nudge.
checkSecretsActivation();
@@ -2967,7 +2982,25 @@ const OverviewPageContent = () => {
return [];
}
- if (isSingleChange) {
+ const createdSecrets = changes.secrets.flatMap((change) =>
+ change.type === PendingAction.Create
+ ? [
+ {
+ environment,
+ key: change.secretKey,
+ value: change.secretValue,
+ tags: change.tags?.map((tag) => tag.slug)
+ }
+ ]
+ : []
+ );
+ if (createdSecrets.length) {
+ notifySecretsCreated(
+ createdSecrets.length,
+ createdSecrets,
+ createdSecrets.length === changeCount ? undefined : `${changeCount} changes committed`
+ );
+ } else if (isSingleChange) {
const change = secretChange ?? folderChange;
const pastTense = {
[PendingAction.Create]: "created",
@@ -3004,7 +3037,8 @@ const OverviewPageContent = () => {
createFolder,
updateFolder,
deleteFolder,
- checkSecretsActivation
+ checkSecretsActivation,
+ notifySecretsCreated
]
);
@@ -4940,6 +4974,7 @@ const OverviewPageContent = () => {
defaultSelectedEnvs={filteredEnvs}
onClose={() => handlePopUpClose("addSecretsInAllEnvs")}
onSecretCreated={checkSecretsActivation}
+ notifySecretsCreated={notifySecretsCreated}
onUploadSecrets={(env) => {
setImportParsedSecrets(env ?? null);
handlePopUpClose("addSecretsInAllEnvs");
@@ -5304,6 +5339,7 @@ const OverviewPageContent = () => {
initialFile={importSecretsInitialFile}
initialStep={importSecretsInitialStep}
initialSelectedEnvironments={visibleEnvs}
+ notifySecretsCreated={notifySecretsCreated}
onComplete={(envSlugs) => {
const visibleSlugs = new Set(visibleEnvs.map((e) => e.slug));
const allTargetEnvsVisible = envSlugs.every((slug) => visibleSlugs.has(slug));
@@ -5414,6 +5450,7 @@ const OverviewPageContent = () => {
isPending={isDeleteEnvironmentPending}
onConfirm={handleDeleteEnvironment}
/>
+ <AddShareSecretModal popUp={popUp} handlePopUpToggle={handlePopUpToggle} />
{!!pathPolicies && pathPolicies.length > 0 && (
<RequestAccessModal
policies={pathPolicies}
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/CreateSecretForm/CreateSecretForm.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/CreateSecretForm/CreateSecretForm.tsx
index cff852f007..128ede66cd 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/CreateSecretForm/CreateSecretForm.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/CreateSecretForm/CreateSecretForm.tsx
@@ -68,6 +68,10 @@ import {
overviewResponsePhase,
useOverviewTelemetry
} from "../../OverviewTelemetry";
+import {
+ notifySecretsCreatedWithoutShare,
+ TNotifySecretsCreated
+} from "../../useNotifySecretsCreated";
import { didAllSecretCreationsSucceed } from "./createSecretFormState";
const MAX_SECRETS_PER_COMMIT = 1000;
@@ -153,6 +157,7 @@ type Props = {
// Called after the user actually creates a secret (non-batch path) so the parent can run the
// activation nudge. The parent owns the nudge hook + modal state, so this stays a callback.
onSecretCreated?: () => void;
+ notifySecretsCreated?: TNotifySecretsCreated;
// Called when the user opts to bulk-upload secrets instead. The parent owns the import modal,
// so it swaps popups; when the user pasted multiple KEY=VALUE pairs, the parsed set is passed
// along so the modal can skip its upload step.
@@ -165,6 +170,7 @@ export const CreateSecretForm = ({
onClose,
editSecret,
onSecretCreated,
+ notifySecretsCreated = notifySecretsCreatedWithoutShare,
onUploadSecrets
}: Props) => {
const overviewTelemetry = useOverviewTelemetry();
@@ -443,10 +449,15 @@ export const CreateSecretForm = ({
text: "Requested changes have been sent for review"
});
} else {
- createNotification({
- type: "success",
- text: `${result.secrets.created.length} secrets created`
- });
+ notifySecretsCreated(
+ result.secrets.created.length,
+ secrets.map((secret) => ({
+ environment: selectedEnv[0].slug,
+ key: secret.key,
+ value: secret.value,
+ tags: secret.tags?.map((tag) => tag.label)
+ }))
+ );
onSecretCreated?.();
}
if (attempt.isCurrent() && formOwner.current.invocation === invocation) {
@@ -475,7 +486,8 @@ export const CreateSecretForm = ({
tagIds: secret.tags?.map((tag) => tag.value),
secretMetadata: filteredMetadata?.length ? filteredMetadata : undefined
})),
- environment
+ environment,
+ secret
};
})
);
@@ -530,12 +542,21 @@ export const CreateSecretForm = ({
}
if (updatedEnvs.length) {
- createNotification({
- type: "success",
- text: `Secrets created in ${
- updatedEnvs.length > 1 ? "environments" : "environment"
- }: ${updatedEnvs.join(", ")}`
- });
+ notifySecretsCreated(
+ responseCount,
+ results.flatMap((result) =>
+ result.status === "fulfilled" && !("approval" in result.value)
+ ? [
+ {
+ environment: result.value.environment,
+ key: result.value.secret.key,
+ value: result.value.secret.value,
+ tags: result.value.secret.tags?.map((tag) => tag.label)
+ }
+ ]
+ : []
+ )
+ );
// The user just created a secret: let the parent check whether to surface the nudge.
onSecretCreated?.();
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SecretDropzone/ImportSecretsModal.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SecretDropzone/ImportSecretsModal.tsx
index e0d1678a04..3338261618 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/SecretDropzone/ImportSecretsModal.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SecretDropzone/ImportSecretsModal.tsx
@@ -75,6 +75,11 @@ import {
overviewResponsePhase,
useOverviewTelemetry
} from "../../OverviewTelemetry";
+import {
+ notifySecretsCreatedWithoutShare,
+ TCreatedSecret,
+ TNotifySecretsCreated
+} from "../../useNotifySecretsCreated";
import { normalizeCopyPath } from "../CopySecretsSheet/copySecrets.utils";
import { getCopySecretsQueryOptions } from "../CopySecretsSheet/useCopySecretsQuery";
import { SecretConflictsDialog } from "../SecretConflictsDialog";
@@ -107,6 +112,7 @@ type Props = {
initialFile?: File | null;
initialStep?: "upload" | "paste";
initialSelectedEnvironments?: { name: string; slug: string }[];
+ notifySecretsCreated?: TNotifySecretsCreated;
onComplete?: (envSlugs: string[]) => void;
};
@@ -131,6 +137,7 @@ type ContentProps = {
initialFile?: File | null;
initialStep?: "upload" | "paste";
initialSelectedEnvironments?: { name: string; slug: string }[];
+ notifySecretsCreated?: TNotifySecretsCreated;
onComplete?: (envSlugs: string[]) => void;
onClose: () => boolean;
onLockChange?: (isLocked: boolean) => void;
@@ -145,6 +152,7 @@ const ImportSecretsContent = ({
initialFile,
initialStep = "upload",
initialSelectedEnvironments = [],
+ notifySecretsCreated = notifySecretsCreatedWithoutShare,
onComplete,
onClose,
onLockChange,
@@ -470,6 +478,7 @@ const ImportSecretsContent = ({
let failureCount = 0;
let folderResponseCount = 0;
let folderFailureCount = 0;
+ const shareableSecrets: TCreatedSecret[] = [];
try {
const requestedSlugs = new Set<string>();
@@ -511,6 +520,18 @@ const ImportSecretsContent = ({
}
const skippedCountByEnv = new Map<string, number>();
+ const createdCountByEnv = new Map<string, number>();
+ const updatedCountByEnv = new Map<string, number>();
+ const addCount = (
+ counts: Map<string, number>,
+ environment: string,
+ result: object,
+ count: number
+ ) => {
+ if (!("approval" in result))
+ counts.set(environment, (counts.get(environment) ?? 0) + count);
+ return result;
+ };
const resolveTagIds = (slugs?: string[]): string[] | undefined => {
if (!slugs?.length) return undefined;
@@ -568,6 +589,7 @@ const ImportSecretsContent = ({
const existingSecrets = mergePersonalSecrets(rawExisting);
const existingKeys = new Set(existingSecrets.map((s) => s.key));
+ const existingSecretsByKey = new Map(existingSecrets.map((s) => [s.key, s]));
// Resolve edited keys (file-based secrets can be renamed in the review table)
const resolvedEntries = Object.entries(secrets).map(([origKey, secretData]) => ({
@@ -622,6 +644,20 @@ const ImportSecretsContent = ({
environment,
secretPath: path,
secrets: secretsToCreate
+ }).then((result) => {
+ addCount(createdCountByEnv, environment, result, secretsToCreate.length);
+ if (!("approval" in result))
+ shareableSecrets.push(
+ ...resolvedEntries
+ .filter(({ finalKey }) => !existingKeys.has(finalKey))
+ .map(({ finalKey, secretData }) => ({
+ environment,
+ key: finalKey,
+ value: secretData.value,
+ tags: secretData.tagSlugs?.filter((slug) => slugToTagId.has(slug))
+ }))
+ );
+ return result;
})
]
: []),
@@ -632,6 +668,35 @@ const ImportSecretsContent = ({
environment,
secretPath: path,
secrets: secretsToUpdate
+ }).then((result) => {
+ addCount(updatedCountByEnv, environment, result, secretsToUpdate.length);
+ if (!("approval" in result))
+ shareableSecrets.push(
+ ...resolvedEntries.flatMap(({ finalKey, secretData }) => {
+ const existing = existingSecretsByKey.get(finalKey);
+ // The API keeps the stored value of rotated secrets and honey tokens
+ if (
+ !existing ||
+ existing.isRotatedSecret ||
+ existing.isHoneyTokenSecret
+ )
+ return [];
+ const uploadedTags = secretData.tagSlugs?.filter((slug) =>
+ slugToTagId.has(slug)
+ );
+ return [
+ {
+ environment,
+ key: finalKey,
+ value: secretData.value,
+ tags: uploadedTags?.length
+ ? uploadedTags
+ : existing.tags?.map((tag) => tag.slug)
+ }
+ ];
+ })
+ );
+ return result;
})
]
: [])
@@ -654,10 +719,14 @@ const ImportSecretsContent = ({
);
const results = await Promise.allSettled([
...creates.chunks.map((chunk) =>
- enqueue(() => createNestedSecretBatch({ ...envelope, secrets: chunk }))
+ enqueue(() => createNestedSecretBatch({ ...envelope, secrets: chunk })).then((result) =>
+ addCount(createdCountByEnv, environment, result, chunk.length)
+ )
),
...updates.chunks.map((chunk) =>
- enqueue(() => updateNestedSecretBatch({ ...envelope, secrets: chunk }))
+ enqueue(() => updateNestedSecretBatch({ ...envelope, secrets: chunk })).then((result) =>
+ addCount(updatedCountByEnv, environment, result, chunk.length)
+ )
),
...(oversizedKeys.length ? [Promise.reject(new Error("Secret exceeds 1 MB"))] : [])
]);
@@ -823,13 +892,28 @@ const ImportSecretsContent = ({
(count, slug) => count + (skippedCountByEnv.get(slug) ?? 0),
0
);
- if (successEnvs.length) {
- createNotification({
- type: "success",
- text: skippedCount
- ? `Uploaded secrets${folderSummary} into ${successEnvs.join(", ")}; ${skippedCount} existing ${skippedCount === 1 ? "secret" : "secrets"} skipped`
- : `Successfully uploaded ${secretCount} secret${secretCount > 1 ? "s" : ""}${folderSummary} into ${successEnvs.join(", ")}`
- });
+ const sumAll = (counts: Map<string, number>) =>
+ [...counts.values()].reduce((count, value) => count + value, 0);
+ const createdCount = sumAll(createdCountByEnv);
+ const updatedCount = sumAll(updatedCountByEnv);
+ const existingDetail = [
+ updatedCount &&
+ `${updatedCount} existing ${updatedCount === 1 ? "secret" : "secrets"} overwritten`,
+ skippedCount &&
+ `${skippedCount} existing ${skippedCount === 1 ? "secret" : "secrets"} skipped`
+ ]
+ .filter(Boolean)
+ .join(", ");
+ if (createdCount) {
+ notifySecretsCreated(createdCount, shareableSecrets, existingDetail || undefined);
+ } else if (successEnvs.length || updatedCount) {
+ notifySecretsCreated(
+ 0,
+ shareableSecrets,
+ successEnvs.length
+ ? `Uploaded secrets${folderSummary} into ${successEnvs.join(", ")}; ${existingDetail || "no new secrets"}`
+ : `Uploaded secrets${folderSummary}; ${existingDetail}`
+ );
}
if (approvalEnvs.length) {
@@ -1432,6 +1516,7 @@ export const ImportSecretsSheet = ({
initialFile,
initialStep,
initialSelectedEnvironments,
+ notifySecretsCreated,
onComplete
}: Props) => {
const telemetry = useOverviewTelemetry();
@@ -1498,6 +1583,7 @@ export const ImportSecretsSheet = ({
initialFile={initialFile}
initialStep={initialStep}
initialSelectedEnvironments={initialSelectedEnvironments}
+ notifySecretsCreated={notifySecretsCreated}
onComplete={onComplete}
onClose={() => closeSheet(false)}
onLockChange={handleLockChange}
diff --git a/frontend/src/pages/secret-manager/OverviewPage/useNotifySecretsCreated.tsx b/frontend/src/pages/secret-manager/OverviewPage/useNotifySecretsCreated.tsx
new file mode 100644
index 0000000000..509dc281fb
--- /dev/null
+++ b/frontend/src/pages/secret-manager/OverviewPage/useNotifySecretsCreated.tsx
@@ -0,0 +1,123 @@
+import { useCallback, useEffect, useRef } from "react";
+
+import { createNotification, dismissNotification } from "@app/components/notifications";
+import { Button } from "@app/components/v3";
+import { useProject, useProjectPermission } from "@app/context";
+import { ProjectPermissionSecretActions } from "@app/context/ProjectPermissionContext/types";
+import { hasSecretReadValueOrDescribePermission } from "@app/lib/fn/permission";
+
+export type TCreatedSecret = {
+ environment: string;
+ key: string;
+ value?: string;
+ tags?: string[];
+};
+
+export type TNotifySecretsCreated = (
+ createdCount: number,
+ secrets: TCreatedSecret[],
+ detail?: string
+) => void;
+
+export type TCreatedSecretsShare = { value: string; name?: string };
+
+const MAX_SHARED_SECRET_LENGTH = 10_000;
+
+const toEnvLine = (key: string, value: string) =>
+ /[\n"'#]|^\s|\s$/.test(value)
+ ? `${key}="${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n")}"`
+ : `${key}=${value}`;
+
+// Mirrors the API, which trims created values but keeps one trailing newline.
+const toSavedValue = (value: string) =>
+ value.at(-1) === "\n" ? `${value.trim()}\n` : value.trim();
+
+// With nothing newly created (an upload that only overwrote), the detail is the whole message.
+const toCreatedNotification = (createdCount: number, detail?: string) => {
+ if (!createdCount && detail) return { text: detail };
+ const title = `${createdCount} New Secret${createdCount === 1 ? "" : "s"} Created`;
+ return detail ? { title, text: detail } : { text: title };
+};
+
+export const notifySecretsCreatedWithoutShare: TNotifySecretsCreated = (
+ createdCount,
+ _,
+ detail
+) => {
+ createNotification({ type: "success", ...toCreatedNotification(createdCount, detail) });
+};
+
+// Several secrets share as one KEY=value per line, so the recipient gets a pasteable .env block.
+export const useNotifySecretsCreated = (
+ secretPath: string,
+ onShare: (share: TCreatedSecretsShare) => boolean
+): TNotifySecretsCreated => {
+ const { currentProject } = useProject();
+ const { permission } = useProjectPermission();
+ const shareNotificationIds = useRef(new Set<string | number>());
+
+ useEffect(() => {
+ const ids = shareNotificationIds.current;
+ return () => ids.forEach((id) => dismissNotification(id));
+ }, []);
+
+ return useCallback(
+ (createdCount, secrets, detail) => {
+ const shareable = new Map<string, string>();
+ if (currentProject.secretSharing) {
+ secrets.forEach(({ environment, key, value, tags }) => {
+ const savedValue = toSavedValue(value ?? "");
+ if (!savedValue || shareable.has(key)) return;
+ const canReadValue = hasSecretReadValueOrDescribePermission(
+ permission,
+ ProjectPermissionSecretActions.ReadValue,
+ { environment, secretPath, secretName: key, secretTags: tags ?? [] }
+ );
+ if (canReadValue) shareable.set(key, savedValue);
+ });
+ }
+
+ const entries = [...shareable.entries()];
+ const share: TCreatedSecretsShare =
+ entries.length === 1
+ ? { name: entries[0][0], value: entries[0][1] }
+ : { value: entries.map(([key, value]) => toEnvLine(key, value)).join("\n") };
+ const sharedLength = share.name
+ ? share.name.length + 1 + share.value.length
+ : share.value.length;
+
+ if (!entries.length || sharedLength > MAX_SHARED_SECRET_LENGTH) {
+ createNotification({ type: "success", ...toCreatedNotification(createdCount, detail) });
+ return;
+ }
+
+ const notificationId = createNotification(
+ {
+ type: "success",
+ ...toCreatedNotification(createdCount, detail),
+ callToAction: (
+ <Button
+ size="xs"
+ variant="outline"
+ onClick={() => {
+ if (!onShare(share)) {
+ createNotification({
+ type: "info",
+ text: "Close the open share before sharing another secret."
+ });
+ return;
+ }
+ dismissNotification(notificationId);
+ }}
+ >
+ {entries.length === 1 ? "Share Secret" : `Share ${entries.length} Secrets`}
+ </Button>
+ )
+ },
+ { duration: 8000 }
+ );
+ shareNotificationIds.current.add(notificationId);
+ },
+ [currentProject.secretSharing, permission, secretPath, onShare]
+ );
+};