@@ -13,17 +13,18 @@ import (
1313
1414var pkgName string
1515
16+ // VulnRecord is the struct containing values within a vulnerability record
1617type VulnRecord struct {
1718 CveTitle string `json:"csv_title"`
1819 Severity string `json:"severity"`
1920 Solution string `json:"solution"`
2021 Count int `json:"count"`
21- IpList []string `json:"ip_list"`
22+ IPList []string `json:"ip_list"`
2223}
2324
24- // CheckIfIpExist checks if ip exists in a slice
25- func CheckIfIpExist (ip string , IpList []string ) bool {
26- for _ , value := range IpList {
25+ // CheckIfIPExist checks if ip exists in a slice
26+ func CheckIfIPExist (ip string , IPList []string ) bool {
27+ for _ , value := range IPList {
2728 if value == ip {
2829 return true
2930 }
@@ -43,21 +44,21 @@ func PrsRrdVuln(vulnDict map[string]VulnRecord, record []string, severityMap map
4344 Severity : severityMap [record [11 ]],
4445 Solution : record [28 ],
4546 Count : 1 ,
46- IpList : []string {record [0 ]},
47+ IPList : []string {record [0 ]},
4748 }
4849 }
4950
5051 // Check if the ip is in the list of ips belonging to the vuln record
51- if ! CheckIfIpExist (record [0 ], vulnDict [pkg ].IpList ) {
52- newIPList := append (vulnDict [pkg ].IpList , record [0 ])
52+ if ! CheckIfIPExist (record [0 ], vulnDict [pkg ].IPList ) {
53+ newIPList := append (vulnDict [pkg ].IPList , record [0 ])
5354 newCount := vulnDict [pkg ].Count + 1
5455
5556 vulnDict [pkg ] = VulnRecord {
5657 CveTitle : vulnDict [pkg ].CveTitle ,
5758 Severity : vulnDict [pkg ].Severity ,
5859 Solution : vulnDict [pkg ].Solution ,
5960 Count : newCount ,
60- IpList : newIPList ,
61+ IPList : newIPList ,
6162 }
6263 }
6364 }
@@ -72,12 +73,13 @@ func GetVulnDictKeys(vulnDict map[string]VulnRecord) []string {
7273 return vulnList
7374}
7475
75- // WriteMapToFile write to json file given a map
76+ // WriteVulnMapToFile write to json file given a map
7677func WriteVulnMapToFile (fileName string , ipDict map [string ]VulnRecord ) {
7778 jsonString , _ := json .Marshal (ipDict )
78- ioutil .WriteFile (fileName , jsonString , os .ModePerm )
79+ _ = ioutil .WriteFile (fileName , jsonString , os .ModePerm )
7980}
8081
82+ // GetVulnerabilities parses input report
8183func GetVulnerabilities () {
8284 vulnDict := make (map [string ]VulnRecord )
8385 severityMap := map [string ]string {
@@ -96,19 +98,19 @@ func GetVulnerabilities() {
9698
9799 r := csv .NewReader (f )
98100
99- ip_order := 0
101+ ipOrder := 0
100102 for {
101103 record , err := r .Read ()
102104 if err == io .EOF {
103105 break
104106 }
105107
106108 if record [0 ] == "IP" {
107- ip_order += 1
109+ ipOrder ++
108110 continue
109111 }
110112
111- if ip_order == 2 {
113+ if ipOrder == 2 {
112114 PrsRrdVuln (vulnDict , record , severityMap )
113115 }
114116 }
@@ -126,11 +128,11 @@ func GetVulnerabilities() {
126128
127129 } else {
128130 _ , valueInDict := vulnDict [pkgName ]
129- if len (vulnDict [pkgName ].IpList ) == 0 || ! valueInDict {
131+ if len (vulnDict [pkgName ].IPList ) == 0 || ! valueInDict {
130132 fmt .Printf ("The ip(s) for the package %s cannot be found!\n " , pkgName )
131133 } else {
132134 fmt .Printf ("The ip(s) found for the package %s are:\n " , pkgName )
133- fmt .Println (strings .Join (vulnDict [pkgName ].IpList , "\n " ))
135+ fmt .Println (strings .Join (vulnDict [pkgName ].IPList , "\n " ))
134136 }
135137 }
136138}
0 commit comments