mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-03 23:26:09 +00:00
Fix dummy signup project to support V2
This commit is contained in:
@@ -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 encryptSecrets from "@app/components/utilities/secrets/encryptSecrets";
|
||||||
import { uploadWsKey } from "@app/hooks/api/keys/queries";
|
|
||||||
import { createSecret } from "@app/hooks/api/secrets/mutations";
|
import { createSecret } from "@app/hooks/api/secrets/mutations";
|
||||||
import { fetchUserDetails } from "@app/hooks/api/users/queries";
|
|
||||||
import { createWorkspace } from "@app/hooks/api/workspace/queries";
|
import { createWorkspace } from "@app/hooks/api/workspace/queries";
|
||||||
|
|
||||||
const secretsToBeAdded = [
|
const secretsToBeAdded = [
|
||||||
@@ -91,43 +86,22 @@ const initProjectHelper = async ({
|
|||||||
}) => {
|
}) => {
|
||||||
// create new project
|
// create new project
|
||||||
const {
|
const {
|
||||||
data: { workspace }
|
data: { project }
|
||||||
} = await createWorkspace({
|
} = await createWorkspace({
|
||||||
workspaceName: projectName,
|
organizationId,
|
||||||
organizationId
|
projectName
|
||||||
});
|
|
||||||
|
|
||||||
// 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
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// encrypt and upload secrets to new project
|
// encrypt and upload secrets to new project
|
||||||
const secrets = await encryptSecrets({
|
const secrets = await encryptSecrets({
|
||||||
secretsToEncrypt: secretsToBeAdded,
|
secretsToEncrypt: secretsToBeAdded,
|
||||||
workspaceId: workspace.id,
|
workspaceId: project.id,
|
||||||
env: "dev"
|
env: "dev"
|
||||||
});
|
});
|
||||||
|
|
||||||
secrets?.forEach((secret) => {
|
secrets?.forEach((secret) => {
|
||||||
createSecret({
|
createSecret({
|
||||||
workspaceId: workspace.id,
|
workspaceId: project.id,
|
||||||
environment: secret.environment,
|
environment: secret.environment,
|
||||||
type: secret.type,
|
type: secret.type,
|
||||||
secretKey: secret.secretName,
|
secretKey: secret.secretName,
|
||||||
@@ -147,7 +121,7 @@ const initProjectHelper = async ({
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return workspace;
|
return project;
|
||||||
};
|
};
|
||||||
|
|
||||||
export { initProjectHelper };
|
export { initProjectHelper };
|
||||||
|
|||||||
Reference in New Issue
Block a user