2019-10-29 16:12:58 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
exports = module.exports = {
|
2019-10-29 20:08:45 -07:00
|
|
|
getServerIp,
|
|
|
|
|
testConfig
|
2019-10-29 16:12:58 -07:00
|
|
|
};
|
|
|
|
|
|
2021-08-27 09:52:24 -07:00
|
|
|
const assert = require('assert'),
|
2019-10-29 20:08:45 -07:00
|
|
|
BoxError = require('../boxerror.js'),
|
|
|
|
|
validator = require('validator');
|
2019-10-29 16:12:58 -07:00
|
|
|
|
2021-08-27 09:52:24 -07:00
|
|
|
async function getServerIp(config) {
|
2019-10-29 16:12:58 -07:00
|
|
|
assert.strictEqual(typeof config, 'object');
|
|
|
|
|
|
2021-08-27 09:52:24 -07:00
|
|
|
return config.ip;
|
2019-10-29 16:12:58 -07:00
|
|
|
}
|
|
|
|
|
|
2021-08-27 09:52:24 -07:00
|
|
|
async function testConfig(config) {
|
2019-10-29 20:08:45 -07:00
|
|
|
assert.strictEqual(typeof config, 'object');
|
|
|
|
|
|
2021-08-27 09:52:24 -07:00
|
|
|
if (typeof config.ip !== 'string') return new BoxError(BoxError.BAD_FIELD, 'ip must be a string');
|
|
|
|
|
if (!validator.isIP(config.ip, 4)) return new BoxError(BoxError.BAD_FIELD, 'ip is not a valid ipv4');
|
2019-10-29 20:08:45 -07:00
|
|
|
|
2021-08-27 09:52:24 -07:00
|
|
|
return null;
|
2019-10-29 20:08:45 -07:00
|
|
|
}
|