fix: SDA-2421: copy config on startup (#1082)

* SDA-2421: copy config on startup

- Copy the global config admin values on startup over to user config

* SDA-2421: address PR comments
This commit is contained in:
Vishwas Shashidhar 2020-10-01 11:29:49 +05:30 committed by GitHub
parent 301c1af23a
commit 25fca2011a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 2 deletions

View File

@ -148,6 +148,7 @@ class Config {
this.userConfig = {};
this.cloudConfig = {};
this.filteredCloudConfig = {};
this.readUserConfig();
this.readGlobalConfig();
this.readInstallVariant();
@ -223,7 +224,7 @@ class Config {
logger.info(`config-handler: updating user config values with the data`, JSON.stringify(data));
this.userConfig = { ...this.userConfig, ...data };
try {
await writeFile(this.userConfigPath, JSON.stringify(this.userConfig), { encoding: 'utf8' });
await writeFile(this.userConfigPath, JSON.stringify(this.userConfig, null, 2), { encoding: 'utf8' });
logger.info(`config-handler: updated user config values with the data ${JSON.stringify(data)}`);
} catch (error) {
logger.error(`config-handler: failed to update user config file with ${JSON.stringify(data)}`, error);
@ -243,7 +244,7 @@ class Config {
this.filterCloudConfig();
logger.info(`config-handler: prioritized and filtered cloud config: `, this.filteredCloudConfig);
try {
await writeFile(this.cloudConfigPath, JSON.stringify(this.cloudConfig), { encoding: 'utf8' });
await writeFile(this.cloudConfigPath, JSON.stringify(this.cloudConfig, null, 2), { encoding: 'utf8' });
logger.info(`config-handler: writing cloud config values to file`);
} catch (error) {
logger.error(`config-handler: failed to update cloud config file with ${data}`, error);
@ -283,6 +284,27 @@ class Config {
await this.updateUserConfig({ buildNumber, installVariant: this.installVariant });
}
/**
* Updates user config on start by fetching new settings from the global config
* @private
*/
public async updateUserConfigOnStart() {
logger.info(`config-handler: updating user config with the latest global config values`);
const latestGlobalConfig = this.globalConfig as IConfig;
// The properties set below are typically controlled by IT admins, so, we copy
// all the values from global config to the user config on SDA relaunch
await this.updateUserConfig({
whitelistUrl: latestGlobalConfig.whitelistUrl,
memoryThreshold: latestGlobalConfig.memoryThreshold,
devToolsEnabled: latestGlobalConfig.devToolsEnabled,
ctWhitelist: latestGlobalConfig.ctWhitelist,
podWhitelist: latestGlobalConfig.podWhitelist,
permissions: latestGlobalConfig.permissions,
autoLaunchPath: latestGlobalConfig.autoLaunchPath,
customFlags: latestGlobalConfig.customFlags,
});
}
/**
* filters out the cloud config
*/
@ -342,6 +364,9 @@ class Config {
* Reads a stores the global config file
*/
private readGlobalConfig() {
if (!fs.existsSync(this.globalConfigPath)) {
throw new Error(`Global config file missing! App will not run as expected!`);
}
this.globalConfig = this.parseConfigData(fs.readFileSync(this.globalConfigPath, 'utf8'));
logger.info(`config-handler: Global configuration: `, this.globalConfig);
}

View File

@ -86,6 +86,8 @@ const startApplication = async () => {
await autoLaunchInstance.handleAutoLaunch();
}
}
// Picks global config values and updates them in the user config
await config.updateUserConfigOnStart();
// Setup session properties only after app ready
setSessionProperties();
await windowHandler.createApplication();