Skip to content

Commit c5ae22c

Browse files
committed
Fix some linting issues
1 parent b7942a4 commit c5ae22c

15 files changed

+718
-182
lines changed

check/checker.go

+6
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,32 @@ type DomainReport struct {
4141

4242
func (r *Report) scanError(check, ns, ip, domain string, results []dns.RR, err error) bool {
4343
fail := false
44+
4445
if err != nil {
4546
if !strings.Contains(err.Error(), "NXDOMAIN") && !strings.Contains(err.Error(), "no rr for") {
4647
r.Result = append(r.Result, ReportResult{Result: fmt.Sprintf("ERR : %s failed on %s (%s) for domain (%s): %s", check, ns, ip, domain, err)})
4748
}
49+
4850
fail = true
4951
}
52+
5053
if len(results) == 0 && err == nil {
5154
// r.Result = append(r.Result, ReportResult{Result: fmt.Sprintf("ERR : %s failed on %s (%s): %s", check, ns, ip, "no records found")})
5255
fail = true
5356
}
57+
5458
return fail
5559
}
5660

5761
func (r Report) String() string {
5862
var sb strings.Builder
63+
5964
for _, res := range r.Result {
6065
for _, record := range res.Records {
6166
sb.WriteString(record)
6267
sb.WriteString("\n")
6368
}
6469
}
70+
6571
return sb.String()
6672
}

check/dnssec.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,48 @@ func NewDNSSEC(s *scan.Scan, ns []structs.NSData) *DNSSECCheck {
2424
s: s,
2525
NS: ns,
2626
}
27+
2728
return c
2829
}
2930

3031
func (c *DNSSECCheck) Scan(domain string) {
3132
log.Debugf("DNSSEC: scan")
3233
defer log.Debugf("DNSSEC: scan exit")
34+
3335
_, err := c.s.ValidateChain(domain)
3436
if err != nil {
3537
c.DNSSEC = append(c.DNSSEC, DNSSECCheckData{Error: err.Error()})
3638
return
3739
}
40+
3841
c.DNSSEC = append(c.DNSSEC, DNSSECCheckData{Valid: true})
3942
}
4043

4144
func (c *DNSSECCheck) Values() []ReportResult {
4245
var results []ReportResult
46+
4347
for _, res := range c.DNSSEC {
4448
if res.Valid {
45-
results = append(results, ReportResult{Result: "OK : DNSKEY validated. Chain validated",
46-
Status: true, Name: "DNSSEC"})
49+
results = append(results, ReportResult{
50+
Result: "OK : DNSKEY validated. Chain validated",
51+
Status: true, Name: "DNSSEC",
52+
})
4753
} else {
48-
results = append(results, ReportResult{Result: "FAIL: " + res.Error,
49-
Status: false, Name: "DNSSEC"})
54+
results = append(results, ReportResult{
55+
Result: "FAIL: " + res.Error,
56+
Status: false, Name: "DNSSEC",
57+
})
5058
}
5159
}
60+
5261
return results
5362
}
5463

5564
func (c *DNSSECCheck) CreateReport(domain string) Report {
5665
c.Scan(domain)
66+
5767
c.Report.Type = "DNSSEC"
5868
c.Report.Result = append(c.Report.Result, c.Values()...)
69+
5970
return c.Report
6071
}

check/glue.go

+35-3
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,21 @@ func NewGlue(s *scan.Scan, ns []structs.NSData) *Glue {
2020
s: s,
2121
NS: ns,
2222
}
23+
2324
return g
2425
}
2526

2627
func (g *Glue) Scan(domain string) {
27-
2828
}
2929

3030
func (g *Glue) CheckParent(domain string) (bool, []string, error) {
3131
parentGlue, err := g.getParentGlue(domain)
3232
if err != nil {
3333
return false, []string{}, err
3434
}
35+
3536
ok, res := g.Compare(parentGlue)
37+
3638
return ok, res, nil
3739
}
3840

@@ -41,99 +43,129 @@ func (g *Glue) CheckSelf(domain string) (bool, []string, error) {
4143
if err != nil {
4244
return false, []string{}, err
4345
}
46+
4447
ok, res := g.Compare(selfGlue)
48+
4549
return ok, res, nil
4650
}
4751

