From bb92cef764fcd405d48a8f88d9599794e970691d Mon Sep 17 00:00:00 2001 From: Daniel Hougaard <62331820+DanielHougaard@users.noreply.github.com> Date: Tue, 13 Feb 2024 20:18:36 +0100 Subject: [PATCH] Fix dummy signup project to support V2 --- frontend/src/helpers/project.ts | 38 ++++++--------------------------- 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/frontend/src/helpers/project.ts b/frontend/src/helpers/project.ts index 21f73e4c63..06f13dc656 100644 --- a/frontend/src/helpers/project.ts +++ b/frontend/src/helpers/project.ts @@ -1,10 +1,5 @@ -import crypto from "crypto"; - -import { encryptAssymmetric } from "@app/components/utilities/cryptography/crypto"; import encryptSecrets from "@app/components/utilities/secrets/encryptSecrets"; -import { uploadWsKey } from "@app/hooks/api/keys/queries"; import { createSecret } from "@app/hooks/api/secrets/mutations"; -import { fetchUserDetails } from "@app/hooks/api/users/queries"; import { createWorkspace } from "@app/hooks/api/workspace/queries"; const secretsToBeAdded = [ @@ -91,43 +86,22 @@ const initProjectHelper = async ({ }) => { // create new project const { - data: { workspace } + data: { project } } = await createWorkspace({ - workspaceName: projectName, - organizationId - }); - - // create and upload new (encrypted) project key - const randomBytes = crypto.randomBytes(16).toString("hex"); - const PRIVATE_KEY = localStorage.getItem("PRIVATE_KEY"); - - if (!PRIVATE_KEY) throw new Error("Failed to find private key"); - - const user = await fetchUserDetails(); - - const { ciphertext, nonce } = encryptAssymmetric({ - plaintext: randomBytes, - publicKey: user.publicKey, - privateKey: PRIVATE_KEY - }); - - await uploadWsKey({ - workspaceId: workspace.id, - userId: user.id, - encryptedKey: ciphertext, - nonce + organizationId, + projectName }); // encrypt and upload secrets to new project const secrets = await encryptSecrets({ secretsToEncrypt: secretsToBeAdded, - workspaceId: workspace.id, + workspaceId: project.id, env: "dev" }); secrets?.forEach((secret) => { createSecret({ - workspaceId: workspace.id, + workspaceId: project.id, environment: secret.environment, type: secret.type, secretKey: secret.secretName, @@ -147,7 +121,7 @@ const initProjectHelper = async ({ }); }); - return workspace; + return project; }; export { initProjectHelper };