Skip to content

Commit ca9178b

Browse files
committed
fix(backend): enforce encryption
1 parent 8015e72 commit ca9178b

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { MigrationInterface, QueryRunner } from "typeorm";
2+
import { domifaConfig } from "../config";
3+
import { structureDocRepository } from "../database";
4+
5+
export class AutoMigration1747256357378 implements MigrationInterface {
6+
name = "AutoMigration1747256357378";
7+
8+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
9+
public async up(_queryRunner: QueryRunner): Promise<void> {
10+
if (
11+
domifaConfig().envId === "prod" ||
12+
domifaConfig().envId === "preprod" ||
13+
domifaConfig().envId === "local"
14+
) {
15+
await structureDocRepository.update({}, { encryptionContext: null });
16+
}
17+
}
18+
19+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
20+
public async down(_queryRunner: QueryRunner): Promise<void> {}
21+
}

packages/backend/src/_migrations/1748264445999-encrypt-structure-docs-migration.ts renamed to packages/backend/src/_migrations/1748264443999-encrypt-structure-docs-migration.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Readable } from "node:stream";
1010
type Docs = StructureDoc & {
1111
structureUuid: string;
1212
};
13-
export class EncryptStructureDocsMigration1748264445999
13+
export class EncryptStructureDocsMigration1748264443999
1414
implements MigrationInterface
1515
{
1616
public fileManagerService: FileManagerService;
@@ -26,7 +26,7 @@ export class EncryptStructureDocsMigration1748264445999
2626
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2727
public async up(_queryRunner: QueryRunner): Promise<void> {
2828
appLogger.warn("[MIGRATION] Encrypt structure docs");
29-
await structureDocRepository.update({}, { encryptionContext: null });
29+
3030
const unencryptedDocs: Docs[] = await structureDocRepository
3131
.createQueryBuilder("structure_doc")
3232
.leftJoin(
@@ -50,7 +50,7 @@ export class EncryptStructureDocsMigration1748264445999
5050
);
5151
const pLimit = (await import("p-limit")).default;
5252

53-
const limit = pLimit(3);
53+
const limit = pLimit(2);
5454

5555
const promises = unencryptedDocs.map((doc) =>
5656
limit(() => this.processWithPause(doc))
@@ -85,18 +85,17 @@ export class EncryptStructureDocsMigration1748264445999
8585
} else {
8686
appLogger.warn("⚠️ Migration completed with errors");
8787
}
88-
throw new Error("pokpo");
8988
}
9089

9190
public processWithPause = async (doc: Docs) => {
9291
await this.processDoc(doc);
9392
this.processedSinceLastPause++;
9493

95-
if (this.processedSinceLastPause >= 6) {
94+
if (this.processedSinceLastPause >= 4) {
9695
this.processedSinceLastPause = 0;
9796

9897
appLogger.info("⏸️ Wait one second ");
99-
await new Promise((resolve) => setTimeout(resolve, 1500));
98+
await new Promise((resolve) => setTimeout(resolve, 3000));
10099
}
101100
};
102101

packages/backend/src/util/file-manager/file-manager.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export class FileManagerService {
155155
return finalBuffer;
156156
} catch (error) {
157157
chunks.length = 0;
158-
appLogger.error(`Erreur décryptage ${filePath}:`, error.message);
158+
appLogger.error(`Decrypt fail ${filePath}:`, error.message);
159159
throw error;
160160
}
161161
}

0 commit comments

Comments
 (0)