settings: move directory server config to it's own route

This commit is contained in:
Girish Ramakrishnan
2023-08-03 02:26:11 +05:30
parent 4a34c390f8
commit 67e4c90d37
11 changed files with 222 additions and 154 deletions
-34
View File
@@ -19,9 +19,6 @@ exports = module.exports = {
getServicesConfig,
setServicesConfig,
getDirectoryServerConfig,
setDirectoryServerConfig,
getRegistryConfig,
setRegistryConfig,
@@ -121,7 +118,6 @@ const assert = require('assert'),
CronJob = require('cron').CronJob,
database = require('./database.js'),
debug = require('debug')('box:settings'),
directoryServer = require('./directoryserver.js'),
docker = require('./docker.js'),
moment = require('moment-timezone'),
mounts = require('./mounts.js'),
@@ -156,11 +152,6 @@ const gDefaults = (function () {
schedule: '00 00 23 * * *' // every day at 11pm
};
result[exports.SERVICES_CONFIG_KEY] = {};
result[exports.DIRECTORY_SERVER_KEY] = {
enabled: false,
secret: '',
allowlist: '' // empty means allow all
};
result[exports.REGISTRY_CONFIG_KEY] = {
provider: 'noop'
};
@@ -368,31 +359,6 @@ async function setServicesConfig(platformConfig) {
notifyChange(exports.SERVICES_CONFIG_KEY, platformConfig);
}
async function getDirectoryServerConfig() {
const value = await get(exports.DIRECTORY_SERVER_KEY);
if (value === null) return gDefaults[exports.DIRECTORY_SERVER_KEY];
return JSON.parse(value);
}
async function setDirectoryServerConfig(directoryServerConfig) {
assert.strictEqual(typeof directoryServerConfig, 'object');
if (isDemo()) throw new BoxError(BoxError.BAD_FIELD, 'Not allowed in demo mode');
const config = {
enabled: directoryServerConfig.enabled,
secret: directoryServerConfig.secret,
// if list is empty, we allow all IPs
allowlist: directoryServerConfig.allowlist || ''
};
await directoryServer.validateConfig(config);
await set(exports.DIRECTORY_SERVER_KEY, JSON.stringify(config));
await directoryServer.applyConfig(config);
notifyChange(exports.DIRECTORY_SERVER_KEY, config);
}
async function getRegistryConfig() {
const value = await get(exports.REGISTRY_CONFIG_KEY);
if (value === null) return gDefaults[exports.REGISTRY_CONFIG_KEY];