Fix: Added explicit SecretType type

This commit is contained in:
Daniel Hougaard
2024-06-21 15:23:50 +02:00
parent 9c06cab99d
commit d0f8394f50
9 changed files with 41 additions and 29 deletions
@@ -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);
@@ -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";
@@ -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",
@@ -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
}); });
}); });
@@ -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 = {
@@ -38,7 +38,6 @@ function SecretRenameRow({ environments, getSecretByKey, secretKey, secretPath }
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));
const isReadOnly = environments.some((env) => { const isReadOnly = environments.some((env) => {
@@ -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
} }
]; ];
} }