backups (tgz): save integrity information

we generate a signing key pair for each target. Initially, I had this
as global. We needed a route to return the public key and putting it
under backup target seemed natural. Since we delete the backups when
we delete a target, we lose all the signing hashes. So, it's fine to lose
the key pair on target delete.
This commit is contained in:
Girish Ramakrishnan
2025-08-11 19:30:22 +05:30
parent 25fa999259
commit 47fc9561ab
9 changed files with 110 additions and 30 deletions
+13 -1
View File
@@ -8,6 +8,7 @@ exports = module.exports = {
add,
update,
setState,
setIntegrity,
list,
del,
@@ -29,7 +30,7 @@ const assert = require('assert'),
hat = require('./hat.js'),
safe = require('safetydance');
const BACKUPS_FIELDS = [ 'id', 'remotePath', 'label', 'identifier', 'creationTime', 'packageVersion', 'type', 'dependsOnJson', 'state', 'manifestJson', 'preserveSecs', 'encryptionVersion', 'appConfigJson', 'targetId' ].join(',');
const BACKUPS_FIELDS = [ 'id', 'remotePath', 'label', 'identifier', 'creationTime', 'packageVersion', 'type', 'integrityJson', 'dependsOnJson', 'state', 'manifestJson', 'preserveSecs', 'encryptionVersion', 'appConfigJson', 'targetId' ].join(',');
function postProcess(result) {
assert.strictEqual(typeof result, 'object');
@@ -40,6 +41,9 @@ function postProcess(result) {
result.manifest = result.manifestJson ? safe.JSON.parse(result.manifestJson) : null;
delete result.manifestJson;
result.integrity = result.integrityJson ? safe.JSON.parse(result.integrityJson) : null;
delete result.integrityJson;
result.appConfig = result.appConfigJson ? safe.JSON.parse(result.appConfigJson) : null;
delete result.appConfigJson;
@@ -166,6 +170,14 @@ async function setState(id, state) {
if (result.affectedRows !== 1) throw new BoxError(BoxError.NOT_FOUND, 'Backup not found');
}
async function setIntegrity(id, integrity) {
assert.strictEqual(typeof id, 'string');
assert.strictEqual(typeof integrity, 'object');
const result = await database.query('UPDATE backups SET integrityJson = ? WHERE id = ?', [JSON.stringify(integrity), id]);
if (result.affectedRows !== 1) throw new BoxError(BoxError.NOT_FOUND, 'Backup not found');
}
async function list(page, perPage) {
assert(typeof page === 'number' && page > 0);
assert(typeof perPage === 'number' && perPage > 0);