From ecf258f995bab51c008cc900a6ed0058502de2f2 Mon Sep 17 00:00:00 2001 From: Juan Font Alonso Date: Sun, 4 Jul 2021 21:56:13 +0200 Subject: [PATCH] Use gorm connection pool --- acls.go | 7 +------ acls_test.go | 14 ++------------ 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/acls.go b/acls.go index 90020a64..f4ed4c0e 100644 --- a/acls.go +++ b/acls.go @@ -166,13 +166,8 @@ func (h *Headscale) expandAlias(s string) (*[]string, error) { // This will have HORRIBLE performance. // We need to change the data model to better store tags - db, err := h.db() - if err != nil { - log.Printf("Cannot open DB: %s", err) - return nil, err - } machines := []Machine{} - if err = db.Where("registered").Find(&machines).Error; err != nil { + if err := h.db.Where("registered").Find(&machines).Error; err != nil { return nil, err } ips := []string{} diff --git a/acls_test.go b/acls_test.go index 379b0061..dc5b4b31 100644 --- a/acls_test.go +++ b/acls_test.go @@ -86,11 +86,6 @@ func (s *Suite) TestPortNamespace(c *check.C) { pak, err := h.CreatePreAuthKey(n.Name, false, false, nil) c.Assert(err, check.IsNil) - db, err := h.db() - if err != nil { - c.Fatal(err) - } - _, err = h.GetMachine("testnamespace", "testmachine") c.Assert(err, check.NotNil) ip, _ := h.getAvailableIP() @@ -106,7 +101,7 @@ func (s *Suite) TestPortNamespace(c *check.C) { IPAddress: ip.String(), AuthKeyID: uint(pak.ID), } - db.Save(&m) + h.db.Save(&m) err = h.LoadACLPolicy("./tests/acls/acl_policy_basic_namespace_as_user.hujson") c.Assert(err, check.IsNil) @@ -131,11 +126,6 @@ func (s *Suite) TestPortGroup(c *check.C) { pak, err := h.CreatePreAuthKey(n.Name, false, false, nil) c.Assert(err, check.IsNil) - db, err := h.db() - if err != nil { - c.Fatal(err) - } - _, err = h.GetMachine("testnamespace", "testmachine") c.Assert(err, check.NotNil) ip, _ := h.getAvailableIP() @@ -151,7 +141,7 @@ func (s *Suite) TestPortGroup(c *check.C) { IPAddress: ip.String(), AuthKeyID: uint(pak.ID), } - db.Save(&m) + h.db.Save(&m) err = h.LoadACLPolicy("./tests/acls/acl_policy_basic_groups.hujson") c.Assert(err, check.IsNil)