Add crud for exposed ldap settings

This commit is contained in:
Johannes Zellner
2021-11-23 18:00:07 +01:00
parent 3a8aaf72ba
commit 4a467c4dce
3 changed files with 96 additions and 0 deletions

View File

@@ -31,6 +31,9 @@ exports = module.exports = {
getExternalLdapConfig,
setExternalLdapConfig,
getExposedLdapConfig,
setExposedLdapConfig,
getRegistryConfig,
setRegistryConfig,
@@ -93,6 +96,7 @@ exports = module.exports = {
BACKUP_CONFIG_KEY: 'backup_config',
SERVICES_CONFIG_KEY: 'services_config',
EXTERNAL_LDAP_KEY: 'external_ldap_config',
EXPOSED_LDAP_KEY: 'exposed_ldap_config',
REGISTRY_CONFIG_KEY: 'registry_config',
SYSINFO_CONFIG_KEY: 'sysinfo_config',
APPSTORE_LISTING_CONFIG_KEY: 'appstore_listing_config',
@@ -180,6 +184,9 @@ const gDefaults = (function () {
provider: 'noop',
autoCreate: false
};
result[exports.EXPOSED_LDAP_KEY] = {
enabled: false
};
result[exports.REGISTRY_CONFIG_KEY] = {
provider: 'noop'
};
@@ -490,6 +497,26 @@ async function setExternalLdapConfig(externalLdapConfig) {
notifyChange(exports.EXTERNAL_LDAP_KEY, externalLdapConfig);
}
async function getExposedLdapConfig() {
const value = await get(exports.EXPOSED_LDAP_KEY);
if (value === null) return gDefaults[exports.EXPOSED_LDAP_KEY];
return JSON.parse(value);
}
async function setExposedLdapConfig(exposedLdapConfig) {
assert.strictEqual(typeof exposedLdapConfig, 'object');
if (isDemo()) throw new BoxError(BoxError.BAD_FIELD, 'Not allowed in demo mode');
const config = {
enabled: exposedLdapConfig.enabled
};
await set(exports.EXPOSED_LDAP_KEY, JSON.stringify(config));
notifyChange(exports.EXPOSED_LDAP_KEY, config);
}
async function getRegistryConfig() {
const value = await get(exports.REGISTRY_CONFIG_KEY);
if (value === null) return gDefaults[exports.REGISTRY_CONFIG_KEY];