From 6ab3c009c7b11d37230abfda5d631e6e3232805b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Serv=C3=A9n=20Mar=C3=ADn?= Date: Thu, 5 May 2022 11:16:20 +0200 Subject: [PATCH] cmd,pkg: fix lint warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lucas Servén Marín --- cmd/kgctl/connect_linux.go | 2 -- pkg/mesh/mesh.go | 4 +++- pkg/mesh/topology_test.go | 5 ----- pkg/wireguard/conf.go | 14 ++++---------- 4 files changed, 7 insertions(+), 18 deletions(-) diff --git a/cmd/kgctl/connect_linux.go b/cmd/kgctl/connect_linux.go index 42496fc..5bb5014 100644 --- a/cmd/kgctl/connect_linux.go +++ b/cmd/kgctl/connect_linux.go @@ -276,8 +276,6 @@ func cleanUp(iface int, t *route.Table, logger log.Logger) { if err := t.CleanUp(); err != nil { level.Error(logger).Log("failed to clean up routes: %v", err) } - - return } func sync(table *route.Table, peerName string, privateKey wgtypes.Key, iface int, logger log.Logger) error { diff --git a/pkg/mesh/mesh.go b/pkg/mesh/mesh.go index bc9b43d..bc684bd 100644 --- a/pkg/mesh/mesh.go +++ b/pkg/mesh/mesh.go @@ -61,7 +61,6 @@ type Mesh struct { ipTables *iptables.Controller kiloIface int kiloIfaceName string - key []byte local bool port int priv wgtypes.Key @@ -94,6 +93,9 @@ func New(backend Backend, enc encapsulation.Encapsulator, granularity Granularit return nil, fmt.Errorf("failed to create directory to store configuration: %v", err) } privateB, err := ioutil.ReadFile(privateKeyPath) + if err != nil && !os.IsNotExist(err) { + return nil, fmt.Errorf("failed to read private key file: %v", err) + } privateB = bytes.Trim(privateB, "\n") private, err := wgtypes.ParseKey(string(privateB)) if err != nil { diff --git a/pkg/mesh/topology_test.go b/pkg/mesh/topology_test.go index 9b0b8a8..2f83fca 100644 --- a/pkg/mesh/topology_test.go +++ b/pkg/mesh/topology_test.go @@ -16,7 +16,6 @@ package mesh import ( "net" - "strings" "testing" "time" @@ -27,10 +26,6 @@ import ( "github.com/squat/kilo/pkg/wireguard" ) -func allowedIPs(ips ...string) string { - return strings.Join(ips, ", ") -} - func mustParseCIDR(s string) (r net.IPNet) { if _, ip, err := net.ParseCIDR(s); err != nil { panic("failed to parse CIDR") diff --git a/pkg/wireguard/conf.go b/pkg/wireguard/conf.go index 8dbcde4..601fea4 100644 --- a/pkg/wireguard/conf.go +++ b/pkg/wireguard/conf.go @@ -183,7 +183,7 @@ func (e *Endpoint) Resolved() bool { // UDPAddr() will not try to resolve a DN name, if the Endpoint is not yet resolved. func (e *Endpoint) UDPAddr(resolve bool) (*net.UDPAddr, error) { if !e.Ready() { - return nil, errors.New("Enpoint is not ready") + return nil, errors.New("endpoint is not ready") } if e.udpAddr != nil { // Make a copy of the UDPAddr to protect it from modification outside this package. @@ -191,7 +191,7 @@ func (e *Endpoint) UDPAddr(resolve bool) (*net.UDPAddr, error) { return &h, nil } if !resolve { - return nil, errors.New("Endpoint is not resolved") + return nil, errors.New("endpoint is not resolved") } var err error if e.udpAddr, err = net.ResolveUDPAddr("udp", e.addr); err != nil { @@ -358,19 +358,13 @@ func (c *Conf) Equal(d *wgtypes.Device) (bool, string) { func sortPeerConfigs(peers []wgtypes.Peer) { sort.Slice(peers, func(i, j int) bool { - if peers[i].PublicKey.String() < peers[j].PublicKey.String() { - return true - } - return false + return peers[i].PublicKey.String() < peers[j].PublicKey.String() }) } func sortPeers(peers []Peer) { sort.Slice(peers, func(i, j int) bool { - if peers[i].PublicKey.String() < peers[j].PublicKey.String() { - return true - } - return false + return peers[i].PublicKey.String() < peers[j].PublicKey.String() }) }