Fix dummy signup project to support V2

This commit is contained in:
Daniel Hougaard
2024-02-13 20:18:36 +01:00
parent 6090f86b74
commit bb92cef764

View File

@@ -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 };