Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var bootstrapUri = agentConfig['edge_config']['bootstrap'];
if (bootstrapUri) {
if (!agentConfig.hasOwnProperty('analytics') || agentConfig['analytics'] === null) {
agentConfig['analytics'] = {};
}
agentConfig['analytics']['uri'] = bootstrapUri.replace('bootstrap', 'axpublisher');
agentConfig['analytics']['bufferSize'] = BUFFERSIZE;
agentConfig['analytics']['batchSize'] = BATCHSIZE;
agentConfig['analytics']['flushInterval'] = FLUSHINTERVAL;
}
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP});
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP}, 'saving configuration information to:', agentConfigPath);
edgeconfig.save(agentConfig, agentConfigPath); // if it didn't throw, save succeeded
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP});
if (options.deployed === true) {
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP}, 'vault info:\n', results[0]);
} else {
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP}, 'vault info:\n', results[1]);
}
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP});
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP},keySecretMessage);
const key = results[2] ? results[2].key : results[1].key;
const secret = results[2] ? results[2].secret : results[1].secret;
assert(key, 'must have a key');
assert(secret, 'must have a secret');
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP}, ' key:', key);
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP}, ' secret:', secret);
edgeconfig.get({ source: sourcePath, keys: keys }, function (err, config) {
edgeconfig.save(config, cachePath);
agentLib({ keys: keys, target: cachePath }, (err, agent, config) => {
if (err) {
return printError(err);
}
downloadedConfig = config;
async.series(tasks, function ( /*asyncErr, res */ ) {
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP},'verification complete');
agent.close(process.exit); // close and stop agent
});
})
});
edgeconfig.get(opts, (err, newConfig) => {
if(validator(newConfig) === false && !err) {
err = {};
}
if (err) {
// failed to check new config. so try to check again after pollInterval
writeConsoleLog('error',{component: CONSOLE_LOG_TAG_COMP},'Failed to check for change in Config. Will retry after ' + pollInterval + ' seconds');
setTimeout(() => {
reloadOnConfigChange(oldConfig, cache, opts);
}, pollInterval * 1000);
} else {
pollInterval = config.edgemicro.config_change_poll_interval ? config.edgemicro.config_change_poll_interval : pollInterval;
var isConfigChanged = hasConfigChanged(oldConfig, newConfig);
if (isConfigChanged) {
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP},'Configuration change detected. Saving new config and Initiating reload');
edgeconfig.save(newConfig, cache);
clientSocket.sendMessage({
command: 'reload'
});
}
setTimeout(() => {
reloadOnConfigChange(newConfig, cache, opts);
}, pollInterval * 1000);
}
});
};
}, (err, config) => {
if (err) {
const exists = fs.existsSync(cache);
writeConsoleLog('error',{component: CONSOLE_LOG_TAG_COMP},"failed to retieve config from gateway. continuing, will try cached copy..");
writeConsoleLog('error',{component: CONSOLE_LOG_TAG_COMP},err);
if (!exists) {
writeConsoleLog('error',{component: CONSOLE_LOG_TAG_COMP},'cache configuration ' + cache + ' does not exist. exiting.');
return;
} else {
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP},'using cached configuration from %s', cache);
config = edgeconfig.load({
source: cache
})
}
} else {
edgeconfig.save(config, cache);
}
socket.sendMessage({
command: 'reload'
});
socket.on('message', (success) => {
if (typeof success === 'object' && success.message) {
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP}, success.message);
}
else if (success) {
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP},'Reload Completed Successfully');
} else {
writeConsoleLog('error',{component: CONSOLE_LOG_TAG_COMP},'Reloading edgemicro was unsuccessful');
}
process.exit(0);
});
}, function( /*err, configPath */ ) {
edgeconfig.save(that.config, that.sourcePath);
options.deployed = false;
options.internaldeployed = false;
that.deployment.checkDeployedProxies(options, (err, options) => {
if (err) {
writeConsoleLog('error',{component: CONSOLE_LOG_TAG_COMP},err);
if ( cb ) { cb(err) } else process.exit(1);
return;
} else {
that.deployment.checkDeployedInternalProxies(options, (err, options) => {
if (err) {
writeConsoleLog('error',{component: CONSOLE_LOG_TAG_COMP},err);
if ( cb ) { cb(err) } else process.exit(1);
return;
} else {
that.configureEdgemicroWithCreds(options, (err) => {
if (err) {
var bootstrapUri = agentConfig['edge_config']['bootstrap'];
if (bootstrapUri) {
if (!agentConfig.hasOwnProperty('analytics') || agentConfig['analytics'] === null) {
agentConfig['analytics'] = {};
}
agentConfig['analytics']['uri'] = bootstrapUri.replace('bootstrap', 'axpublisher');
agentConfig['analytics']['bufferSize'] = 100;
agentConfig['analytics']['batchSize'] = 50;
agentConfig['analytics']['flushInterval'] = 500;
}
writeConsoleLog('log')
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP},'saving configuration information to:', agentConfigPath);
edgeconfig.save(agentConfig, agentConfigPath);
writeConsoleLog('log')
if (options.internaldeployed === false && options.deployed === false) {
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP},'vault info:\n', results[3]);
} else if (options.internaldeployed === true && options.internaldeployed === false) {
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP},'vault info:\n', results[1]);
}
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP},'edgemicro configuration complete!');
cb();
});
};
writeConsoleLog('error',{component: CONSOLE_LOG_TAG_COMP},'cache configuration ' + cache + ' does not exist. exiting.');
return;
} else {
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP},'using cached configuration from %s', cache);
config = edgeconfig.load({
source: cache
});
if (options.port) {
config.edgemicro.port = parseInt(options.port);
}
}
} else {
if (options.port) {
config.edgemicro.port = parseInt(options.port);
}
edgeconfig.save(config, cache);
}
config.uid = uuid();
initializeMicroGatewayLogging(config,options);
var opt = {};
delete args.keys;
//set pluginDir
if (!args.pluginDir) {
if (config.edgemicro.plugins.dir) {
args.pluginDir = path.resolve(config.edgemicro.plugins.dir);
}
}
opt.args = [JSON.stringify(args)];
opt.timeout = 10;
opt.logger = gateway.Logging.getLogger();