Merge pull request #2004 from Infisical/daniel/show-imported-overwritten-values-overview

feat(platform): Show imported/overwritten values in secret overview
This commit is contained in:
Maidul Islam
2024-06-21 17:13:02 -04:00
committed by GitHub
18 changed files with 152 additions and 65 deletions
@@ -6,6 +6,8 @@ import { faUpload } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { parseDocument, Scalar, YAMLMap } from "yaml"; import { parseDocument, Scalar, YAMLMap } from "yaml";
import { SecretType } from "@app/hooks/api/types";
import Button from "../basic/buttons/Button"; import Button from "../basic/buttons/Button";
import Error from "../basic/Error"; import Error from "../basic/Error";
import { createNotification } from "../notifications"; import { createNotification } from "../notifications";
@@ -33,7 +35,6 @@ const DropZone = ({
numCurrentRows numCurrentRows
}: DropZoneProps) => { }: DropZoneProps) => {
const { t } = useTranslation(); const { t } = useTranslation();
const handleDragEnter = (e: DragEvent) => { const handleDragEnter = (e: DragEvent) => {
e.preventDefault(); e.preventDefault();
@@ -66,7 +67,7 @@ const DropZone = ({
key, key,
value: keyPairs[key as keyof typeof keyPairs].value, value: keyPairs[key as keyof typeof keyPairs].value,
comment: keyPairs[key as keyof typeof keyPairs].comments.join("\n"), comment: keyPairs[key as keyof typeof keyPairs].comments.join("\n"),
type: "shared", type: SecretType.Shared,
tags: [] tags: []
})); }));
break; break;
@@ -79,7 +80,7 @@ const DropZone = ({
key, key,
value: keyPairs[key as keyof typeof keyPairs], value: keyPairs[key as keyof typeof keyPairs],
comment: "", comment: "",
type: "shared", type: SecretType.Shared,
tags: [] tags: []
})); }));
break; break;
@@ -102,7 +103,7 @@ const DropZone = ({
key, key,
value: keyPairs[key as keyof typeof keyPairs]?.toString() ?? "", value: keyPairs[key as keyof typeof keyPairs]?.toString() ?? "",
comment, comment,
type: "shared", type: SecretType.Shared,
tags: [] tags: []
}; };
}); });
@@ -132,7 +133,7 @@ const DropZone = ({
if (file === undefined) { if (file === undefined) {
createNotification({ createNotification({
text: "You can't inject files from VS Code. Click 'Reveal in finder', and drag your file directly from the directory where it's located.", text: "You can't inject files from VS Code. Click 'Reveal in finder', and drag your file directly from the directory where it's located.",
type: "error", type: "error"
}); });
setLoading(false); setLoading(false);
return; return;
@@ -1,5 +1,7 @@
import { SecretDataProps } from "public/data/frequentInterfaces"; import { SecretDataProps } from "public/data/frequentInterfaces";
import { SecretType } from "@app/hooks/api/types";
/** /**
* This function downloads the secrets as a .env file * This function downloads the secrets as a .env file
* @param {object} obj * @param {object} obj
@@ -10,8 +12,8 @@ const checkOverrides = async ({ data }: { data: SecretDataProps[] }) => {
let secrets: SecretDataProps[] = data!.map((secret) => Object.create(secret)); let secrets: SecretDataProps[] = data!.map((secret) => Object.create(secret));
const overridenSecrets = data!.filter((secret) => const overridenSecrets = data!.filter((secret) =>
secret.valueOverride === undefined || secret?.value !== secret?.valueOverride secret.valueOverride === undefined || secret?.value !== secret?.valueOverride
? "shared" ? SecretType.Shared
: "personal" : SecretType.Personal
); );
if (overridenSecrets.length) { if (overridenSecrets.length) {
overridenSecrets.forEach((secret) => { overridenSecrets.forEach((secret) => {
@@ -3,6 +3,7 @@ import crypto from "crypto";
import { SecretDataProps, Tag } from "public/data/frequentInterfaces"; import { SecretDataProps, Tag } from "public/data/frequentInterfaces";
import { fetchUserWsKey } from "@app/hooks/api/keys/queries"; import { fetchUserWsKey } from "@app/hooks/api/keys/queries";
import { SecretType } from "@app/hooks/api/types";
import { decryptAssymmetric, encryptSymmetric } from "../cryptography/crypto"; import { decryptAssymmetric, encryptSymmetric } from "../cryptography/crypto";
@@ -20,7 +21,7 @@ interface EncryptedSecretProps {
secretValueCiphertext: string; secretValueCiphertext: string;
secretValueIV: string; secretValueIV: string;
secretValueTag: string; secretValueTag: string;
type: "personal" | "shared"; type: SecretType;
tags: Tag[]; tags: Tag[];
} }
@@ -108,8 +109,8 @@ const encryptSecrets = async ({
secretCommentTag, secretCommentTag,
type: type:
secret.valueOverride === undefined || secret?.value !== secret?.valueOverride secret.valueOverride === undefined || secret?.value !== secret?.valueOverride
? "shared" ? SecretType.Shared
: "personal", : SecretType.Personal,
tags: secret.tags tags: secret.tags
}; };
@@ -15,7 +15,7 @@ const replaceContentWithDot = (str: string) => {
}; };
const syntaxHighlight = (content?: string | null, isVisible?: boolean, isImport?: boolean) => { const syntaxHighlight = (content?: string | null, isVisible?: boolean, isImport?: boolean) => {
if (isImport) return "IMPORTED"; if (isImport && !content) return "IMPORTED";
if (content === "") return "EMPTY"; if (content === "") return "EMPTY";
if (!content) return "EMPTY"; if (!content) return "EMPTY";
if (!isVisible) return replaceContentWithDot(content); if (!isVisible) return replaceContentWithDot(content);
@@ -279,7 +279,28 @@ export const useGetImportedSecretsAllEnvs = ({
[(secretImports || []).map((response) => response.data)] [(secretImports || []).map((response) => response.data)]
); );
return { secretImports, isImportedSecretPresentInEnv }; const getImportedSecretByKey = useCallback(
(envSlug: string, secretName: string) => {
const selectedEnvIndex = environments.indexOf(envSlug);
if (selectedEnvIndex !== -1) {
const secret = secretImports?.[selectedEnvIndex]?.data?.find(({ secrets }) =>
secrets.find((s) => s.key === secretName)
);
if (!secret) return undefined;
return {
secret: secret?.secrets.find((s) => s.key === secretName),
environmentInfo: secret?.environmentInfo
};
}
return undefined;
},
[(secretImports || []).map((response) => response.data)]
);
return { secretImports, isImportedSecretPresentInEnv, getImportedSecretByKey };
}; };
export const useGetImportedFoldersByEnv = ({ export const useGetImportedFoldersByEnv = ({
@@ -7,7 +7,7 @@ import {
} from "@app/components/utilities/cryptography/crypto"; } from "@app/components/utilities/cryptography/crypto";
import { apiRequest } from "@app/config/request"; import { apiRequest } from "@app/config/request";
import { DecryptedSecret } from "../secrets/types"; import { DecryptedSecret, SecretType } from "../secrets/types";
import { import {
TGetSecretSnapshotsDTO, TGetSecretSnapshotsDTO,
TSecretRollbackDTO, TSecretRollbackDTO,
@@ -112,7 +112,7 @@ export const useGetSnapshotSecrets = ({ decryptFileKey, snapshotId }: TSnapshotD
version: encSecret.version version: encSecret.version
}; };
if (encSecret.type === "personal") { if (encSecret.type === SecretType.Personal) {
personalSecrets[decryptedSecret.key] = { id: encSecret.secretId, value: secretValue }; personalSecrets[decryptedSecret.key] = { id: encSecret.secretId, value: secretValue };
} else { } else {
sharedSecrets.push(decryptedSecret); sharedSecrets.push(decryptedSecret);
+2 -1
View File
@@ -14,6 +14,7 @@ import {
EncryptedSecret, EncryptedSecret,
EncryptedSecretVersion, EncryptedSecretVersion,
GetSecretVersionsDTO, GetSecretVersionsDTO,
SecretType,
TGetProjectSecretsAllEnvDTO, TGetProjectSecretsAllEnvDTO,
TGetProjectSecretsDTO, TGetProjectSecretsDTO,
TGetProjectSecretsKey TGetProjectSecretsKey
@@ -77,7 +78,7 @@ export const decryptSecrets = (
skipMultilineEncoding: encSecret.skipMultilineEncoding skipMultilineEncoding: encSecret.skipMultilineEncoding
}; };
if (encSecret.type === "personal") { if (encSecret.type === SecretType.Personal) {
personalSecrets[decryptedSecret.key] = { personalSecrets[decryptedSecret.key] = {
id: encSecret.id, id: encSecret.id,
value: secretValue value: secretValue
+14 -9
View File
@@ -1,11 +1,16 @@
import type { UserWsKeyPair } from "../keys/types"; import type { UserWsKeyPair } from "../keys/types";
import type { WsTag } from "../tags/types"; import type { WsTag } from "../tags/types";
export enum SecretType {
Shared = "shared",
Personal = "personal"
}
export type EncryptedSecret = { export type EncryptedSecret = {
id: string; id: string;
version: number; version: number;
workspace: string; workspace: string;
type: "shared" | "personal"; type: SecretType;
environment: string; environment: string;
secretKeyCiphertext: string; secretKeyCiphertext: string;
secretKeyIV: string; secretKeyIV: string;
@@ -49,7 +54,7 @@ export type EncryptedSecretVersion = {
secretId: string; secretId: string;
version: number; version: number;
workspace: string; workspace: string;
type: string; type: SecretType;
isDeleted: boolean; isDeleted: boolean;
envId: string; envId: string;
secretKeyCiphertext: string; secretKeyCiphertext: string;
@@ -101,14 +106,14 @@ export type TCreateSecretsV3DTO = {
secretPath: string; secretPath: string;
workspaceId: string; workspaceId: string;
environment: string; environment: string;
type: string; type: SecretType;
}; };
export type TUpdateSecretsV3DTO = { export type TUpdateSecretsV3DTO = {
latestFileKey: UserWsKeyPair; latestFileKey: UserWsKeyPair;
workspaceId: string; workspaceId: string;
environment: string; environment: string;
type: string; type: SecretType;
secretPath: string; secretPath: string;
skipMultilineEncoding?: boolean; skipMultilineEncoding?: boolean;
newSecretName?: string; newSecretName?: string;
@@ -124,7 +129,7 @@ export type TUpdateSecretsV3DTO = {
export type TDeleteSecretsV3DTO = { export type TDeleteSecretsV3DTO = {
workspaceId: string; workspaceId: string;
environment: string; environment: string;
type: "shared" | "personal"; type: SecretType;
secretPath: string; secretPath: string;
secretName: string; secretName: string;
secretId?: string; secretId?: string;
@@ -140,7 +145,7 @@ export type TCreateSecretBatchDTO = {
secretValue: string; secretValue: string;
secretComment: string; secretComment: string;
skipMultilineEncoding?: boolean; skipMultilineEncoding?: boolean;
type: "shared" | "personal"; type: SecretType;
metadata?: { metadata?: {
source?: string; source?: string;
}; };
@@ -153,7 +158,7 @@ export type TUpdateSecretBatchDTO = {
secretPath: string; secretPath: string;
latestFileKey: UserWsKeyPair; latestFileKey: UserWsKeyPair;
secrets: Array<{ secrets: Array<{
type: "shared" | "personal"; type: SecretType;
secretName: string; secretName: string;
skipMultilineEncoding?: boolean; skipMultilineEncoding?: boolean;
secretValue: string; secretValue: string;
@@ -168,14 +173,14 @@ export type TDeleteSecretBatchDTO = {
secretPath: string; secretPath: string;
secrets: Array<{ secrets: Array<{
secretName: string; secretName: string;
type: "shared" | "personal"; type: SecretType;
}>; }>;
}; };
export type CreateSecretDTO = { export type CreateSecretDTO = {
workspaceId: string; workspaceId: string;
environment: string; environment: string;
type: "shared" | "personal"; type: SecretType;
secretKey: string; secretKey: string;
secretKeyCiphertext: string; secretKeyCiphertext: string;
secretKeyIV: string; secretKeyIV: string;
@@ -47,7 +47,7 @@ import { ProjectPermissionActions, ProjectPermissionSub, useSubscription } from
import { interpolateSecrets } from "@app/helpers/secret"; import { interpolateSecrets } from "@app/helpers/secret";
import { usePopUp } from "@app/hooks"; import { usePopUp } from "@app/hooks";
import { useCreateFolder, useDeleteSecretBatch, useGetUserWsKey } from "@app/hooks/api"; import { useCreateFolder, useDeleteSecretBatch, useGetUserWsKey } from "@app/hooks/api";
import { DecryptedSecret, TImportedSecrets, WsTag } from "@app/hooks/api/types"; import { DecryptedSecret, SecretType, TImportedSecrets, WsTag } from "@app/hooks/api/types";
import { debounce } from "@app/lib/fn/debounce"; import { debounce } from "@app/lib/fn/debounce";
import { import {
@@ -211,7 +211,7 @@ export const ActionBar = ({
secretPath, secretPath,
workspaceId, workspaceId,
environment, environment,
secrets: bulkDeletedSecrets.map(({ key }) => ({ secretName: key, type: "shared" })) secrets: bulkDeletedSecrets.map(({ key }) => ({ secretName: key, type: SecretType.Shared }))
}); });
resetSelectedSecret(); resetSelectedSecret();
handlePopUpClose("bulkDeleteSecrets"); handlePopUpClose("bulkDeleteSecrets");
@@ -6,7 +6,7 @@ import { createNotification } from "@app/components/notifications";
import { Button, FormControl, Input, Modal, ModalContent } from "@app/components/v2"; import { Button, FormControl, Input, Modal, ModalContent } from "@app/components/v2";
import { InfisicalSecretInput } from "@app/components/v2/InfisicalSecretInput"; import { InfisicalSecretInput } from "@app/components/v2/InfisicalSecretInput";
import { useCreateSecretV3 } from "@app/hooks/api"; import { useCreateSecretV3 } from "@app/hooks/api";
import { UserWsKeyPair } from "@app/hooks/api/types"; import { SecretType, UserWsKeyPair } from "@app/hooks/api/types";
import { PopUpNames, usePopUpAction, usePopUpState } from "../../SecretMainPage.store"; import { PopUpNames, usePopUpAction, usePopUpState } from "../../SecretMainPage.store";
@@ -56,7 +56,7 @@ export const CreateSecretForm = ({
secretName: key, secretName: key,
secretValue: value || "", secretValue: value || "",
secretComment: "", secretComment: "",
type: "shared", type: SecretType.Shared,
latestFileKey: decryptFileKey latestFileKey: decryptFileKey
}); });
closePopUp(PopUpNames.CreateSecretForm); closePopUp(PopUpNames.CreateSecretForm);
@@ -16,7 +16,7 @@ import { usePopUp, useToggle } from "@app/hooks";
import { useCreateSecretBatch, useUpdateSecretBatch } from "@app/hooks/api"; import { useCreateSecretBatch, useUpdateSecretBatch } from "@app/hooks/api";
import { secretApprovalRequestKeys } from "@app/hooks/api/secretApprovalRequest/queries"; import { secretApprovalRequestKeys } from "@app/hooks/api/secretApprovalRequest/queries";
import { secretKeys } from "@app/hooks/api/secrets/queries"; import { secretKeys } from "@app/hooks/api/secrets/queries";
import { DecryptedSecret, UserWsKeyPair } from "@app/hooks/api/types"; import { DecryptedSecret, SecretType, UserWsKeyPair } from "@app/hooks/api/types";
import { PopUpNames, usePopUpAction } from "../../SecretMainPage.store"; import { PopUpNames, usePopUpAction } from "../../SecretMainPage.store";
import { CopySecretsFromBoard } from "./CopySecretsFromBoard"; import { CopySecretsFromBoard } from "./CopySecretsFromBoard";
@@ -170,7 +170,7 @@ export const SecretDropzone = ({
workspaceId, workspaceId,
environment, environment,
secrets: Object.entries(create).map(([secretName, secData]) => ({ secrets: Object.entries(create).map(([secretName, secData]) => ({
type: "shared", type: SecretType.Shared,
secretComment: secData.comments.join("\n"), secretComment: secData.comments.join("\n"),
secretValue: secData.value, secretValue: secData.value,
secretName secretName
@@ -184,7 +184,7 @@ export const SecretDropzone = ({
workspaceId, workspaceId,
environment, environment,
secrets: Object.entries(update).map(([secretName, secData]) => ({ secrets: Object.entries(update).map(([secretName, secData]) => ({
type: "shared", type: SecretType.Shared,
secretComment: secData.comments.join("\n"), secretComment: secData.comments.join("\n"),
secretValue: secData.value, secretValue: secData.value,
secretName secretName
@@ -10,7 +10,7 @@ import { usePopUp } from "@app/hooks";
import { useCreateSecretV3, useDeleteSecretV3, useUpdateSecretV3 } from "@app/hooks/api"; import { useCreateSecretV3, useDeleteSecretV3, useUpdateSecretV3 } from "@app/hooks/api";
import { secretApprovalRequestKeys } from "@app/hooks/api/secretApprovalRequest/queries"; import { secretApprovalRequestKeys } from "@app/hooks/api/secretApprovalRequest/queries";
import { secretKeys } from "@app/hooks/api/secrets/queries"; import { secretKeys } from "@app/hooks/api/secrets/queries";
import { DecryptedSecret } from "@app/hooks/api/secrets/types"; import { DecryptedSecret, SecretType } from "@app/hooks/api/secrets/types";
import { secretSnapshotKeys } from "@app/hooks/api/secretSnapshots/queries"; import { secretSnapshotKeys } from "@app/hooks/api/secretSnapshots/queries";
import { UserWsKeyPair, WsTag } from "@app/hooks/api/types"; import { UserWsKeyPair, WsTag } from "@app/hooks/api/types";
@@ -119,7 +119,7 @@ export const SecretListView = ({
const handleSecretOperation = async ( const handleSecretOperation = async (
operation: "create" | "update" | "delete", operation: "create" | "update" | "delete",
type: "shared" | "personal", type: SecretType,
key: string, key: string,
{ {
value, value,
@@ -227,23 +227,25 @@ export const SecretListView = ({
try { try {
// personal secret change // personal secret change
if (overrideAction === "deleted") { if (overrideAction === "deleted") {
await handleSecretOperation("delete", "personal", oldKey, { await handleSecretOperation("delete", SecretType.Personal, oldKey, {
secretId: orgSecret.idOverride secretId: orgSecret.idOverride
}); });
} else if (overrideAction && idOverride) { } else if (overrideAction && idOverride) {
await handleSecretOperation("update", "personal", oldKey, { await handleSecretOperation("update", SecretType.Personal, oldKey, {
value: valueOverride, value: valueOverride,
newKey: hasKeyChanged ? key : undefined, newKey: hasKeyChanged ? key : undefined,
secretId: orgSecret.idOverride, secretId: orgSecret.idOverride,
skipMultilineEncoding: modSecret.skipMultilineEncoding skipMultilineEncoding: modSecret.skipMultilineEncoding
}); });
} else if (overrideAction) { } else if (overrideAction) {
await handleSecretOperation("create", "personal", oldKey, { value: valueOverride }); await handleSecretOperation("create", SecretType.Personal, oldKey, {
value: valueOverride
});
} }
// shared secret change // shared secret change
if (!isSharedSecUnchanged) { if (!isSharedSecUnchanged) {
await handleSecretOperation("update", "shared", oldKey, { await handleSecretOperation("update", SecretType.Shared, oldKey, {
value, value,
tags: tagIds, tags: tagIds,
comment, comment,
@@ -286,7 +288,7 @@ export const SecretListView = ({
const handleSecretDelete = useCallback(async () => { const handleSecretDelete = useCallback(async () => {
const { key, id: secretId } = popUp.deleteSecret?.data as DecryptedSecret; const { key, id: secretId } = popUp.deleteSecret?.data as DecryptedSecret;
try { try {
await handleSecretOperation("delete", "shared", key, { secretId }); await handleSecretOperation("delete", SecretType.Shared, key, { secretId });
// wrap this in another function and then reuse // wrap this in another function and then reuse
queryClient.invalidateQueries( queryClient.invalidateQueries(
secretKeys.getProjectSecret({ workspaceId, environment, secretPath }) secretKeys.getProjectSecret({ workspaceId, environment, secretPath })
@@ -64,7 +64,7 @@ import {
} from "@app/hooks/api"; } from "@app/hooks/api";
import { useUpdateFolderBatch } from "@app/hooks/api/secretFolders/queries"; import { useUpdateFolderBatch } from "@app/hooks/api/secretFolders/queries";
import { TUpdateFolderBatchDTO } from "@app/hooks/api/secretFolders/types"; import { TUpdateFolderBatchDTO } from "@app/hooks/api/secretFolders/types";
import { TSecretFolder } from "@app/hooks/api/types"; import { SecretType, TSecretFolder } from "@app/hooks/api/types";
import { ProjectVersion } from "@app/hooks/api/workspace/types"; import { ProjectVersion } from "@app/hooks/api/workspace/types";
import { FolderForm } from "../SecretMainPage/components/ActionBar/FolderForm"; import { FolderForm } from "../SecretMainPage/components/ActionBar/FolderForm";
@@ -188,7 +188,7 @@ export const SecretOverviewPage = () => {
environments: userAvailableEnvs.map(({ slug }) => slug) environments: userAvailableEnvs.map(({ slug }) => slug)
}); });
const { isImportedSecretPresentInEnv } = useGetImportedSecretsAllEnvs({ const { isImportedSecretPresentInEnv, getImportedSecretByKey } = useGetImportedSecretsAllEnvs({
projectId: workspaceId, projectId: workspaceId,
decryptFileKey: latestFileKey!, decryptFileKey: latestFileKey!,
path: secretPath, path: secretPath,
@@ -320,7 +320,7 @@ export const SecretOverviewPage = () => {
secretName: key, secretName: key,
secretValue: value, secretValue: value,
secretComment: "", secretComment: "",
type: "shared", type: SecretType.Shared,
latestFileKey: latestFileKey! latestFileKey: latestFileKey!
}); });
createNotification({ createNotification({
@@ -344,7 +344,13 @@ export const SecretOverviewPage = () => {
} }
}; };
const handleSecretUpdate = async (env: string, key: string, value: string, secretId?: string) => { const handleSecretUpdate = async (
env: string,
key: string,
value: string,
type = SecretType.Shared,
secretId?: string
) => {
try { try {
await updateSecretV3({ await updateSecretV3({
environment: env, environment: env,
@@ -353,7 +359,7 @@ export const SecretOverviewPage = () => {
secretId, secretId,
secretName: key, secretName: key,
secretValue: value, secretValue: value,
type: "shared", type,
latestFileKey: latestFileKey! latestFileKey: latestFileKey!
}); });
createNotification({ createNotification({
@@ -377,7 +383,7 @@ export const SecretOverviewPage = () => {
secretPath, secretPath,
secretName: key, secretName: key,
secretId, secretId,
type: "shared" type: SecretType.Shared
}); });
createNotification({ createNotification({
type: "success", type: "success",
@@ -807,6 +813,7 @@ export const SecretOverviewPage = () => {
isSelected={selectedEntries.secret[key]} isSelected={selectedEntries.secret[key]}
onToggleSecretSelect={() => toggleSelectedEntry(EntryType.SECRET, key)} onToggleSecretSelect={() => toggleSelectedEntry(EntryType.SECRET, key)}
secretPath={secretPath} secretPath={secretPath}
getImportedSecretByKey={getImportedSecretByKey}
isImportedSecretPresentInEnv={isImportedSecretPresentInEnv} isImportedSecretPresentInEnv={isImportedSecretPresentInEnv}
onSecretCreate={handleSecretCreate} onSecretCreate={handleSecretCreate}
onSecretDelete={handleSecretDelete} onSecretDelete={handleSecretDelete}
@@ -18,7 +18,7 @@ import {
import { InfisicalSecretInput } from "@app/components/v2/InfisicalSecretInput"; import { InfisicalSecretInput } from "@app/components/v2/InfisicalSecretInput";
import { useWorkspace } from "@app/context"; import { useWorkspace } from "@app/context";
import { useCreateFolder, useCreateSecretV3, useUpdateSecretV3 } from "@app/hooks/api"; import { useCreateFolder, useCreateSecretV3, useUpdateSecretV3 } from "@app/hooks/api";
import { DecryptedSecret, UserWsKeyPair } from "@app/hooks/api/types"; import { DecryptedSecret, SecretType, UserWsKeyPair } from "@app/hooks/api/types";
const typeSchema = z const typeSchema = z
.object({ .object({
@@ -103,7 +103,7 @@ export const CreateSecretForm = ({
secretPath, secretPath,
secretName: key, secretName: key,
secretValue: value || "", secretValue: value || "",
type: "shared", type: SecretType.Shared,
latestFileKey: decryptFileKey latestFileKey: decryptFileKey
}); });
} }
@@ -115,7 +115,7 @@ export const CreateSecretForm = ({
secretName: key, secretName: key,
secretValue: value || "", secretValue: value || "",
secretComment: "", secretComment: "",
type: "shared", type: SecretType.Shared,
latestFileKey: decryptFileKey latestFileKey: decryptFileKey
}); });
}); });
@@ -10,24 +10,33 @@ import { IconButton, Tooltip } from "@app/components/v2";
import { InfisicalSecretInput } from "@app/components/v2/InfisicalSecretInput"; import { InfisicalSecretInput } from "@app/components/v2/InfisicalSecretInput";
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/context"; import { ProjectPermissionActions, ProjectPermissionSub } from "@app/context";
import { useToggle } from "@app/hooks"; import { useToggle } from "@app/hooks";
import { SecretType } from "@app/hooks/api/types";
type Props = { type Props = {
defaultValue?: string | null; defaultValue?: string | null;
secretName: string; secretName: string;
secretId?: string; secretId?: string;
isOverride?: boolean;
isCreatable?: boolean; isCreatable?: boolean;
isVisible?: boolean; isVisible?: boolean;
isImportedSecret: boolean; isImportedSecret: boolean;
environment: string; environment: string;
secretPath: string; secretPath: string;
onSecretCreate: (env: string, key: string, value: string) => Promise<void>; onSecretCreate: (env: string, key: string, value: string) => Promise<void>;
onSecretUpdate: (env: string, key: string, value: string, secretId?: string) => Promise<void>; onSecretUpdate: (
env: string,
key: string,
value: string,
type?: SecretType,
secretId?: string
) => Promise<void>;
onSecretDelete: (env: string, key: string, secretId?: string) => Promise<void>; onSecretDelete: (env: string, key: string, secretId?: string) => Promise<void>;
}; };
export const SecretEditRow = ({ export const SecretEditRow = ({
defaultValue, defaultValue,
isCreatable, isCreatable,
isOverride,
isImportedSecret, isImportedSecret,
onSecretUpdate, onSecretUpdate,
secretName, secretName,
@@ -73,7 +82,13 @@ export const SecretEditRow = ({
if (isCreatable) { if (isCreatable) {
await onSecretCreate(environment, secretName, value); await onSecretCreate(environment, secretName, value);
} else { } else {
await onSecretUpdate(environment, secretName, value, secretId); await onSecretUpdate(
environment,
secretName,
value,
isOverride ? SecretType.Personal : SecretType.Shared,
secretId
);
} }
} }
reset({ value }); reset({ value });
@@ -93,12 +108,13 @@ export const SecretEditRow = ({
<div className="group flex w-full cursor-text items-center space-x-2"> <div className="group flex w-full cursor-text items-center space-x-2">
<div className="flex-grow border-r border-r-mineshaft-600 pr-2 pl-1"> <div className="flex-grow border-r border-r-mineshaft-600 pr-2 pl-1">
<Controller <Controller
disabled={isImportedSecret} disabled={isImportedSecret && !defaultValue}
control={control} control={control}
name="value" name="value"
render={({ field }) => ( render={({ field }) => (
<InfisicalSecretInput <InfisicalSecretInput
{...field} {...field}
isReadOnly={isImportedSecret}
value={field.value as string} value={field.value as string}
key="secret-input" key="secret-input"
isVisible={isVisible} isVisible={isVisible}
@@ -13,7 +13,8 @@ import { twMerge } from "tailwind-merge";
import { Button, Checkbox, TableContainer, Td, Tooltip, Tr } from "@app/components/v2"; import { Button, Checkbox, TableContainer, Td, Tooltip, Tr } from "@app/components/v2";
import { useToggle } from "@app/hooks"; import { useToggle } from "@app/hooks";
import { DecryptedSecret } from "@app/hooks/api/secrets/types"; import { DecryptedSecret, SecretType } from "@app/hooks/api/secrets/types";
import { WorkspaceEnv } from "@app/hooks/api/types";
import { SecretEditRow } from "./SecretEditRow"; import { SecretEditRow } from "./SecretEditRow";
import SecretRenameRow from "./SecretRenameRow"; import SecretRenameRow from "./SecretRenameRow";
@@ -27,9 +28,19 @@ type Props = {
onToggleSecretSelect: (key: string) => void; onToggleSecretSelect: (key: string) => void;
getSecretByKey: (slug: string, key: string) => DecryptedSecret | undefined; getSecretByKey: (slug: string, key: string) => DecryptedSecret | undefined;
onSecretCreate: (env: string, key: string, value: string) => Promise<void>; onSecretCreate: (env: string, key: string, value: string) => Promise<void>;
onSecretUpdate: (env: string, key: string, value: string, secretId?: string) => Promise<void>; onSecretUpdate: (
env: string,
key: string,
value: string,
type?: SecretType,
secretId?: string
) => Promise<void>;
onSecretDelete: (env: string, key: string, secretId?: string) => Promise<void>; onSecretDelete: (env: string, key: string, secretId?: string) => Promise<void>;
isImportedSecretPresentInEnv: (env: string, secretName: string) => boolean; isImportedSecretPresentInEnv: (env: string, secretName: string) => boolean;
getImportedSecretByKey: (
env: string,
secretName: string
) => { secret?: DecryptedSecret; environmentInfo?: WorkspaceEnv } | undefined;
}; };
export const SecretOverviewTableRow = ({ export const SecretOverviewTableRow = ({
@@ -41,6 +52,7 @@ export const SecretOverviewTableRow = ({
onSecretCreate, onSecretCreate,
onSecretDelete, onSecretDelete,
isImportedSecretPresentInEnv, isImportedSecretPresentInEnv,
getImportedSecretByKey,
expandableColWidth, expandableColWidth,
onToggleSecretSelect, onToggleSecretSelect,
isSelected isSelected
@@ -53,8 +65,9 @@ export const SecretOverviewTableRow = ({
<> <>
<Tr isHoverable isSelectable onClick={() => setIsFormExpanded.toggle()} className="group"> <Tr isHoverable isSelectable onClick={() => setIsFormExpanded.toggle()} className="group">
<Td <Td
className={`sticky left-0 z-10 bg-mineshaft-800 bg-clip-padding py-0 px-0 group-hover:bg-mineshaft-700 ${isFormExpanded && "border-t-2 border-mineshaft-500" className={`sticky left-0 z-10 bg-mineshaft-800 bg-clip-padding py-0 px-0 group-hover:bg-mineshaft-700 ${
}`} isFormExpanded && "border-t-2 border-mineshaft-500"
}`}
> >
<div className="h-full w-full border-r border-mineshaft-600 py-2.5 px-5"> <div className="h-full w-full border-r border-mineshaft-600 py-2.5 px-5">
<div className="flex items-center space-x-5"> <div className="flex items-center space-x-5">
@@ -107,8 +120,8 @@ export const SecretOverviewTableRow = ({
isSecretPresent isSecretPresent
? "Present secret" ? "Present secret"
: isSecretImported : isSecretImported
? "Imported secret" ? "Imported secret"
: "Missing secret" : "Missing secret"
} }
> >
<FontAwesomeIcon <FontAwesomeIcon
@@ -132,8 +145,9 @@ export const SecretOverviewTableRow = ({
<Tr> <Tr>
<Td <Td
colSpan={totalCols} colSpan={totalCols}
className={`bg-bunker-600 px-0 py-0 ${isFormExpanded && "border-b-2 border-mineshaft-500" className={`bg-bunker-600 px-0 py-0 ${
}`} isFormExpanded && "border-b-2 border-mineshaft-500"
}`}
> >
<div <div
className="ml-2 p-2" className="ml-2 p-2"
@@ -179,6 +193,7 @@ export const SecretOverviewTableRow = ({
const isCreatable = !secret; const isCreatable = !secret;
const isImportedSecret = isImportedSecretPresentInEnv(slug, secretKey); const isImportedSecret = isImportedSecretPresentInEnv(slug, secretKey);
const importedSecret = getImportedSecretByKey(slug, secretKey);
return ( return (
<tr <tr
@@ -189,8 +204,15 @@ export const SecretOverviewTableRow = ({
className="flex h-full items-center" className="flex h-full items-center"
style={{ padding: "0.25rem 1rem" }} style={{ padding: "0.25rem 1rem" }}
> >
<div title={name} className="flex h-8 w-[8rem] items-center "> <div title={name} className="flex h-8 w-[8rem] items-center space-x-2 ">
<span className="truncate">{name}</span> <span className="truncate">{name}</span>
{isImportedSecret && (
<Tooltip
content={`Imported secret from the '${importedSecret?.environmentInfo?.name}' environment`}
>
<FontAwesomeIcon icon={faFileImport} />
</Tooltip>
)}
</div> </div>
</td> </td>
<td className="col-span-2 h-8 w-full"> <td className="col-span-2 h-8 w-full">
@@ -198,8 +220,13 @@ export const SecretOverviewTableRow = ({
secretPath={secretPath} secretPath={secretPath}
isVisible={isSecretVisible} isVisible={isSecretVisible}
secretName={secretKey} secretName={secretKey}
defaultValue={secret?.value} defaultValue={
secret?.valueOverride ||
secret?.value ||
importedSecret?.secret?.value
}
secretId={secret?.id} secretId={secret?.id}
isOverride={Boolean(secret?.valueOverride)}
isImportedSecret={isImportedSecret} isImportedSecret={isImportedSecret}
isCreatable={isCreatable} isCreatable={isCreatable}
onSecretDelete={onSecretDelete} onSecretDelete={onSecretDelete}
@@ -18,7 +18,7 @@ import {
} from "@app/context"; } from "@app/context";
import { useToggle } from "@app/hooks"; import { useToggle } from "@app/hooks";
import { useGetUserWsKey, useUpdateSecretV3 } from "@app/hooks/api"; import { useGetUserWsKey, useUpdateSecretV3 } from "@app/hooks/api";
import { DecryptedSecret } from "@app/hooks/api/types"; import { DecryptedSecret, SecretType } from "@app/hooks/api/types";
import { SecretActionType } from "@app/views/SecretMainPage/components/SecretListView/SecretListView.utils"; import { SecretActionType } from "@app/views/SecretMainPage/components/SecretListView/SecretListView.utils";
type Props = { type Props = {
@@ -37,7 +37,6 @@ type TFormSchema = z.infer<typeof formSchema>;
function SecretRenameRow({ environments, getSecretByKey, secretKey, secretPath }: Props) { function SecretRenameRow({ environments, getSecretByKey, secretKey, secretPath }: Props) {
const { currentWorkspace } = useWorkspace(); const { currentWorkspace } = useWorkspace();
const { permission } = useProjectPermission(); const { permission } = useProjectPermission();
const secrets = environments.map((env) => getSecretByKey(env.slug, secretKey)); const secrets = environments.map((env) => getSecretByKey(env.slug, secretKey));
@@ -113,7 +112,7 @@ function SecretRenameRow({ environments, getSecretByKey, secretKey, secretPath }
secretName: secret.key, secretName: secret.key,
secretId: secret.id, secretId: secret.id,
secretValue: secret.value || "", secretValue: secret.value || "",
type: "shared", type: SecretType.Shared,
latestFileKey: decryptFileKey!, latestFileKey: decryptFileKey!,
tags: secret.tags.map((tag) => tag.id), tags: secret.tags.map((tag) => tag.id),
secretComment: secret.comment, secretComment: secret.comment,
@@ -13,7 +13,12 @@ import {
} from "@app/context"; } from "@app/context";
import { usePopUp } from "@app/hooks"; import { usePopUp } from "@app/hooks";
import { useDeleteFolder, useDeleteSecretBatch } from "@app/hooks/api"; import { useDeleteFolder, useDeleteSecretBatch } from "@app/hooks/api";
import { DecryptedSecret, TDeleteSecretBatchDTO, TSecretFolder } from "@app/hooks/api/types"; import {
DecryptedSecret,
SecretType,
TDeleteSecretBatchDTO,
TSecretFolder
} from "@app/hooks/api/types";
export enum EntryType { export enum EntryType {
FOLDER = "folder", FOLDER = "folder",
@@ -100,7 +105,7 @@ export const SelectionPanel = ({
...accum, ...accum,
{ {
secretName: entry.key, secretName: entry.key,
type: "shared" as "shared" type: SecretType.Shared
} }
]; ];
} }