Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scanner
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
whats-this
scanner
Commits
a29f0a64
Commit
a29f0a64
authored
8 years ago
by
aurieh
Browse files
Options
Downloads
Patches
Plain Diff
Scan, WIP
parent
9f4898db
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
routes/scan.js
+37
-35
37 additions, 35 deletions
routes/scan.js
with
37 additions
and
35 deletions
routes/scan.js
+
37
−
35
View file @
a29f0a64
...
@@ -124,53 +124,55 @@ function fireInfectedNotification (data) {
...
@@ -124,53 +124,55 @@ function fireInfectedNotification (data) {
* > POST /scan
* > POST /scan
* Scan the file specified in the S3 event in the body.
* Scan the file specified in the S3 event in the body.
*/
*/
module
.
exports
=
function
scan
(
req
,
res
,
next
)
{
module
.
exports
=
function
*
scan
()
{
debug
(
'
received data from SQS
'
);
debug
(
'
received data from SQS
'
);
// Reject incoming data
// Reject incoming data
function
rejectData
(
msg
)
{
function
rejectData
(
msg
)
{
res
.
status
(
400
).
json
({
this
.
status
=
400
;
this
.
body
=
{
code
:
400
,
code
:
400
,
message
:
msg
message
:
msg
}
)
;
};
}
}
// Test incoming data
// Test incoming data
if
(
req
.
body
.
Event
===
'
s3:TestEvent
'
)
return
rejectData
(
'
test event
'
);
if
(
this
.
req
.
body
.
Event
===
'
s3:TestEvent
'
)
return
rejectData
(
'
test event
'
);
if
(
!
Array
.
isArray
(
req
.
body
.
Records
))
return
rejectData
(
'
invalid S3 message structure
'
);
if
(
!
Array
.
isArray
(
this
.
req
.
body
.
Records
))
return
rejectData
(
'
invalid S3 message structure
'
);
if
(
req
.
body
.
Records
.
length
!==
1
)
return
rejectData
(
'
records count !== 1
'
);
if
(
this
.
req
.
body
.
Records
.
length
!==
1
)
return
rejectData
(
'
records count !== 1
'
);
for
(
const
item
of
req
.
body
.
Records
)
{
for
(
const
item
of
this
.
req
.
body
.
Records
)
{
if
(
typeof
item
!==
'
object
'
||
item
===
null
)
return
rejectData
(
'
invalid item in records
'
);
if
(
typeof
item
!==
'
object
'
||
item
===
null
)
return
rejectData
(
'
invalid item in records
'
);
if
(
typeof
item
.
eventName
!==
'
string
'
||
item
.
eventName
.
indexOf
(
'
ObjectCreated
'
)
===
-
1
)
return
rejectData
(
'
invalid event type on record
'
);
if
(
typeof
item
.
eventName
!==
'
string
'
||
item
.
eventName
.
indexOf
(
'
ObjectCreated
'
)
===
-
1
)
return
rejectData
(
'
invalid event type on record
'
);
}
}
// Promise chain for processing the scan
// Promise chain for processing the scan
Promise
.
resolve
(
req
.
body
)
try
{
.
then
(
getObject
)
const
data
=
yield
Promise
.
resolve
(
this
.
req
.
body
)
.
then
(
writeTempFile
)
.
then
(
getObject
)
.
then
(
clamScan
)
.
then
(
writeTempFile
)
// TODO: .then(uploadInfectedToS3)
.
then
(
clamScan
)
.
then
(
unlinkTempFile
)
// TODO: .then(uploadInfectedToS3)
.
then
(
deleteInfectedFromS3
)
.
then
(
unlinkTempFile
)
.
then
(
fireInfectedNotification
)
.
then
(
deleteInfectedFromS3
)
.
then
(
data
=>
{
.
then
(
fireInfectedNotification
);
res
.
status
(
200
).
json
({
this
.
status
=
200
;
processed
:
true
,
this
.
body
=
{
infected
:
data
.
isInfected
||
false
,
processed
:
true
,
permanentlyDeleted
:
data
.
wasPermanentlyDeleted
||
false
infected
:
data
.
isInfected
||
false
,
});
permanentlyDeleted
:
data
.
wasPermanentlyDeleted
||
false
})
};
.
catch
(
err
=>
{
}
catch
(
err
)
{
console
.
error
(
err
.
stack
);
console
.
error
(
err
.
stack
);
res
.
status
(
500
).
json
({
this
.
status
=
500
;
code
:
500
,
this
.
body
=
{
message
:
'
internal server error
'
,
code
:
500
,
data
:
{
message
:
'
internal server error
'
,
type
:
err
.
type
,
data
:
{
name
:
err
.
name
,
type
:
err
.
type
,
arguments
:
err
.
arguments
,
name
:
err
.
name
,
message
:
err
.
message
arguments
:
err
.
arguments
,
}
message
:
err
.
message
});
}
});
};
}
};
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment