add settings.setTlsConfig

This commit is contained in:
Girish Ramakrishnan
2015-12-11 22:32:34 -08:00
parent e0a56f75c3
commit 9d91340223
4 changed files with 39 additions and 2 deletions

View File

@@ -27,6 +27,7 @@ exports = module.exports = {
setBackupConfig: setBackupConfig,
getTlsConfig: getTlsConfig,
setTlsConfig: setTlsConfig,
getDefaultSync: getDefaultSync,
getAll: getAll,
@@ -60,7 +61,7 @@ var gDefaults = (function () {
result[exports.DEVELOPER_MODE_KEY] = false;
result[exports.DNS_CONFIG_KEY] = { };
result[exports.BACKUP_CONFIG_KEY] = { };
result[exports.TLS_CONFIG_KEY] = { };
result[exports.TLS_CONFIG_KEY] = { provider: 'caas' };
return result;
})();
@@ -277,6 +278,23 @@ function getTlsConfig(callback) {
});
}
function setTlsConfig(tlsConfig, callback) {
assert.strictEqual(typeof tlsConfig, 'object');
assert.strictEqual(typeof callback, 'function');
if (tlsConfig.provider !== 'caas' && tlsConfig.provider.indexOf('le-') !== 0) {
return callback(new SettingsError(SettingsError.BAD_FIELD, 'provider must be caas or le-*'));
}
settingsdb.set(exports.TLS_CONFIG_KEY, JSON.stringify(tlsConfig), function (error) {
if (error) return callback(new SettingsError(SettingsError.INTERNAL_ERROR, error));
exports.events.emit(exports.TLS_CONFIG_KEY, tlsConfig);
callback(null);
});
}
function getBackupConfig(callback) {
assert.strictEqual(typeof callback, 'function');