Skip to content

Commit

Permalink
chore: revert
Browse files Browse the repository at this point in the history
  • Loading branch information
rafasdc committed Sep 16, 2024
1 parent 08d96c4 commit 013d451
Showing 1 changed file with 35 additions and 46 deletions.
81 changes: 35 additions & 46 deletions app/backend/lib/s3download.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { Router } from 'express';
import RateLimit from 'express-rate-limit';
import config from '../../config';
import getAuthRole from '../../utils/getAuthRole';
import { getFileTagging, getFileFromS3 } from './s3client';

const AWS_S3_BUCKET = config.get('AWS_S3_BUCKET');

const limiter = RateLimit({
windowMs: 1 * 60 * 1000,
max: 2000,
});

const s3download = Router();
const detectInfected = async (uuid: string) => {
const params = {
Expand All @@ -22,47 +16,42 @@ const detectInfected = async (uuid: string) => {
};

// eslint-disable-next-line consistent-return
s3download.get(
'/api/s3/download/:uuid/:fileName',
limiter,
// eslint-disable-next-line consistent-return
async (req, res) => {
const { uuid, fileName } = req.params;

const authRole = getAuthRole(req);
const isRoleAuthorized =
authRole?.pgRole === 'ccbc_admin' ||
authRole?.pgRole === 'ccbc_analyst' ||
authRole?.pgRole === 'ccbc_auth_user' ||
authRole?.pgRole === 'cbc_admin' ||
authRole?.pgRole === 'super_admin';

if (!isRoleAuthorized || !uuid || !fileName) {
return res.status(404).end();
}
if (
authRole?.pgRole === 'ccbc_admin' ||
authRole?.pgRole === 'ccbc_analyst' ||
authRole?.pgRole === 'cbc_admin' ||
authRole?.pgRole === 'super_admin'
) {
// first check AV tag
// only for admin and analyst
const healthCheck = await detectInfected(uuid);
const suspect = healthCheck.TagSet.find((x) => x.Key === 'av-status');
if (suspect?.Value === 'dirty') {
return res.json({ avstatus: 'dirty' });
}
s3download.get('/api/s3/download/:uuid/:fileName', async (req, res) => {
const { uuid, fileName } = req.params;

const authRole = getAuthRole(req);
const isRoleAuthorized =
authRole?.pgRole === 'ccbc_admin' ||
authRole?.pgRole === 'ccbc_analyst' ||
authRole?.pgRole === 'ccbc_auth_user' ||
authRole?.pgRole === 'cbc_admin' ||
authRole?.pgRole === 'super_admin';

if (!isRoleAuthorized || !uuid || !fileName) {
return res.status(404).end();
}
if (
authRole?.pgRole === 'ccbc_admin' ||
authRole?.pgRole === 'ccbc_analyst' ||
authRole?.pgRole === 'cbc_admin' ||
authRole?.pgRole === 'super_admin'
) {
// first check AV tag
// only for admin and analyst
const healthCheck = await detectInfected(uuid);
const suspect = healthCheck.TagSet.find((x) => x.Key === 'av-status');
if (suspect?.Value === 'dirty') {
return res.json({ avstatus: 'dirty' });
}

getFileFromS3(uuid, fileName, res)
.then(() => {
res.end();
})
.catch(() => {
res.status(500).end();
});
}
);

getFileFromS3(uuid, fileName, res)
.then(() => {
res.end();
})
.catch(() => {
res.status(500).end();
});
});

export default s3download;

0 comments on commit 013d451

Please sign in to comment.