FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
secureCodeBox/parser-sdk/nodejs/parser-utils.js at python-venv · Spritekin/secureCodeBox · GitHub
Spritekin
/
secureCodeBox
Public
forked from
secureCodeBox/secureCodeBox
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
secureCodeBox
/
parser-sdk
/
nodejs
/
parser-utils.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
55 lines (49 loc) · 1.58 KB
Breadcrumbs
secureCodeBox
/
parser-sdk
/
nodejs
/
parser-utils.js
Copy path
File metadata and controls
55 lines (49 loc) · 1.58 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const
fs
=
require
(
"fs"
)
;
const
Ajv
=
require
(
"ajv-draft-04"
)
;
const
ajv
=
new
Ajv
(
)
;
const
addFormats
=
require
(
"ajv-formats"
)
;
addFormats
(
ajv
)
;
const
util
=
require
(
"util"
)
;
const
jsonpointer
=
require
(
"jsonpointer"
)
;
// eslint-disable-next-line security/detect-non-literal-fs-filename
const
readFile
=
util
.
promisify
(
fs
.
readFile
)
;
const
{
v4
:
uuid
}
=
require
(
"uuid"
)
;
function
addIdsAndDates
(
findings
)
{
return
findings
.
map
(
(
finding
)
=>
{
return
{
...
finding
,
id
:
uuid
(
)
,
parsed_at
:
new
Date
(
)
.
toISOString
(
)
,
}
;
}
)
;
}
async
function
validateAgainstJsonSchema
(
jsonData
)
{
const
jsonSchemaString
=
await
readFile
(
__dirname
+
"/findings-schema.json"
,
"utf8"
)
;
const
jsonSchema
=
JSON
.
parse
(
jsonSchemaString
)
;
const
validator
=
ajv
.
compile
(
jsonSchema
)
;
const
valid
=
validator
(
jsonData
)
;
if
(
!
valid
)
{
const
errorMessage
=
generateErrorMessage
(
validator
.
errors
,
jsonData
)
;
throw
new
Error
(
errorMessage
)
;
}
}
async
function
addSampleIdsAndDatesAndValidate
(
jsonData
)
{
// add sample IDs and Dates only if the jsonData Array is not empty
const
extendedData
=
addIdsAndDates
(
jsonData
)
;
return
validateAgainstJsonSchema
(
extendedData
)
;
}
function
generateErrorMessage
(
errors
,
jsonData
)
{
errors
=
errors
.
map
(
(
error
)
=>
{
return
{
...
error
,
invalidValue
:
jsonpointer
.
get
(
jsonData
,
error
.
instancePath
)
,
}
;
}
)
;
return
JSON
.
stringify
(
errors
,
null
,
2
)
;
}
module
.
exports
.
addIdsAndDates
=
addIdsAndDates
;
module
.
exports
.
validate
=
validateAgainstJsonSchema
;
module
.
exports
.
validateParser
=
addSampleIdsAndDatesAndValidate
;
Back
|
FazBrowse Home
|
New Git URL