Skip to content

Commit e0d916b

Browse files
committed
Remove dependency on postgres' jsonb
1 parent e7a626d commit e0d916b

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

api.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111

1212
"github.com/gin-gonic/gin"
1313
"github.com/jinzhu/gorm"
14-
"github.com/jinzhu/gorm/dialects/postgres"
1514
"github.com/klauspost/compress/zstd"
15+
"gorm.io/datatypes"
1616
"inet.af/netaddr"
1717
"tailscale.com/tailcfg"
1818
"tailscale.com/wgengine/wgcfg"
@@ -40,7 +40,7 @@ func (h *Headscale) RegisterWebAPI(c *gin.Context) {
4040
<body>
4141
<h1>headscale</h1>
4242
<p>
43-
Run the command below on the headscale server to add this machine to your network:
43+
Run the command below in the headscale server to add this machine to your network:
4444
</p>
4545
4646
<p>
@@ -174,13 +174,13 @@ func (h *Headscale) PollNetMapHandler(c *gin.Context) {
174174
defer db.Close()
175175
var m Machine
176176
if db.First(&m, "machine_key = ?", mKey.HexString()).RecordNotFound() {
177-
log.Printf("Cannot find machine: %s", err)
177+
log.Printf("Cannot fingitd machine: %s", err)
178178
return
179179
}
180180

181181
hostinfo, _ := json.Marshal(req.Hostinfo)
182182
m.Name = req.Hostinfo.Hostname
183-
m.HostInfo = postgres.Jsonb{RawMessage: json.RawMessage(hostinfo)}
183+
m.HostInfo = datatypes.JSON(hostinfo)
184184
m.DiscoKey = wgcfg.Key(req.DiscoKey).HexString()
185185
now := time.Now().UTC()
186186

@@ -194,7 +194,7 @@ func (h *Headscale) PollNetMapHandler(c *gin.Context) {
194194
// before their first real endpoint update.
195195
if !req.ReadOnly {
196196
endpoints, _ := json.Marshal(req.Endpoints)
197-
m.Endpoints = postgres.Jsonb{RawMessage: json.RawMessage(endpoints)}
197+
m.Endpoints = datatypes.JSON(endpoints)
198198
m.LastSeen = &now
199199
}
200200
db.Save(&m)

machine.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strconv"
99
"time"
1010

11-
"github.com/jinzhu/gorm/dialects/postgres"
11+
"gorm.io/datatypes"
1212
"inet.af/netaddr"
1313
"tailscale.com/tailcfg"
1414
"tailscale.com/wgengine/wgcfg"
@@ -33,9 +33,9 @@ type Machine struct {
3333
LastSeen *time.Time
3434
Expiry *time.Time
3535

36-
HostInfo postgres.Jsonb
37-
Endpoints postgres.Jsonb
38-
EnabledRoutes postgres.Jsonb
36+
HostInfo datatypes.JSON
37+
Endpoints datatypes.JSON
38+
EnabledRoutes datatypes.JSON
3939

4040
CreatedAt time.Time
4141
UpdatedAt time.Time
@@ -79,7 +79,7 @@ func (m Machine) toNode() (*tailcfg.Node, error) {
7979
allowedIPs = append(allowedIPs, ip) // we append the node own IP, as it is required by the clients
8080

8181
routesStr := []string{}
82-
if len(m.EnabledRoutes.RawMessage) != 0 {
82+
if len(m.EnabledRoutes) != 0 {
8383
allwIps, err := m.EnabledRoutes.MarshalJSON()
8484
if err != nil {
8585
return nil, err
@@ -99,7 +99,7 @@ func (m Machine) toNode() (*tailcfg.Node, error) {
9999
}
100100

101101
endpoints := []string{}
102-
if len(m.Endpoints.RawMessage) != 0 {
102+
if len(m.Endpoints) != 0 {
103103
be, err := m.Endpoints.MarshalJSON()
104104
if err != nil {
105105
return nil, err
@@ -111,7 +111,7 @@ func (m Machine) toNode() (*tailcfg.Node, error) {
111111
}
112112

113113
hostinfo := tailcfg.Hostinfo{}
114-
if len(m.HostInfo.RawMessage) != 0 {
114+
if len(m.HostInfo) != 0 {
115115
hi, err := m.HostInfo.MarshalJSON()
116116
if err != nil {
117117
return nil, err
@@ -198,7 +198,7 @@ func (h *Headscale) GetMachine(namespace string, name string) (*Machine, error)
198198
// GetHostInfo returns a Hostinfo struct for the machine
199199
func (m *Machine) GetHostInfo() (*tailcfg.Hostinfo, error) {
200200
hostinfo := tailcfg.Hostinfo{}
201-
if len(m.HostInfo.RawMessage) != 0 {
201+
if len(m.HostInfo) != 0 {
202202
hi, err := m.HostInfo.MarshalJSON()
203203
if err != nil {
204204
return nil, err

routes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"errors"
66
"log"
77

8-
"github.com/jinzhu/gorm/dialects/postgres"
8+
"gorm.io/datatypes"
99
"inet.af/netaddr"
1010
)
1111

@@ -49,7 +49,7 @@ func (h *Headscale) EnableNodeRoute(namespace string, nodeName string, routeStr
4949
}
5050

5151
routes, _ := json.Marshal([]string{routeStr}) // TODO: only one for the time being, so overwriting the rest
52-
m.EnabledRoutes = postgres.Jsonb{RawMessage: json.RawMessage(routes)}
52+
m.EnabledRoutes = datatypes.JSON(routes)
5353
db.Save(&m)
5454
db.Close()
5555

routes_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package headscale
33
import (
44
"encoding/json"
55

6-
"github.com/jinzhu/gorm/dialects/postgres"
76
"gopkg.in/check.v1"
7+
"gorm.io/datatypes"
88
"inet.af/netaddr"
99
"tailscale.com/tailcfg"
1010
)
@@ -46,7 +46,7 @@ func (s *Suite) TestGetRoutes(c *check.C) {
4646
Registered: true,
4747
RegisterMethod: "authKey",
4848
AuthKeyID: uint(pak.ID),
49-
HostInfo: postgres.Jsonb{RawMessage: json.RawMessage(hostinfo)},
49+
HostInfo: datatypes.JSON(hostinfo),
5050
}
5151
db.Save(&m)
5252

0 commit comments

Comments
 (0)