Skip to content
Snippets Groups Projects
Commit e9c959e3 authored by aurieh's avatar aurieh
Browse files

Eslint, deps

parent eb518993
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,6 @@ ...@@ -6,6 +6,6 @@
"promise" "promise"
], ],
"rules": { "rules": {
"semi": "always" "semi": [2, "always"]
} }
} }
\ No newline at end of file
module.exports = function getFile(S3, key) { module.exports = function getFile (S3, key) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
S3.getObject({ S3.getObject({
Bucket: `${process.env.SERVICE}-filestore-${process.env.STAGE}-1`, Bucket: `${process.env.SERVICE}-filestore-${process.env.STAGE}-1`,
...@@ -8,4 +8,4 @@ module.exports = function getFile(S3, key) { ...@@ -8,4 +8,4 @@ module.exports = function getFile(S3, key) {
resolve(file); resolve(file);
}); });
}); });
} };
\ No newline at end of file
const exec = require('child_process').exec; const exec = require('child_process').exec;
const debug = require("debug")("scanner"); const debug = require('debug')('scanner');
module.exports = function refresh() { module.exports = function refresh () {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
debug('Updating virus database') debug('Updating virus database');
const proc = exec('freshclam', [], {stdio: 'inherit'}); const proc = exec('freshclam', [], {stdio: 'inherit'});
proc.on('error', reject); proc.on('error', reject);
proc.on('exit', code => { proc.on('exit', code => {
if (code !== 0) return void reject(new Error(`Clamscan exited with code ${code}`)); if (code !== 0) return void reject(new Error(`Clamscan exited with code ${code}`));
debug('Finished updating'); debug('Finished updating');
resolve(); resolve();
}) });
}); });
} };
\ No newline at end of file
...@@ -3,20 +3,20 @@ const fs = require('fs'); ...@@ -3,20 +3,20 @@ const fs = require('fs');
const path = require('path'); const path = require('path');
const getFile = require('./getfile'); const getFile = require('./getfile');
module.exports = function scanFile(notif, S3) { module.exports = function scanFile (notif, S3) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const key = notif.Records[0].s3.object.key; const key = notif.Records[0].s3.object.key;
getFile(S3, key).then(file => { getFile(S3, key).then(file => {
const filepath = path.resolve(path.join(__dirname, '/files/', key)); const filepath = path.resolve(path.join(__dirname, '/files/', key));
fs.writeFile(filepath, file.body, (err) => { fs.writeFile(filepath, file.body, (err) => {
if (err) return void reject(err); if (err) return void reject(err);
clam.is_infected(filepath, (err, _, is_infected) => { clam.is_infected(filepath, (err, _, isInfected) => {
fs.unlink(filepath, (unlinkErr) => { fs.unlink(filepath, (unlinkErr) => {
if (err || unlinkErr) return void reject(err || unlinkErr); if (err || unlinkErr) return void reject(err || unlinkErr);
resolve({infected: is_infected}); resolve({infected: isInfected});
}); });
}); });
}); });
}, reject); }, reject);
}); });
} };
\ No newline at end of file
...@@ -27,5 +27,9 @@ ...@@ -27,5 +27,9 @@
"eslint-config-standard": "^6.2.1", "eslint-config-standard": "^6.2.1",
"eslint-plugin-promise": "^3.4.0", "eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^2.0.1" "eslint-plugin-standard": "^2.0.1"
},
"dependencies": {
"clamscan": "^0.8.4",
"debug": "^2.4.4"
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment