-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
78 lines (65 loc) · 2.06 KB
/
main.go
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
package main
import (
"context"
"encoding/json"
"github.com/golang/protobuf/ptypes/empty"
"github.com/ovh/cds/contrib/grpcplugins"
"github.com/ovh/cds/sdk"
"github.com/ovh/cds/sdk/grpcplugin/actionplugin"
"io/ioutil"
)
type securityCheckerParserActionPlugin struct {
actionplugin.Common
}
func (actPlugin *securityCheckerParserActionPlugin) Manifest(ctx context.Context, _ *empty.Empty) (*actionplugin.ActionPluginManifest, error) {
return &actionplugin.ActionPluginManifest{
Name: "plugin-security-checker-parser",
Author: "Maarten de Boer <maarten@cloudstek.nl>",
Description: "This is a plugin to parse a sensiolabs/security-checker report",
Version: "1.0.0",
}, nil
}
func (actPlugin *securityCheckerParserActionPlugin) Run(ctx context.Context, q *actionplugin.ActionQuery) (*actionplugin.ActionResult, error) {
// Get file parameter
file := q.GetOptions()["file"]
if file == "" {
return actionplugin.Fail("File parameter must not be empty")
}
// Read file
b, err := ioutil.ReadFile(file)
if err != nil {
return actionplugin.Fail("Unable to read file %s: %v", file, err)
}
// Parse file
var securityCheckerResult map[string]vulnerablePackage
if err := json.Unmarshal(b, &securityCheckerResult); err != nil {
return actionplugin.Fail("Unable to read security-checker report: %v", err)
}
var report sdk.VulnerabilityWorkerReport
for n, p := range securityCheckerResult {
for _, a := range p.advisories {
v := sdk.Vulnerability{
Title: a.title,
Component: n,
CVE: a.cve,
Link: a.link,
Version: p.version,
}
report.Vulnerabilities = append(report.Vulnerabilities, v)
}
}
report.Type = "composer"
if err := grpcplugins.SendVulnerabilityReport(actPlugin.HTTPPort, report); err != nil {
return actionplugin.Fail("Unable to send report: %s", err)
}
return &actionplugin.ActionResult{
Status: sdk.StatusSuccess,
}, nil
}
func main() {
actPlugin := securityCheckerParserActionPlugin{}
if err := actionplugin.Start(context.Background(), &actPlugin); err != nil {
panic(err)
}
return
}