FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
secureCodeBox/hook-sdk/nodejs/hook-wrapper.js at hash-finding · avicoder/secureCodeBox · GitHub
avicoder
/
secureCodeBox
Public
forked from
secureCodeBox/secureCodeBox
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
secureCodeBox
/
hook-sdk
/
nodejs
/
hook-wrapper.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
104 lines (90 loc) · 2.65 KB
Breadcrumbs
secureCodeBox
/
hook-sdk
/
nodejs
/
hook-wrapper.js
Copy path
File metadata and controls
104 lines (90 loc) · 2.65 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const
axios
=
require
(
"axios"
)
;
const
{
handle
}
=
require
(
"./hook/hook"
)
;
const
k8s
=
require
(
"@kubernetes/client-node"
)
;
const
{
uploadFile
,
NAMESPACE
,
SCAN_NAME
,
updateScanStatus
}
=
require
(
"../../scb-sdk"
)
console
.
log
(
`Starting hook for Scan "
${
SCAN_NAME
}
"`
)
;
const
kc
=
new
k8s
.
KubeConfig
(
)
;
kc
.
loadFromCluster
(
)
;
const
k8sApi
=
kc
.
makeApiClient
(
k8s
.
CustomObjectsApi
)
;
function
downloadFile
(
url
)
{
return
axios
.
get
(
url
)
;
}
function
getRawResults
(
)
{
const
rawResultUrl
=
process
.
argv
[
2
]
;
return
downloadFile
(
rawResultUrl
)
.
then
(
(
{
data
}
)
=>
{
console
.
log
(
`Fetched raw result file contents from the file storage`
)
;
return
data
;
}
)
;
}
function
getFindings
(
)
{
const
findingsUrl
=
process
.
argv
[
3
]
;
return
downloadFile
(
findingsUrl
)
.
then
(
(
{
data
:
findings
}
)
=>
{
console
.
log
(
`Fetched
${
findings
.
length
}
findings from the file storage`
)
;
return
findings
;
}
)
;
}
function
updateRawResults
(
fileContents
)
{
const
rawResultUploadUrl
=
process
.
argv
[
4
]
;
if
(
rawResultUploadUrl
===
undefined
)
{
console
.
error
(
"Tried to upload RawResults but didn't find a valid URL to upload the findings to."
)
;
console
.
error
(
"This probably means that this hook is a ReadOnly hook."
)
;
console
.
error
(
"If you want to change RawResults you'll need to use a ReadAndWrite Hook."
)
;
}
return
uploadFile
(
rawResultUploadUrl
,
fileContents
)
;
}
async
function
updateFindings
(
findings
)
{
const
findingsUploadUrl
=
process
.
argv
[
5
]
;
if
(
findingsUploadUrl
===
undefined
)
{
console
.
error
(
"Tried to upload Findings but didn't find a valid URL to upload the findings to."
)
;
console
.
error
(
"This probably means that this hook is a ReadOnly hook."
)
;
console
.
error
(
"If you want to change Findings you'll need to use a ReadAndWrite Hook."
)
;
}
await
uploadFile
(
findingsUploadUrl
,
JSON
.
stringify
(
findings
)
)
;
// Update the scans findingStats (severities, categories, or the count) of the scan results
await
updateScanStatus
(
findings
)
;
}
async
function
main
(
)
{
let
scan
;
try
{
const
{
body
}
=
await
k8sApi
.
getNamespacedCustomObject
(
"execution.securecodebox.io"
,
"v1"
,
NAMESPACE
,
"scans"
,
SCAN_NAME
)
;
scan
=
body
;
}
catch
(
err
)
{
console
.
error
(
"Failed to get Scan from the kubernetes api"
)
;
console
.
error
(
err
)
;
process
.
exit
(
1
)
;
}
try
{
await
handle
(
{
getRawResults
,
getFindings
,
updateRawResults
,
updateFindings
,
scan
,
}
)
;
}
catch
(
error
)
{
console
.
error
(
"Error was thrown while running hooks handle function"
)
;
console
.
error
(
error
)
;
process
.
exit
(
1
)
;
}
console
.
log
(
`Hook completed`
)
;
}
main
(
)
;
Back
|
FazBrowse Home
|
New Git URL