From cd6a63fc576f0f7959646d845e5741456bd77134 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Mon, 8 Mar 2021 14:49:44 +0100 Subject: [PATCH] Fix go vet issues --- checker/checker.go | 2 +- token-validator/check.go | 2 +- token-validator/domain.go | 16 ++++++++-------- token-validator/ip.go | 6 +++--- token-validator/students.go | 2 +- token-validator/wg.go | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/checker/checker.go b/checker/checker.go index 5d510aa..b6b3e5c 100644 --- a/checker/checker.go +++ b/checker/checker.go @@ -207,7 +207,7 @@ func check_matrix(domain string) (version string, err error) { version = federationTest.Version.Name + " " + federationTest.Version.Version return version, nil } else if err = json.NewDecoder(resp.Body).Decode(&federationTest); err != nil { - log.Printf("Error in chech_matrix, when decoding json:", err.Error()) + log.Printf("Error in chech_matrix, when decoding json: %w", err.Error()) return "", fmt.Errorf("Sorry, the federation tester is broken. Check on https://federationtester.matrix.org/#%s", domain) } else if federationTest.DNSResult.SRVError != nil && federationTest.WellKnownResult.Result != "" { return "", fmt.Errorf("%s OR %s", federationTest.DNSResult.SRVError.Message, federationTest.WellKnownResult.Result) diff --git a/token-validator/check.go b/token-validator/check.go index 722e54f..c9e0ddc 100644 --- a/token-validator/check.go +++ b/token-validator/check.go @@ -29,7 +29,7 @@ func init() { } func check_GLUE_respond(student *adlin.Student, domain string, ip string) (err error) { if !strings.HasPrefix(ip, adlin.StudentIP(student.Id).String()) { - return fmt.Errorf("%q is not your IP range") + return fmt.Errorf("%q is not your IP range", ip) } client := dns.Client{Net: "tcp", Timeout: time.Second * 5} diff --git a/token-validator/domain.go b/token-validator/domain.go index 596f3bd..38c9cd8 100644 --- a/token-validator/domain.go +++ b/token-validator/domain.go @@ -260,7 +260,7 @@ func delAssociatedDomains(student *adlin.Student, dn string) (err error) { m1.Id = dns.Id() m1.Opcode = dns.OpcodeUpdate m1.Question = make([]dns.Question, 1) - m1.Question[0] = dns.Question{adlin.AssociatedDomainSuffix, dns.TypeSOA, dns.ClassINET} + m1.Question[0] = dns.Question{Name: adlin.AssociatedDomainSuffix, Qtype: dns.TypeSOA, Qclass: dns.ClassINET} var rrs []dns.RR for _, domain := range adomains { @@ -302,7 +302,7 @@ func AddAssociatedDomains(student *adlin.Student, aaaa net.IP) (err error) { m2.Id = dns.Id() m2.Opcode = dns.OpcodeUpdate m2.Question = make([]dns.Question, 1) - m2.Question[0] = dns.Question{adlin.AssociatedDomainSuffix, dns.TypeSOA, dns.ClassINET} + m2.Question[0] = dns.Question{Name: adlin.AssociatedDomainSuffix, Qtype: dns.TypeSOA, Qclass: dns.ClassINET} rrA := new(dns.A) rrA.Hdr = dns.RR_Header{Name: student.DefaultAssociatedDomain(), Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 3600} @@ -354,7 +354,7 @@ func AddNSDelegatedDomain(student *adlin.Student, dn string, ttl uint32, ns stri m1.Id = dns.Id() m1.Opcode = dns.OpcodeUpdate m1.Question = make([]dns.Question, 1) - m1.Question[0] = dns.Question{adlin.DelegatedDomainSuffix, dns.TypeSOA, dns.ClassINET} + m1.Question[0] = dns.Question{Name: adlin.DelegatedDomainSuffix, Qtype: dns.TypeSOA, Qclass: dns.ClassINET} rrNS := new(dns.NS) rrNS.Hdr = dns.RR_Header{Name: d, Rrtype: dns.TypeNS, Class: dns.ClassINET, Ttl: ttl} @@ -377,7 +377,7 @@ func UpdateNSDelegatedDomain(student *adlin.Student, dn string, ttl uint32, oldn m1.Id = dns.Id() m1.Opcode = dns.OpcodeUpdate m1.Question = make([]dns.Question, 1) - m1.Question[0] = dns.Question{adlin.DelegatedDomainSuffix, dns.TypeSOA, dns.ClassINET} + m1.Question[0] = dns.Question{Name: adlin.DelegatedDomainSuffix, Qtype: dns.TypeSOA, Qclass: dns.ClassINET} rrOldNS := new(dns.NS) rrOldNS.Hdr = dns.RR_Header{Name: d, Rrtype: dns.TypeNS, Class: dns.ClassINET} @@ -417,7 +417,7 @@ func AddGLUEDelegatedDomain(student *adlin.Student, dn string, ttl uint32, aaaa m1.Id = dns.Id() m1.Opcode = dns.OpcodeUpdate m1.Question = make([]dns.Question, 1) - m1.Question[0] = dns.Question{adlin.DelegatedDomainSuffix, dns.TypeSOA, dns.ClassINET} + m1.Question[0] = dns.Question{Name: adlin.DelegatedDomainSuffix, Qtype: dns.TypeSOA, Qclass: dns.ClassINET} var rr dns.RR rr, err = dns.NewRR(fmt.Sprintf("%s %d IN AAAA %s", dn, ttl, aaaa)) @@ -453,7 +453,7 @@ func UpdateGLUEDelegatedDomain(student *adlin.Student, dn string, ttl uint32, ol m1.Id = dns.Id() m1.Opcode = dns.OpcodeUpdate m1.Question = make([]dns.Question, 1) - m1.Question[0] = dns.Question{adlin.DelegatedDomainSuffix, dns.TypeSOA, dns.ClassINET} + m1.Question[0] = dns.Question{Name: adlin.DelegatedDomainSuffix, Qtype: dns.TypeSOA, Qclass: dns.ClassINET} var rr dns.RR @@ -509,7 +509,7 @@ func AddDSDelegatedDomain(student *adlin.Student, dn string, ttl uint32, rdata s m1.Id = dns.Id() m1.Opcode = dns.OpcodeUpdate m1.Question = make([]dns.Question, 1) - m1.Question[0] = dns.Question{adlin.DelegatedDomainSuffix, dns.TypeSOA, dns.ClassINET} + m1.Question[0] = dns.Question{Name: adlin.DelegatedDomainSuffix, Qtype: dns.TypeSOA, Qclass: dns.ClassINET} var ds *dns.DS ds = dnskey.ToDS(dns.SHA256) @@ -545,7 +545,7 @@ func DeleteRRDelegatedDomain(student *adlin.Student, dn string, rr string, value m1.Id = dns.Id() m1.Opcode = dns.OpcodeUpdate m1.Question = make([]dns.Question, 1) - m1.Question[0] = dns.Question{adlin.DelegatedDomainSuffix, dns.TypeSOA, dns.ClassINET} + m1.Question[0] = dns.Question{Name: adlin.DelegatedDomainSuffix, Qtype: dns.TypeSOA, Qclass: dns.ClassINET} rrr, errr := dns.NewRR(fmt.Sprintf("%s %s %s", dn, rr, strings.Join(values, " "))) if errr != nil { diff --git a/token-validator/ip.go b/token-validator/ip.go index 885cd0f..0a6e490 100644 --- a/token-validator/ip.go +++ b/token-validator/ip.go @@ -69,9 +69,9 @@ func GetStudentTunnelIPs(student *adlin.Student) (ips []string) { func getStudentIPs(student *adlin.Student) (r map[string]string) { r = make(map[string]string) - r["vlan0"] = IPSuffix(student, net.IPNet{net.ParseIP("172.23.0.0"), net.CIDRMask(17, 32)}).String() - r["wg0"] = IPSuffix(student, net.IPNet{net.ParseIP("172.17.0.0"), net.CIDRMask(16, 32)}).String() - r["vlan7"] = IPSuffix(student, net.IPNet{net.ParseIP("172.23.142.0"), net.CIDRMask(23, 32)}).String() + r["vlan0"] = IPSuffix(student, net.IPNet{IP: net.ParseIP("172.23.0.0"), Mask: net.CIDRMask(17, 32)}).String() + r["wg0"] = IPSuffix(student, net.IPNet{IP: net.ParseIP("172.17.0.0"), Mask: net.CIDRMask(16, 32)}).String() + r["vlan7"] = IPSuffix(student, net.IPNet{IP: net.ParseIP("172.23.142.0"), Mask: net.CIDRMask(23, 32)}).String() for d, ip := range GetStudentTunnelIPs(student) { key := "wg" diff --git a/token-validator/students.go b/token-validator/students.go index cee1e47..c8e7270 100644 --- a/token-validator/students.go +++ b/token-validator/students.go @@ -104,7 +104,7 @@ func createStudent(_ httprouter.Params, body []byte) (interface{}, error) { } exist.RegisterAccess(std.IP, std.MAC) - ip := IPSuffix(exist, net.IPNet{net.ParseIP("172.23.0.0"), net.CIDRMask(17, 32)}).String() + ip := IPSuffix(exist, net.IPNet{IP: net.ParseIP("172.23.0.0"), Mask: net.CIDRMask(17, 32)}).String() exist.IP = &ip return exist, nil diff --git a/token-validator/wg.go b/token-validator/wg.go index 195a3f7..e80544b 100644 --- a/token-validator/wg.go +++ b/token-validator/wg.go @@ -111,7 +111,7 @@ func getWgTunnelInfo(w http.ResponseWriter, r *http.Request, ps httprouter.Param pt.PubKey, _ = base64.StdEncoding.DecodeString(pubkey) version = 3 } else { - http.Error(w, fmt.Sprintf("{errmsg:\"No public key given\"}", err), http.StatusBadRequest) + http.Error(w, fmt.Sprintf("{errmsg:\"No public key given\"}"), http.StatusBadRequest) return }