Add route to set/get sysinfo
This commit is contained in:
@@ -279,6 +279,26 @@ function setRegistryConfig(req, res, next) {
|
||||
});
|
||||
}
|
||||
|
||||
function getSysinfoConfig(req, res, next) {
|
||||
settings.getSysinfConfig(function (error, sysinfoConfig) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, sysinfoConfig));
|
||||
});
|
||||
}
|
||||
|
||||
function setSysinfoConfig(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
if (!req.body.provider || typeof req.body.provider !== 'string') return next(new HttpError(400, 'provider is required'));
|
||||
|
||||
settings.setSysinfoConfig(req.body, function (error) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, {}));
|
||||
});
|
||||
}
|
||||
|
||||
function get(req, res, next) {
|
||||
assert.strictEqual(typeof req.params.setting, 'string');
|
||||
|
||||
@@ -289,6 +309,7 @@ function get(req, res, next) {
|
||||
case settings.EXTERNAL_LDAP_KEY: return getExternalLdapConfig(req, res, next);
|
||||
case settings.UNSTABLE_APPS_KEY: return getUnstableAppsConfig(req, res, next);
|
||||
case settings.REGISTRY_CONFIG_KEY: return getRegistryConfig(req, res, next);
|
||||
case settings.SYSINFO_CONFIG_KEY: return getSysinfoConfig(req, res, next);
|
||||
|
||||
case settings.APP_AUTOUPDATE_PATTERN_KEY: return getAppAutoupdatePattern(req, res, next);
|
||||
case settings.BOX_AUTOUPDATE_PATTERN_KEY: return getBoxAutoupdatePattern(req, res, next);
|
||||
@@ -311,6 +332,7 @@ function set(req, res, next) {
|
||||
case settings.EXTERNAL_LDAP_KEY: return setExternalLdapConfig(req, res, next);
|
||||
case settings.UNSTABLE_APPS_KEY: return setUnstableAppsConfig(req, res, next);
|
||||
case settings.REGISTRY_CONFIG_KEY: return setRegistryConfig(req, res, next);
|
||||
case settings.SYSINFO_CONFIG_KEY: return setSysinfoConfig(req, res, next);
|
||||
|
||||
case settings.APP_AUTOUPDATE_PATTERN_KEY: return setAppAutoupdatePattern(req, res, next);
|
||||
case settings.BOX_AUTOUPDATE_PATTERN_KEY: return setBoxAutoupdatePattern(req, res, next);
|
||||
|
||||
+8
-3
@@ -112,6 +112,7 @@ var addons = require('./addons.js'),
|
||||
paths = require('./paths.js'),
|
||||
safe = require('safetydance'),
|
||||
settingsdb = require('./settingsdb.js'),
|
||||
sysinfo = require('./sysinfo.js'),
|
||||
util = require('util'),
|
||||
_ = require('underscore');
|
||||
|
||||
@@ -491,12 +492,16 @@ function setSysinfoConfig(sysinfoConfig, callback) {
|
||||
assert.strictEqual(typeof sysinfoConfig, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
settingsdb.set(exports.SYSINFO_CONFIG_KEY, JSON.stringify(sysinfoConfig), function (error) {
|
||||
sysinfo.testConfig(sysinfoConfig, function (error) {
|
||||
if (error) return callback(error);
|
||||
|
||||
notifyChange(exports.REGISTRY_CONFIG_KEY, sysinfoConfig);
|
||||
settingsdb.set(exports.SYSINFO_CONFIG_KEY, JSON.stringify(sysinfoConfig), function (error) {
|
||||
if (error) return callback(error);
|
||||
|
||||
callback(null);
|
||||
notifyChange(exports.SYSINFO_CONFIG_KEY, sysinfoConfig);
|
||||
|
||||
callback(null);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
exports = module.exports = {
|
||||
getServerIp: getServerIp,
|
||||
testConfig: testConfig,
|
||||
|
||||
hasIPv6: hasIPv6
|
||||
};
|
||||
@@ -41,3 +42,10 @@ function hasIPv6() {
|
||||
// on contabo, /proc/net/if_inet6 is an empty file. so just exists is not enough
|
||||
return fs.existsSync(IPV6_PROC_FILE) && fs.readFileSync(IPV6_PROC_FILE, 'utf8').trim().length !== 0;
|
||||
}
|
||||
|
||||
function testConfig(config, callback) {
|
||||
assert.strictEqual(typeof config, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
api(config.provider).testConfig(config, callback);
|
||||
}
|
||||
|
||||
+9
-1
@@ -1,7 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
exports = module.exports = {
|
||||
getServerIp: getServerIp
|
||||
getServerIp: getServerIp,
|
||||
testConfig: testConfig
|
||||
};
|
||||
|
||||
var assert = require('assert'),
|
||||
@@ -20,3 +21,10 @@ function getServerIp(config, callback) {
|
||||
callback(null, result.text);
|
||||
});
|
||||
}
|
||||
|
||||
function testConfig(config, callback) {
|
||||
assert.strictEqual(typeof config, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
callback(null);
|
||||
}
|
||||
|
||||
+14
-2
@@ -1,10 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
exports = module.exports = {
|
||||
getServerIp: getServerIp
|
||||
getServerIp,
|
||||
testConfig
|
||||
};
|
||||
|
||||
var assert = require('assert');
|
||||
var assert = require('assert'),
|
||||
BoxError = require('../boxerror.js'),
|
||||
validator = require('validator');
|
||||
|
||||
function getServerIp(config, callback) {
|
||||
assert.strictEqual(typeof config, 'object');
|
||||
@@ -13,3 +16,12 @@ function getServerIp(config, callback) {
|
||||
callback(null, config.ip);
|
||||
}
|
||||
|
||||
function testConfig(config, callback) {
|
||||
assert.strictEqual(typeof config, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
if (typeof config.ip !== 'string') return callback(new BoxError(BoxError.BAD_FIELD, 'ip must be a string'));
|
||||
if (!validator.isIP(config.ip, 4)) return callback(new BoxError(BoxError.BAD_FIELD, 'ip is not a valid ipv4'));
|
||||
|
||||
callback(null);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
exports = module.exports = {
|
||||
getServerIp: getServerIp
|
||||
getServerIp,
|
||||
testConfig
|
||||
};
|
||||
|
||||
var assert = require('assert'),
|
||||
@@ -34,3 +35,10 @@ function getServerIp(config, callback) {
|
||||
callback(null, result);
|
||||
});
|
||||
}
|
||||
|
||||
function testConfig(config, callback) {
|
||||
assert.strictEqual(typeof config, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
callback(null);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
// -------------------------------------------
|
||||
|
||||
exports = module.exports = {
|
||||
getServerIp: getServerIp
|
||||
getServerIp,
|
||||
testConfig
|
||||
};
|
||||
|
||||
var assert = require('assert');
|
||||
@@ -19,3 +20,9 @@ function getServerIp(config, callback) {
|
||||
callback(new Error('not implemented'));
|
||||
}
|
||||
|
||||
function testConfig(config, callback) {
|
||||
assert.strictEqual(typeof config, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
callback(null);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
exports = module.exports = {
|
||||
getServerIp: getServerIp
|
||||
getServerIp,
|
||||
testConfig
|
||||
};
|
||||
|
||||
var assert = require('assert'),
|
||||
@@ -23,3 +24,12 @@ function getServerIp(config, callback) {
|
||||
|
||||
return callback(null, addresses[0]);
|
||||
}
|
||||
|
||||
function testConfig(config, callback) {
|
||||
assert.strictEqual(typeof config, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
if (typeof config.ifname !== 'string') return callback(new BoxError(BoxError.BAD_FIELD, 'ifname is not a string'));
|
||||
|
||||
callback(null);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
exports = module.exports = {
|
||||
getServerIp: getServerIp
|
||||
getServerIp,
|
||||
testConfig
|
||||
};
|
||||
|
||||
var assert = require('assert'),
|
||||
@@ -24,3 +25,9 @@ function getServerIp(config, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function testConfig(config, callback) {
|
||||
assert.strictEqual(typeof config, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
callback(null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user