3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

Encrypt archives at rest

This commit is contained in:
Dragory 2020-09-16 22:42:25 +03:00
parent 7562a886e1
commit a017aa7bfe
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
3 changed files with 47 additions and 1 deletions

View file

@ -0,0 +1,20 @@
import { MigrationInterface, QueryRunner } from "typeorm";
import { decrypt, encrypt } from "../utils/crypt";
export class EncryptArchives1600285077890 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<any> {
const archives = await queryRunner.query("SELECT id, body FROM archives");
for (const archive of archives) {
const encryptedBody = encrypt(archive.body);
await queryRunner.query("UPDATE archives SET body = ? WHERE id = ?", [encryptedBody, archive.id]);
}
}
public async down(queryRunner: QueryRunner): Promise<any> {
const archives = await queryRunner.query("SELECT id, body FROM archives");
for (const archive of archives) {
const decryptedBody = decrypt(archive.body);
await queryRunner.query("UPDATE archives SET body = ? WHERE id = ?", [decryptedBody, archive.id]);
}
}
}