feat: env file sync with infra config (#4545)
This commit is contained in:
@@ -29,6 +29,7 @@ import {
|
||||
getEncryptionRequiredInfraConfigEntries,
|
||||
getMissingInfraConfigEntries,
|
||||
stopApp,
|
||||
syncInfraConfigWithEnvFile,
|
||||
} from './helper';
|
||||
import { EnableAndDisableSSOArgs, InfraConfigArgs } from './input-args';
|
||||
import { AuthProvider } from 'src/auth/helper';
|
||||
@@ -65,8 +66,11 @@ export class InfraConfigService implements OnModuleInit {
|
||||
*/
|
||||
async initializeInfraConfigTable() {
|
||||
try {
|
||||
const defaultInfraConfigs = await getDefaultInfraConfigs();
|
||||
|
||||
// Adding missing InfraConfigs to the database (with encrypted values)
|
||||
const propsToInsert = await getMissingInfraConfigEntries();
|
||||
const propsToInsert =
|
||||
await getMissingInfraConfigEntries(defaultInfraConfigs);
|
||||
|
||||
if (propsToInsert.length > 0) {
|
||||
await this.prisma.infraConfig.createMany({ data: propsToInsert });
|
||||
@@ -74,7 +78,7 @@ export class InfraConfigService implements OnModuleInit {
|
||||
|
||||
// Encrypting previous InfraConfigs that are required to be encrypted
|
||||
const encryptionRequiredEntries =
|
||||
await getEncryptionRequiredInfraConfigEntries();
|
||||
await getEncryptionRequiredInfraConfigEntries(defaultInfraConfigs);
|
||||
|
||||
if (encryptionRequiredEntries.length > 0) {
|
||||
const dbOperations = encryptionRequiredEntries.map((dbConfig) => {
|
||||
@@ -87,8 +91,25 @@ export class InfraConfigService implements OnModuleInit {
|
||||
await Promise.allSettled(dbOperations);
|
||||
}
|
||||
|
||||
// Sync the InfraConfigs with the .env file, if .env file updates later on
|
||||
const envFileChangesRequired = await syncInfraConfigWithEnvFile();
|
||||
if (envFileChangesRequired.length > 0) {
|
||||
const dbOperations = envFileChangesRequired.map((dbConfig) => {
|
||||
const { id, ...dataObj } = dbConfig;
|
||||
return this.prisma.infraConfig.update({
|
||||
where: { id: dbConfig.id },
|
||||
data: dataObj,
|
||||
});
|
||||
});
|
||||
await Promise.allSettled(dbOperations);
|
||||
}
|
||||
|
||||
// Restart the app if needed
|
||||
if (propsToInsert.length > 0 || encryptionRequiredEntries.length > 0) {
|
||||
if (
|
||||
propsToInsert.length > 0 ||
|
||||
encryptionRequiredEntries.length > 0 ||
|
||||
envFileChangesRequired.length > 0
|
||||
) {
|
||||
stopApp();
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user