Add registry config to settings table

This commit is contained in:
Girish Ramakrishnan
2019-10-22 22:07:44 -07:00
parent e82ac5ecc5
commit 8cdddef077
3 changed files with 79 additions and 4 deletions

View File

@@ -31,6 +31,9 @@ exports = module.exports = {
getExternalLdapConfig: getExternalLdapConfig,
setExternalLdapConfig: setExternalLdapConfig,
getRegistryConfig: getRegistryConfig,
setRegistryConfig: setRegistryConfig,
getLicenseKey: getLicenseKey,
setLicenseKey: setLicenseKey,
@@ -65,6 +68,7 @@ exports = module.exports = {
BACKUP_CONFIG_KEY: 'backup_config',
PLATFORM_CONFIG_KEY: 'platform_config',
EXTERNAL_LDAP_KEY: 'external_ldap_config',
REGISTRY_CONFIG_KEY: 'registry_config',
// strings
APP_AUTOUPDATE_PATTERN_KEY: 'app_autoupdate_pattern',
@@ -97,6 +101,7 @@ var addons = require('./addons.js'),
CronJob = require('cron').CronJob,
DatabaseError = require('./databaseerror.js'),
debug = require('debug')('box:settings'),
docker = require('./docker.js'),
externalldap = require('./externalldap.js'),
ExternalLdapError = externalldap.ExternalLdapError,
moment = require('moment-timezone'),
@@ -127,6 +132,7 @@ let gDefaults = (function () {
};
result[exports.PLATFORM_CONFIG_KEY] = {};
result[exports.EXTERNAL_LDAP_KEY] = {};
result[exports.REGISTRY_CONFIG_KEY] = {};
result[exports.ADMIN_DOMAIN_KEY] = '';
result[exports.ADMIN_FQDN_KEY] = '';
result[exports.API_SERVER_ORIGIN_KEY] = 'https://api.cloudron.io';
@@ -423,6 +429,40 @@ function setExternalLdapConfig(externalLdapConfig, callback) {
});
}
function getRegistryConfig(callback) {
assert.strictEqual(typeof callback, 'function');
settingsdb.get(exports.REGISTRY_CONFIG_KEY, function (error, value) {
if (error && error.reason === DatabaseError.NOT_FOUND) return callback(null, gDefaults[exports.REGISTRY_CONFIG_KEY]);
if (error) return callback(new BoxError(BoxError.DATABASE_ERROR, error));
callback(null, JSON.parse(value));
});
}
function setRegistryConfig(registryConfig, callback) {
assert.strictEqual(typeof registryConfig, 'object');
assert.strictEqual(typeof callback, 'function');
getRegistryConfig(function (error, curentConfig) {
if (error) return callback(error);
docker.injectPrivateFields(registryConfig, curentConfig);
docker.testRegistryConfig(registryConfig, function (error) {
if (error) return callback(error);
settingsdb.set(exports.REGISTRY_CONFIG_KEY, JSON.stringify(registryConfig), function (error) {
if (error) return callback(new BoxError(BoxError.DATABASE_ERROR, error));
notifyChange(exports.REGISTRY_CONFIG_KEY, registryConfig);
callback(null);
});
});
});
}
function getLicenseKey(callback) {
assert.strictEqual(typeof callback, 'function');
@@ -510,7 +550,7 @@ function getAll(callback) {
result[exports.DEMO_KEY] = !!result[exports.DEMO_KEY];
// convert JSON objects
[exports.BACKUP_CONFIG_KEY, exports.PLATFORM_CONFIG_KEY, exports.EXTERNAL_LDAP_KEY ].forEach(function (key) {
[exports.BACKUP_CONFIG_KEY, exports.PLATFORM_CONFIG_KEY, exports.EXTERNAL_LDAP_KEY, exports.REGISTRY_CONFIG_KEY ].forEach(function (key) {
result[key] = typeof result[key] === 'object' ? result[key] : safe.JSON.parse(result[key]);
});