Skip to content

Commit b1d0d4c

Browse files
committed
Upgrade age to 0.2 and adapt to the new interface.
1 parent cde5e15 commit b1d0d4c

File tree

4 files changed

+41
-33
lines changed

4 files changed

+41
-33
lines changed

backup/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
},
66
"dependencies": {
77
"@google-cloud/storage": "^7.14.0",
8-
"age-encryption": "^0.1.5",
8+
"age-encryption": "^0.2.0",
99
"express": "^4.21.2",
1010
"morgan": "^1.10.0"
1111
},

backup/pnpm-lock.yaml

Lines changed: 34 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backup/server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Storage } from '@google-cloud/storage';
2+
import * as age from 'age-encryption';
23
import express from 'express';
34
import morgan from 'morgan';
45
import { exec } from 'node:child_process';
56
import process from 'node:process';
67
import util from 'node:util';
78
import zlib from 'node:zlib';
8-
import age from 'age-encryption';
99

1010
const execP = util.promisify(exec);
1111

@@ -54,9 +54,9 @@ app.post('/backup', async (req, res) => {
5454
}
5555
});
5656

57-
const encrypter = new (await age()).Encrypter;
57+
const encrypter = new age.Encrypter;
5858
encrypter.addRecipient(process.env.BACKUP_AGE_RECIPIENT!);
59-
const encrypted = encrypter.encrypt(compressed);
59+
const encrypted = await encrypter.encrypt(compressed);
6060

6161
const bucket = 'vlach-cookbook-backup';
6262
const filename = `backup-${backupTimestamp.toISOString()}.br.age`;

webserver/replaceDbWithBackup.mjs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Storage } from '@google-cloud/storage';
2-
import age from "age-encryption";
2+
import * as age from "age-encryption";
33
import { execSync } from 'node:child_process';
44
import zlib from 'node:zlib';
55

@@ -33,10 +33,9 @@ export async function replaceDbWithBackup({DATABASE_URL, dbName, GOOGLE_CREDENTI
3333
}
3434
const [contents] = await recentBackups[recentBackups.length - 1].download();
3535

36-
const { Decrypter } = await age();
37-
const d = new Decrypter();
36+
const d = new age.Decrypter();
3837
d.addIdentity(AGE_IDENTITY);
39-
const decrypted = d.decrypt(contents);
38+
const decrypted = await d.decrypt(contents);
4039

4140
const dump = zlib.brotliDecompressSync(decrypted).toString('utf-8');
4241

0 commit comments

Comments
 (0)