Skip to content

Commit 9c01afe

Browse files
committed
fixed errors
1 parent 5706a26 commit 9c01afe

File tree

7 files changed

+47
-47
lines changed

7 files changed

+47
-47
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ qualys_parser
2323
*.json
2424
test.csv
2525
real.csv
26-
real_2.csv
26+
real_2.csv

.goreleaser.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ changelog:
3636
filters:
3737
exclude:
3838
- "^docs:"
39-
- "^test:"
39+
- "^test:"

.pre-commit-config.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,5 @@ repos:
1919
- id: validate-toml
2020
- id: no-go-testing
2121
- id: golangci-lint
22-
args: [--skip-dirs=test]
23-
- id: go-critic
2422
- id: go-unit-tests
2523
- id: go-build

cmd/root.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ var rootCmd = &cobra.Command{
3232
if outputFileName == "" {
3333
outputFileName = "parsing_result.json"
3434
}
35-
hostIp, _ = cmd.Flags().GetString("host")
35+
hostIP, _ = cmd.Flags().GetString("host")
3636
listOnly, _ = cmd.Flags().GetBool("list")
3737
pkgName, _ = cmd.Flags().GetString("pkg")
38-
reportByIp, _ := cmd.Flags().GetBool("ip")
39-
if reportByIp {
38+
reportByIP, _ := cmd.Flags().GetBool("ip")
39+
if reportByIP {
4040
GetVulnerabilitiesByIP()
4141
} else {
4242
GetVulnerabilities()

cmd/vuln.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@ import (
1313

1414
var pkgName string
1515

16+
// VulnRecord is the struct containing values within a vulnerability record
1617
type 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
7677
func 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
8183
func 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
}

cmd/vulnbyip.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import (
1414
var inputFileName string
1515
var outputFileName string
1616
var detailSet bool
17-
var hostIp string
17+
var hostIP string
1818
var listOnly bool
1919

20-
// PrsRrdVulnByIp parses each record in csv and updates the dictionary
21-
func PrsRrdVulnByIp(ipDict map[string]map[string]bool, ip string, packages *[]string) {
20+
// PrsRrdVulnByIP parses each record in csv and updates the dictionary
21+
func PrsRrdVulnByIP(ipDict map[string]map[string]bool, ip string, packages *[]string) {
2222
// Check if value in Dictionary
2323
_, valueInDict := ipDict[ip]
2424
if !valueInDict {
@@ -83,13 +83,13 @@ func GetIPDictKeys(ipDict map[string]map[string]bool) []string {
8383
return ipList
8484
}
8585

86-
// WriteMapToFile write to json file given a map
86+
// WriteIPMapToFile writes to json file given a map
8787
func WriteIPMapToFile(fileName string, ipDict map[string][]string) {
8888
jsonString, _ := json.Marshal(ipDict)
89-
ioutil.WriteFile(fileName, jsonString, os.ModePerm)
89+
_ = ioutil.WriteFile(fileName, jsonString, os.ModePerm)
9090
}
9191

92-
// GetVulnerabilitiesByIP get the list of vulnerabilities for each ip
92+
// GetVulnerabilitiesByIP gets the list of vulnerabilities for each ip
9393
func GetVulnerabilitiesByIP() {
9494
ipDict := make(map[string]map[string]bool)
9595

@@ -101,27 +101,27 @@ func GetVulnerabilitiesByIP() {
101101

102102
r := csv.NewReader(f)
103103

104-
ip_order := 0
104+
ipOrder := 0
105105
for {
106106
record, err := r.Read()
107107
if err == io.EOF {
108108
break
109109
}
110110

111111
if record[0] == "IP" {
112-
ip_order += 1
112+
ipOrder++
113113
continue
114114
}
115115

116-
if ip_order == 2 {
116+
if ipOrder == 2 {
117117
// 31 is Result field
118118
packages := ParsePackage(record[31])
119-
PrsRrdVulnByIp(ipDict, record[0], &packages)
119+
PrsRrdVulnByIP(ipDict, record[0], &packages)
120120
}
121121
}
122122

123123
convertedDict := convertDict(ipDict)
124-
if hostIp == "" {
124+
if hostIP == "" {
125125
if listOnly {
126126
ipDictKeys := GetIPDictKeys(ipDict)
127127
fmt.Printf("The IPs with vulnerable packages:\n")
@@ -131,11 +131,11 @@ func GetVulnerabilitiesByIP() {
131131
WriteIPMapToFile(outputFileName, convertedDict)
132132
}
133133
} else {
134-
if len(convertedDict[hostIp]) == 0 {
135-
fmt.Printf("The vulnerable package(s) found for the host %s cannot be found!\n", hostIp)
134+
if len(convertedDict[hostIP]) == 0 {
135+
fmt.Printf("The vulnerable package(s) found for the host %s cannot be found!\n", hostIP)
136136
} else {
137-
fmt.Printf("The vulnerable package(s) found for the host %s are:\n", hostIp)
138-
fmt.Println(strings.Join(convertedDict[hostIp], "\n"))
137+
fmt.Printf("The vulnerable package(s) found for the host %s are:\n", hostIP)
138+
fmt.Println(strings.Join(convertedDict[hostIP], "\n"))
139139
}
140140
}
141141
}

0 commit comments

Comments
 (0)