Skip to content

Commit

Permalink
Revert "feat: encrypt pii data (#203)" (#204)
Browse files Browse the repository at this point in the history
This reverts commit ba2e854.
  • Loading branch information
jatinsandilya authored Aug 23, 2023
1 parent ba2e854 commit a1b3d86
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 165 deletions.
1 change: 0 additions & 1 deletion packages/backend/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const config = {
SHORTLOOP_AUTH_KEY: process.env.SHORTLOOP_AUTH_KEY!,
SVIX_ENDPOINT_SECRET: process.env.SVIX_ENDPOINT_SECRET!,
svix: new Svix(process.env.SVIX_AUTH_TOKEN!),
AES_ENCRYPTION_SECRET: process.env.AES_ENCRYPTION_SECRET!,
};

export default config;
48 changes: 0 additions & 48 deletions packages/backend/helpers/gcmUtil.ts

This file was deleted.

66 changes: 0 additions & 66 deletions packages/backend/prisma/client.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,6 @@
import { PrismaClient, Prisma } from '@prisma/client';
import config from '../config';
import gcm from '../helpers/gcmUtil';

const prisma = new PrismaClient();

// Prisma middleware to encrypt and decrypt data on fly
prisma.$use(async (params, next) => {
if (params.model !== 'connections') {
return next(params);
}

const isReadOperation = ['findFirst', 'findMany', 'delete'].includes(params.action);
const isWriteOperation = ['update', 'upsert'].includes(params.action);

if (isReadOperation) {
return handleReadOperation(params, next);
} else if (isWriteOperation) {
return handleWriteOperation(params, next);
}
return next(params);
});

async function handleReadOperation(
params: Prisma.MiddlewareParams,
next: (params: Prisma.MiddlewareParams) => Promise<any>
): Promise<any> {
try {
const connections = await next(params);
if (!connections) return connections;
if (Array.isArray(connections)) {
connections.forEach((connection) => {
connection.tp_customer_id = gcm.decrypt(connection.tp_customer_id, config.AES_ENCRYPTION_SECRET);
});
} else {
connections.tp_customer_id = gcm.decrypt(connections.tp_customer_id, config.AES_ENCRYPTION_SECRET);
}
return connections;
} catch (error: any) {
throw new Error(error);
}
}

async function handleWriteOperation(
params: Prisma.MiddlewareParams,
_: (params: Prisma.MiddlewareParams) => Promise<any>
): Promise<any> {
try {
if (Array.isArray(params.args?.data)) {
params.args?.data.forEach((connection: any) => {
connection.tp_customer_id = gcm.encrypt(connection.tp_customer_id, config.AES_ENCRYPTION_SECRET);
});
} else {
if (params.action === 'upsert') {
params.args.create.tp_customer_id = gcm.encrypt(
params.args.create.tp_customer_id,
config.AES_ENCRYPTION_SECRET
);
} else {
params.args.data.tp_customer_id = gcm.encrypt(
params.args.data.tp_customer_id,
config.AES_ENCRYPTION_SECRET
);
}
}
} catch (error: any) {
throw new Error(error);
}
}

export default prisma;
export { Prisma };
3 changes: 2 additions & 1 deletion packages/backend/services/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ const connectionService = new ConnectionService({
const deleted: any = await prisma.connections.delete({
// TODO: Add environments to connections.
where: {
uniqueThirdPartyPerTenant: {
uniqueCustomerPerTenantPerThirdParty: {
tp_customer_id: connection.tp_customer_id,
t_id: connection.t_id,
tp_id: connection.tp_id,
},
Expand Down
49 changes: 0 additions & 49 deletions scripts/backend/encrypt_customerEmails.js

This file was deleted.

1 comment on commit a1b3d86

@vercel
Copy link

@vercel vercel bot commented on a1b3d86 Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

revert-client – ./

revert-client-git-main-revertdev.vercel.app
app.revert.dev
revert-client-revertdev.vercel.app

Please sign in to comment.