Ability to work without encryption in db

This commit is contained in:
Romaric Mourgues
2023-04-24 17:24:31 +02:00
parent b6420f280c
commit a454875602
2 changed files with 18 additions and 15 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"database": { "database": {
"secret": "ab63bb3e90c0271c9a1c06651a7c0967eab8851a7a897766", "secret": "",
"mongodb": { "mongodb": {
"uri": "mongodb://mongo:27017" "uri": "mongodb://mongo:27017"
}, },
+17 -14
View File
@@ -19,22 +19,24 @@ export type CryptoResult = {
}; };
export function decrypt(data: string, encryptionKey: string): CryptoResult { export function decrypt(data: string, encryptionKey: string): CryptoResult {
let result = v2.decrypt(data, encryptionKey); if (encryptionKey) {
if (result.done) { let result = v2.decrypt(data, encryptionKey);
return result; if (result.done) {
return result;
}
result = v1.decrypt(data, encryptionKey);
if (result.done) {
return result;
}
result = legacy.decrypt(data, encryptionKey);
if (result.done) {
return result;
}
} }
result = v1.decrypt(data, encryptionKey); return { data, done: true };
if (result.done) {
return result;
}
result = legacy.decrypt(data, encryptionKey);
if (result.done) {
return result;
}
return result;
} }
export function md5(value: string): string { export function md5(value: string): string {
@@ -46,5 +48,6 @@ export function encrypt(
encryptionKey: any, encryptionKey: any,
options: { disableSalts?: boolean } = {}, options: { disableSalts?: boolean } = {},
): CryptoResult { ): CryptoResult {
if (!encryptionKey) return value;
return v2.encrypt(value, encryptionKey, options); return v2.encrypt(value, encryptionKey, options);
} }