From 486aa139c2e900027bc00cde81478e454449f9d1 Mon Sep 17 00:00:00 2001 From: Vladyslav Matsiiako Date: Mon, 9 Jan 2023 13:14:07 -0800 Subject: [PATCH] Changed frontend to use the new secrets routes --- .../src/controllers/v2/secretsController.ts | 8 +- backend/src/routes/v2/secrets.ts | 2 +- backend/src/services/PostHogClient.ts | 8 +- frontend/components/basic/Toggle.tsx | 2 +- .../components/dashboard/CommentField.tsx | 6 +- .../dashboard/DownloadSecretsMenu.tsx | 75 +++++++++ frontend/components/dashboard/SideBar.tsx | 2 +- .../{attemptLogin.js => attemptLogin.ts} | 61 ++++---- .../utilities/secrets/checkOverrides.ts | 33 ++++ .../utilities/secrets/downloadDotEnv.ts | 46 ++++++ .../utilities/secrets/downloadYaml.ts | 52 +++++++ .../utilities/secrets/encryptSecrets.ts | 116 ++++++++++++++ .../utilities/secrets/getSecretsForProject.ts | 113 ++++++++------ .../components/utilities/secrets/pushKeys.ts | 126 --------------- .../utilities/secrets/pushKeysIntegration.ts | 79 ---------- frontend/ee/api/secrets/GetActionData.ts | 1 - .../ee/api/secrets/PerformSecretRollback.ts | 30 ++++ frontend/ee/components/PITRecoverySidebar.tsx | 2 +- frontend/pages/api/files/AddSecrets.ts | 48 ++++++ frontend/pages/api/files/DeleteSecrets.ts | 27 ++++ frontend/pages/api/files/GetSecrets.ts | 10 +- frontend/pages/api/files/UpdateSecrets.ts | 44 ++++++ frontend/pages/dashboard/[id].tsx | 147 ++++++++---------- 23 files changed, 648 insertions(+), 390 deletions(-) create mode 100644 frontend/components/dashboard/DownloadSecretsMenu.tsx rename frontend/components/utilities/{attemptLogin.js => attemptLogin.ts} (68%) create mode 100644 frontend/components/utilities/secrets/checkOverrides.ts create mode 100644 frontend/components/utilities/secrets/downloadDotEnv.ts create mode 100644 frontend/components/utilities/secrets/downloadYaml.ts create mode 100644 frontend/components/utilities/secrets/encryptSecrets.ts delete mode 100644 frontend/components/utilities/secrets/pushKeys.ts delete mode 100644 frontend/components/utilities/secrets/pushKeysIntegration.ts create mode 100644 frontend/ee/api/secrets/PerformSecretRollback.ts create mode 100644 frontend/pages/api/files/AddSecrets.ts create mode 100644 frontend/pages/api/files/DeleteSecrets.ts create mode 100644 frontend/pages/api/files/UpdateSecrets.ts diff --git a/backend/src/controllers/v2/secretsController.ts b/backend/src/controllers/v2/secretsController.ts index 30748cb3f..69cacd75c 100644 --- a/backend/src/controllers/v2/secretsController.ts +++ b/backend/src/controllers/v2/secretsController.ts @@ -273,7 +273,7 @@ export const updateSecrets = async (req: Request, res: Response) => { }); await Secret.bulkWrite(ops); - let newSecretsObj: { [key: string]: PatchSecret } = {}; + const newSecretsObj: { [key: string]: PatchSecret } = {}; req.body.secrets.forEach((secret: PatchSecret) => { newSecretsObj[secret.id] = secret; }); @@ -323,7 +323,7 @@ export const updateSecrets = async (req: Request, res: Response) => { // group secrets into workspaces so updated secrets can // be logged and snapshotted separately for each workspace - let workspaceSecretObj: any = {}; + const workspaceSecretObj: any = {}; req.secrets.forEach((s: any) => { if (s.workspace.toString() in workspaceSecretObj) { workspaceSecretObj[s.workspace.toString()].push(s); @@ -399,7 +399,7 @@ export const deleteSecrets = async (req: Request, res: Response) => { // group secrets into workspaces so deleted secrets can // be logged and snapshotted separately for each workspace - let workspaceSecretObj: any = {}; + const workspaceSecretObj: any = {}; req.secrets.forEach((s: any) => { if (s.workspace.toString() in workspaceSecretObj) { workspaceSecretObj[s.workspace.toString()].push(s); @@ -445,7 +445,7 @@ export const deleteSecrets = async (req: Request, res: Response) => { } }); - return res.status(400).send({ + return res.status(200).send({ secrets: req.secrets }); } \ No newline at end of file diff --git a/backend/src/routes/v2/secrets.ts b/backend/src/routes/v2/secrets.ts index 73461d9cd..1f68d4420 100644 --- a/backend/src/routes/v2/secrets.ts +++ b/backend/src/routes/v2/secrets.ts @@ -138,7 +138,7 @@ router.patch( router.delete( '/', [ - check('secretIds') + body('secretIds') .exists() .custom((value) => { // case: delete 1 secret diff --git a/backend/src/services/PostHogClient.ts b/backend/src/services/PostHogClient.ts index 4ce0117f0..0d91a1c13 100644 --- a/backend/src/services/PostHogClient.ts +++ b/backend/src/services/PostHogClient.ts @@ -7,12 +7,12 @@ import { } from '../config'; import { getLogger } from '../utils/logger'; -if(TELEMETRY_ENABLED){ +if(!TELEMETRY_ENABLED){ getLogger("backend-main").info([ "", - "Infisical collects telemetry data about general usage.", - "The data helps us understand how the product is doing and guide our product development to create the best possible platform; it also helps us demonstrate growth for investors as we support Infisical as open-source software.", - "To opt out of telemetry, you can set `TELEMETRY_ENABLED=false` within the environment variables", + "To improve, Infisical collects telemetry data about general usage.", + "This helps us understand how the product is doing and guide our product development to create the best possible platform; it also helps us demonstrate growth as we support Infisical as open-source software.", + "To opt into telemetry, you can set `TELEMETRY_ENABLED=true` within the environment variables.", ].join('\n')) } diff --git a/frontend/components/basic/Toggle.tsx b/frontend/components/basic/Toggle.tsx index d15aed622..c9957cc3c 100644 --- a/frontend/components/basic/Toggle.tsx +++ b/frontend/components/basic/Toggle.tsx @@ -34,7 +34,7 @@ interface ToggleProps { * @param {string} obj.value - value of a certain secret * @param {number} obj.pos - position of a certain secret #TODO: make the secret id persistent? - * @param {string} obj.id - id of a certain secret + * @param {string} obj.id - id of a certain secret (NOTE: THIS IS THE ID OF THE MAIN SECRET - NOT OF AN OVERRIDE) * @param {function} obj.deleteOverride - a function that deleted an override for a certain secret * @param {string[]} obj.sharedToHide - an array of shared secrets that we want to hide visually because they are overriden. * @param {function} obj.setSharedToHide - a function that updates the array of secrets that we want to hide visually diff --git a/frontend/components/dashboard/CommentField.tsx b/frontend/components/dashboard/CommentField.tsx index ea29aa73c..62ff0c2f1 100644 --- a/frontend/components/dashboard/CommentField.tsx +++ b/frontend/components/dashboard/CommentField.tsx @@ -6,10 +6,10 @@ import { useTranslation } from "next-i18next"; const CommentField = ({ comment, modifyComment, position }: { comment: string; modifyComment: (value: string, posistion: number) => void; position: number;}) => { const { t } = useTranslation(); - return
-

{t("dashboard:sidebar.comments")}

+ return
+

{t("dashboard:sidebar.comments")}