diff --git a/migrations/20250724102340-backupSites-create-table.js b/migrations/20250724102340-backupSites-create-table.js index a832daeae..97475a1f5 100644 --- a/migrations/20250724102340-backupSites-create-table.js +++ b/migrations/20250724102340-backupSites-create-table.js @@ -22,7 +22,7 @@ exports.up = async function (db) { 'integrityKeyPairJson TEXT,' + 'format VARCHAR(16) NOT NULL,' + 'schedule VARCHAR(128),' + - 'enabledForUpdates BOOLEAN DEFAULT false,' + + 'enableForUpdates BOOLEAN DEFAULT false,' + 'contentsJson TEXT,' + 'creationTime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,' + 'ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,' + @@ -39,7 +39,7 @@ exports.up = async function (db) { return; } - const name = 'Default', enabledForUpdates = true; + const name = 'Default', enableForUpdates = true; let config = null, limits = null, encryption = null, format = null, provider = null; let retention = { keepWithinSecs: 2 * 24 * 60 * 60 }; let schedule = '00 00 23 * * *'; @@ -100,8 +100,8 @@ exports.up = async function (db) { child_process.execSync(`rm -f ${targetInfoDir}/*.cache`); await db.runSql('START TRANSACTION'); - await db.runSql('INSERT INTO backupSites (id, name, provider, configJson, limitsJson, integrityKeyPairJson, retentionJson, schedule, encryptionJson, format, enabledForUpdates) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', - [ id, name, provider, JSON.stringify(config), JSON.stringify(limits), JSON.stringify(integrityKeyPair), JSON.stringify(retention), schedule, JSON.stringify(encryption), format, enabledForUpdates ]); + await db.runSql('INSERT INTO backupSites (id, name, provider, configJson, limitsJson, integrityKeyPairJson, retentionJson, schedule, encryptionJson, format, enableForUpdates) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', + [ id, name, provider, JSON.stringify(config), JSON.stringify(limits), JSON.stringify(integrityKeyPair), JSON.stringify(retention), schedule, JSON.stringify(encryption), format, enableForUpdates ]); await deleteOldSettings(db); await db.runSql('COMMIT'); }; diff --git a/src/backupsites.js b/src/backupsites.js index f66a80369..5150490c5 100644 --- a/src/backupsites.js +++ b/src/backupsites.js @@ -64,7 +64,7 @@ const assert = require('node:assert'), // filesystem - backupDir, noHardlinks // mountpoint - mountPoint, prefix, noHardlinks // encryption: 'encryptionPassword' and 'encryptedFilenames' is converted into an 'encryption' object using hush.js. Password is lost forever after conversion. -const BACKUP_TARGET_FIELDS = [ 'id', 'name', 'provider', 'configJson', 'limitsJson', 'retentionJson', 'schedule', 'encryptionJson', 'format', 'enabledForUpdates', 'contentsJson', 'creationTime', 'ts', 'integrityKeyPairJson' ].join(','); +const BACKUP_TARGET_FIELDS = [ 'id', 'name', 'provider', 'configJson', 'limitsJson', 'retentionJson', 'schedule', 'encryptionJson', 'format', 'enableForUpdates', 'contentsJson', 'creationTime', 'ts', 'integrityKeyPairJson' ].join(','); function storageApi(backupSite) { assert.strictEqual(typeof backupSite, 'object'); @@ -117,7 +117,7 @@ function postProcess(result) { result.integrityKeyPair = result.integrityKeyPairJson ? safe.JSON.parse(result.integrityKeyPairJson) : null; delete result.integrityKeyPairJson; - result.enabledForUpdates = !!result.enabledForUpdates; + result.enableForUpdates = !!result.enableForUpdates; result.contents = safe.JSON.parse(result.contentsJson) || null; delete result.contentsJson; @@ -216,7 +216,7 @@ function hasContent({ contents }, id) { async function listByContentForUpdates(id) { assert.strictEqual(typeof id, 'string'); - const results = await database.query(`SELECT ${BACKUP_TARGET_FIELDS} FROM backupSites WHERE enabledForUpdates=?`, [ true ]); + const results = await database.query(`SELECT ${BACKUP_TARGET_FIELDS} FROM backupSites WHERE enableForUpdates=?`, [ true ]); results.forEach(function (result) { postProcess(result); }); return results.filter(r => hasContent(r, id)); @@ -235,7 +235,7 @@ async function update(site, data) { const args = []; const fields = []; for (const k in data) { - if (k === 'name' || k === 'schedule' || k === 'enabledForUpdates') { // format, provider cannot be updated + if (k === 'name' || k === 'schedule' || k === 'enableForUpdates') { // format, provider cannot be updated fields.push(k + ' = ?'); args.push(data[k]); } else if (k === 'config' || k === 'limits' || k === 'retention' || k === 'contents') { // encryption cannot be updated @@ -284,13 +284,13 @@ async function setRetention(backupSite, retention, auditSource) { await eventlog.add(eventlog.ACTION_BACKUP_TARGET_UPDATE, auditSource, { backupSite, retention }); } -async function setEnabledForUpdates(backupSite, enabledForUpdates, auditSource) { +async function setEnabledForUpdates(backupSite, enableForUpdates, auditSource) { assert.strictEqual(typeof backupSite, 'object'); - assert.strictEqual(typeof enabledForUpdates, 'boolean'); + assert.strictEqual(typeof enableForUpdates, 'boolean'); assert.strictEqual(typeof auditSource, 'object'); - await update(backupSite, { enabledForUpdates }); - await eventlog.add(eventlog.ACTION_BACKUP_TARGET_UPDATE, auditSource, { backupSite, enabledForUpdates }); + await update(backupSite, { enableForUpdates }); + await eventlog.add(eventlog.ACTION_BACKUP_TARGET_UPDATE, auditSource, { backupSite, enableForUpdates }); } async function setEncryption(backupSite, data, auditSource) { @@ -548,7 +548,7 @@ async function add(data, auditSource) { debug('add: validating new storage configuration'); const sanitizedConfig = await storageApi({ provider }).verifyConfig({id, provider, config }); - await database.query('INSERT INTO backupSites (id, name, provider, configJson, contentsJson, limitsJson, integrityKeyPairJson, retentionJson, schedule, encryptionJson, format, enabledForUpdates) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', + await database.query('INSERT INTO backupSites (id, name, provider, configJson, contentsJson, limitsJson, integrityKeyPairJson, retentionJson, schedule, encryptionJson, format, enableForUpdates) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [ id, name, provider, JSON.stringify(sanitizedConfig), JSON.stringify(contents), JSON.stringify(limits), JSON.stringify(integrityKeyPair), JSON.stringify(retention), schedule, JSON.stringify(encryption), format, enableForUpdates ]); debug('add: setting up new storage configuration'); @@ -571,7 +571,7 @@ async function addDefault(auditSource) { schedule: '00 00 23 * * *', format: 'tgz', contents: null, - enabledForUpdates: true + enableForUpdates: true }; return await add(defaultBackupSite, auditSource); } diff --git a/src/routes/test/backupsites-test.js b/src/routes/test/backupsites-test.js index 4f99e7662..08e76d104 100644 --- a/src/routes/test/backupsites-test.js +++ b/src/routes/test/backupsites-test.js @@ -21,7 +21,7 @@ describe('Backups API', function () { retention: { keepWithinSecs: 60 * 60 }, schedule: '00 01 * * * *', contents: null, - enabledForUpdates: true + enableForUpdates: true }; const encryptedSite = { @@ -32,7 +32,7 @@ describe('Backups API', function () { retention: { keepMonthly: 60 }, schedule: '* 1 * * * *', contents: { exclude: [ 'thatapp' ] }, - enabledForUpdates: false + enableForUpdates: false }; describe('add', function () { @@ -79,7 +79,7 @@ describe('Backups API', function () { expect(tmp.config).to.be.ok(); expect(tmp.format).to.be(newSite.format); expect(tmp.name).to.be(newSite.name); - expect(tmp.enabledForUpdates).to.be(true); + expect(tmp.enableForUpdates).to.be(true); }); }); @@ -92,7 +92,7 @@ describe('Backups API', function () { expect(response.body.config).to.be.ok(); expect(response.body.format).to.be(newSite.format); expect(response.body.name).to.be(newSite.name); - expect(response.body.enabledForUpdates).to.be(true); + expect(response.body.enableForUpdates).to.be(true); }); it('succeeds as admin (encrypted)', async function () { @@ -103,7 +103,7 @@ describe('Backups API', function () { expect(response.body.config).to.be.ok(); expect(response.body.format).to.be(encryptedSite.format); expect(response.body.name).to.be(encryptedSite.name); - expect(response.body.enabledForUpdates).to.be(false); + expect(response.body.enableForUpdates).to.be(false); expect(response.body.encrypted).to.be(true); expect(response.body.encryptedFilenames).to.be(true); }); @@ -267,7 +267,7 @@ describe('Backups API', function () { }); }); - describe('enabledForUpdates', function () { + describe('enableForUpdates', function () { it('cannot set invalid id', async function () { const response = await superagent.post(`${serverUrl}/api/v1/backup_sites/${newSite.id}xx/configure/enable_for_updates`) .query({ access_token: owner.token }) @@ -287,10 +287,10 @@ describe('Backups API', function () { expect(response.status).to.equal(200); const result = await backupSites.get(newSite.id); - expect(result.enabledForUpdates).to.be(false); + expect(result.enableForUpdates).to.be(false); const result2 = await backupSites.get(oldDefault.id); - expect(result2.enabledForUpdates).to.be(true); + expect(result2.enableForUpdates).to.be(true); }); }); diff --git a/src/test/backupsites-test.js b/src/test/backupsites-test.js index 23d1f0bd9..efffb50e8 100644 --- a/src/test/backupsites-test.js +++ b/src/test/backupsites-test.js @@ -31,7 +31,7 @@ describe('backups', function () { retention: { keepWithinSecs: 2 * 24 * 60 * 60 }, schedule: '00 00 23 * * *', contents: null, - enabledForUpdates: true + enableForUpdates: true }; const appBackup = { @@ -54,7 +54,6 @@ describe('backups', function () { before(async function () { defaultBackupSite = await getDefaultBackupSite(); - console.log(defaultBackupSite); appBackup.siteId = defaultBackupSite.id; appBackup.id = await backups.add(appBackup); await archives.add(appBackup.id, {}, auditSource); @@ -78,7 +77,7 @@ describe('backups', function () { expect(backupSite.format).to.be('tgz'); expect(backupSite.encryption).to.be(null); expect(backupSite.contents).to.be(null); - expect(backupSite.enabledForUpdates).to.be(true); + expect(backupSite.enableForUpdates).to.be(true); }); it('cannot get random backup site', async function () { @@ -123,7 +122,7 @@ describe('backups', function () { it('cannot disable for update', async function () { await backupSites.setEnabledForUpdates(defaultBackupSite, false, auditSource); const backupSite = await backupSites.get(defaultBackupSite.id); - expect(backupSite.enabledForUpdates).to.eql(false); + expect(backupSite.enableForUpdates).to.eql(false); }); it('can delete all the backup sites', async function () {