Skip to content

Commit

Permalink
Use gorm connection pool
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfont committed Jul 4, 2021
1 parent d4b27fd commit ecf258f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
7 changes: 1 addition & 6 deletions acls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
14 changes: 2 additions & 12 deletions acls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit ecf258f

Please sign in to comment.