/
dougcve.go
94 lines (75 loc) · 1.61 KB
/
dougcve.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package cve
import (
"encoding/json"
"strconv"
"gopkg.in/yaml.v2"
)
// DougCVE Simplified Doug CVE Format
type DougCVE struct {
Cve string `json:"cve,omitempty" xml:"cve"`
Product string `json:"product,omitempty"`
Score float64 `json:"score,omitempty"`
Arista string `json:"arista,omitempty"`
Aruba string `json:"aruba,omitempty"`
Hp string `json:"hp,omitempty"`
Ios string `json:"ios,omitempty"`
IosXe string `json:"ios_xe,omitempty"`
IosXr string `json:"ios_xr,omitempty"`
Junos string `json:"junos,omitempty"`
NxOs string `json:"nx_os,omitempty"`
Platform string `json:"platform,omitempty"`
}
// SetFromMap Set attributes from a map.
func (c *DougCVE) SetFromMap(m map[string]string) {
if m["cve"] != "" {
c.Cve = m["cve"]
}
if m["product"] != "" {
c.Product = m["product"]
}
if m["arista"] != "" {
c.Arista = m["arista"]
}
if m["aruba"] != "" {
c.Aruba = m["aruba"]
}
if m["hp"] != "" {
c.Hp = m["hp"]
}
if m["ios"] != "" {
c.Ios = m["ios"]
}
if m["iosxe"] != "" {
c.IosXe = m["iosxe"]
}
if m["iosxr"] != "" {
c.IosXr = m["iosxr"]
}
if m["junos"] != "" {
c.Junos = m["junos"]
}
if m["nxos"] != "" {
c.NxOs = m["nxos"]
}
if m["platform"] != "" {
c.Platform = m["platform"]
}
if m["score"] != "" {
c.Score, _ = strconv.ParseFloat(m["score"], 32)
}
}
// YamlString ...
func (c *DougCVE) YamlString() string {
pjson, err := yaml.Marshal(c)
if err != nil {
panic(err)
}
return string(pjson)
}
func (c *DougCVE) String() string {
pjson, err := json.Marshal(c)
if err != nil {
panic(err)
}
return string(pjson)
}