backups: split config and policy

keeping them together makes the test/validation quite complicated.
for example, when policy is changed, we test the storage backends

part of #817
This commit is contained in:
Girish Ramakrishnan
2023-07-12 10:01:53 +05:30
parent 7926ff2811
commit 9cebde3005
15 changed files with 299 additions and 198 deletions

View File

@@ -24,6 +24,9 @@ exports = module.exports = {
getUnstableAppsConfig,
setUnstableAppsConfig,
getBackupPolicy,
setBackupPolicy,
getBackupConfig,
setBackupConfig,
setBackupCredentials,
@@ -101,6 +104,7 @@ exports = module.exports = {
// json. if you add an entry here, be sure to fix list()
BACKUP_CONFIG_KEY: 'backup_config',
BACKUP_POLICY_KEY: 'backup_policy',
SERVICES_CONFIG_KEY: 'services_config',
EXTERNAL_LDAP_KEY: 'external_ldap_config',
DIRECTORY_SERVER_KEY: 'user_directory_config',
@@ -187,8 +191,10 @@ const gDefaults = (function () {
backupFolder: '/var/backups',
format: 'tgz',
encryption: null,
retentionPolicy: { keepWithinSecs: 2 * 24 * 60 * 60 }, // 2 days
schedulePattern: '00 00 23 * * *' // every day at 11pm
};
result[exports.BACKUP_POLICY_KEY] = {
retention: { keepWithinSecs: 2 * 24 * 60 * 60 }, // 2 days
schedule: '00 00 23 * * *' // every day at 11pm
};
result[exports.REVERSE_PROXY_CONFIG_KEY] = {
ocsp: true
@@ -407,6 +413,22 @@ async function setUnstableAppsConfig(enabled) {
notifyChange(exports.UNSTABLE_APPS_KEY, enabled);
}
async function getBackupPolicy() {
const result = await get(exports.BACKUP_POLICY_KEY);
if (result === null) return gDefaults[exports.BACKUP_POLICY_KEY];
return JSON.parse(result);
}
async function setBackupPolicy(policy) {
assert.strictEqual(typeof policy, 'object');
const error = await backups.validatePolicy(policy);
if (error) throw error;
await set(exports.BACKUP_POLICY_KEY, JSON.stringify(policy));
notifyChange(exports.BACKUP_POLICY_KEY, policy);
}
async function getBackupConfig() {
const value = await get(exports.BACKUP_CONFIG_KEY);
if (value === null) return gDefaults[exports.BACKUP_CONFIG_KEY];
@@ -469,7 +491,7 @@ async function setBackupCredentials(credentials) {
const currentConfig = await getBackupConfig();
// preserve these fields
const extra = _.pick(currentConfig, 'retentionPolicy', 'schedulePattern', 'copyConcurrency', 'syncConcurrency', 'memoryLimit', 'downloadConcurrency', 'deleteConcurrency', 'uploadPartSize');
const extra = _.pick(currentConfig, 'copyConcurrency', 'syncConcurrency', 'memoryLimit', 'downloadConcurrency', 'deleteConcurrency', 'uploadPartSize');
const backupConfig = Object.assign({}, credentials, extra);
@@ -743,7 +765,8 @@ async function list() {
result[exports.DEMO_KEY] = !!result[exports.DEMO_KEY];
// convert JSON objects
[exports.BACKUP_CONFIG_KEY, exports.IPV6_CONFIG_KEY, exports.PROFILE_CONFIG_KEY, exports.SERVICES_CONFIG_KEY, exports.EXTERNAL_LDAP_KEY, exports.REGISTRY_CONFIG_KEY, exports.SYSINFO_CONFIG_KEY, exports.REVERSE_PROXY_CONFIG_KEY ].forEach(function (key) {
[exports.BACKUP_POLICY_KEY, exports.BACKUP_CONFIG_KEY, exports.IPV6_CONFIG_KEY, exports.PROFILE_CONFIG_KEY, exports.SERVICES_CONFIG_KEY,
exports.EXTERNAL_LDAP_KEY, exports.REGISTRY_CONFIG_KEY, exports.SYSINFO_CONFIG_KEY, exports.REVERSE_PROXY_CONFIG_KEY ].forEach(function (key) {
result[key] = typeof result[key] === 'object' ? result[key] : safe.JSON.parse(result[key]);
});