Begin refactoring backfilling and preparation operations into setup and start adding encryption metadata to models

This commit is contained in:
Tuan Dang
2023-05-03 14:21:42 +03:00
parent b462ca3e89
commit 099cee7f39
37 changed files with 797 additions and 619 deletions
+13 -1
View File
@@ -1,4 +1,5 @@
import InfisicalClient from 'infisical-node';
import { validateEncryptionKey } from '../validation';
const client = new InfisicalClient({
token: process.env.INFISICAL_TOKEN!
@@ -6,7 +7,18 @@ const client = new InfisicalClient({
export const getPort = async () => (await client.getSecret('PORT')).secretValue || 4000;
export const getInviteOnlySignup = async () => (await client.getSecret('INVITE_ONLY_SIGNUP')).secretValue == undefined ? false : (await client.getSecret('INVITE_ONLY_SIGNUP')).secretValue;
export const getEncryptionKey = async () => (await client.getSecret('ENCRYPTION_KEY')).secretValue;
export const getEncryptionKey = async () => (await client.getSecret('ENCRYPTION_KEY')).secretValue; // TODO: deprecate in favor of INFISICAL_ENCRYPTION_KEY
export const getRootEncryptionKey = async (): Promise<string | undefined> => {
const encryptionKey = (await client.getSecret('ROOT_ENCRYPTION_KEY')).secretValue;
if (encryptionKey) {
// validate [encryptionKey] to make sure it is in base64 format and 256-bit
validateEncryptionKey(encryptionKey);
return encryptionKey;
}
return encryptionKey;
}
export const getSaltRounds = async () => parseInt((await client.getSecret('SALT_ROUNDS')).secretValue) || 10;
export const getJwtAuthLifetime = async () => (await client.getSecret('JWT_AUTH_LIFETIME')).secretValue || '10d';
export const getJwtAuthSecret = async () => (await client.getSecret('JWT_AUTH_SECRET')).secretValue;