4852
func (g *Glue) CreateReport(domain string) Report {
4953
res := ReportResult{}
5054
rep := Report{}
51-
var missed []string
52-
var err error
55+
56+
var (
57+
missed []string
58+
err error
59+
)
60+
5361
res.Status, missed, err = g.CheckParent(domain)
62+
5463
res.Name = "Parent"
5564
if err != nil {
5665
res.Error = err.Error()
5766
}
67+
5868
if !res.Status {
5969
res.Result = fmt.Sprintf("WARN: no glue records found for %s in NS of parent %s", missed, dns.Fqdn(getParentDomain(domain)))
6070
res.Name = "Parent"
6171
}
72+
6273
if res.Error != "" {
6374
res.Result = fmt.Sprintf("ERR : CheckParentGlue test failed: %s", res.Error)
6475
}
76+
6577
rep.Result = append(rep.Result, res)
6678
res = ReportResult{Result: fmt.Sprintf("OK : glue records found for all nameservers in NS record of %s", dns.Fqdn(domain))}
6779
res.Status, missed, err = g.CheckSelf(domain)
6880
res.Name = "Self"
81+
6982
if !res.Status {
7083
res.Result = fmt.Sprintf("WARN: no glue records found for %s in NS of %s", missed, dns.Fqdn(domain))
7184
res.Name = "Self"
7285
}
86+
7387
if err != nil {
7488
res.Error = err.Error()
7589
}
90+
7691
if res.Error != "" {
7792
res.Result = fmt.Sprintf("ERR : CheckSelfGlue test failed: %s", res.Error)
7893
}
94+
7995
rep.Result = append(rep.Result, res)
8096
rep.Type = "GLUE"
8197
g.Report = rep
98+
8299
return rep
83100
}
84101

85102
func (g *Glue) Compare(parentGlue []net.IP) (bool, []string) {
86103
var NSips []net.IP
104+
87105
for _, data := range g.NS {
88106
NSips = append(NSips, data.IP...)
89107
}
90108

91109
m := make(map[string]bool)
110+
92111
var ips []string
112+
93113
for _, ip := range NSips {
94114
m[ip.String()] = false
95115
}
116+
96117
for _, ip := range parentGlue {
97118
m[ip.String()] = true
98119
}
120+
99121
for k, v := range m {
100122
if !v {
101123
ips = append(ips, k)
102124
}
103125
}
126+
104127
if len(ips) == 0 {
105128
return true, ips
106129
}
130+
107131
return false, ips
108132
}
109133

110134
func (g *Glue) getParentGlue(domain string) ([]net.IP, error) {
111135
// TODO ask every parent
112136
log.Debugf("Finding NS of parent: %s", dns.Fqdn(getParentDomain(domain)))
137+
113138
var ips []net.IP
139+
114140
nsdata, err := g.s.FindNS(getParentDomain(domain))
115141
if err != nil {
116142
return ips, err
117143
}
118144
// asking parent about NS
119145
log.Debugf("Asking parent %s (%s) NS of %s", nsdata[0].Info[0].IP.String(), getParentDomain(domain), domain)
146+
120147
return g.getGlueIPs(domain, nsdata[0].Info[0].IP.String())
121148
}
122149

123150
func (g *Glue) getSelfGlue(domain string) ([]net.IP, error) {
124151
// TODO all NS
125152
log.Debugf("Asking self %s (%s) NS of %s", g.NS[0].IP[0].String(), domain, domain)
153+
126154
return g.getGlueIPs(domain, g.NS[0].IP[0].String())
127155
}
128156

129157
func (g *Glue) getGlueIPs(domain string, server string) ([]net.IP, error) {
130158
log.Debugf("GLUE: getGlueIPs")
131159
defer log.Debugf("GLUE: getGlueIPs exit")
160+
132161
var ips []net.IP
162+
133163
res, err := scan.Query(domain, dns.TypeNS, server, true)
134164
if err != nil {
135165
return ips, err
136166
}
167+
137168
rrset := extractRR(res.Msg.Extra, dns.TypeA, dns.TypeAAAA)
169+
138170
return extractIP(rrset), nil
139171
}

0 commit comments

Comments
 (0)