Add endpoints to create and delete remote server (#4606)

* Build remote server

* Add getters

* Migrate to json inputs

* Use extendable type

* Use regex validation

* Remove acronymes

---------

Co-authored-by: Thomas Trompette <thomast@twenty.com>
This commit is contained in:
Thomas Trompette
2024-03-25 15:21:23 +01:00
committed by GitHub
parent e2af5b8628
commit 9e70f5b650
17 changed files with 496 additions and 3 deletions

View File

@ -1,3 +1,5 @@
import { createCipheriv, createDecipheriv, createHash } from 'crypto';
import * as bcrypt from 'bcrypt';
export const PASSWORD_REGEX = /^.{8,}$/;
@ -13,3 +15,42 @@ export const hashPassword = async (password: string) => {
export const compareHash = async (password: string, passwordHash: string) => {
return bcrypt.compare(password, passwordHash);
};
export const encryptText = async (
textToEncrypt: string,
key: string,
iv: string,
): Promise<string> => {
const keyHash = createHash('sha512')
.update(key)
.digest('hex')
.substring(0, 32);
const ivHash = createHash('sha512').update(iv).digest('hex').substring(0, 16);
const cipher = createCipheriv('aes-256-ctr', keyHash, ivHash);
return Buffer.concat([cipher.update(textToEncrypt), cipher.final()]).toString(
'base64',
);
};
export const decryptText = async (
textToDecrypt: string,
key: string,
iv: string,
) => {
const keyHash = createHash('sha512')
.update(key)
.digest('hex')
.substring(0, 32);
const ivHash = createHash('sha512').update(iv).digest('hex').substring(0, 16);
const decipher = createDecipheriv('aes-256-ctr', keyHash, ivHash);
return Buffer.concat([
decipher.update(Buffer.from(textToDecrypt, 'base64')),
decipher.final(),
]).toString();
};

View File

@ -10,6 +10,7 @@ import { TimelineMessagingModule } from 'src/engine/core-modules/messaging/timel
import { TimelineCalendarEventModule } from 'src/engine/core-modules/calendar/timeline-calendar-event.module';
import { BillingModule } from 'src/engine/core-modules/billing/billing.module';
import { HealthModule } from 'src/engine/core-modules/health/health.module';
import { RemoteServerModule } from 'src/engine/metadata-modules/remote-server/remote-server.module';
import { AnalyticsModule } from './analytics/analytics.module';
import { FileModule } from './file/file.module';
@ -30,6 +31,7 @@ import { ClientConfigModule } from './client-config/client-config.module';
TimelineCalendarEventModule,
UserModule,
WorkspaceModule,
RemoteServerModule,
],
exports: [
AnalyticsModule,