diff --git a/api.go b/api.go index b4f59cd1..56d858ca 100644 --- a/api.go +++ b/api.go @@ -11,8 +11,8 @@ import ( "github.com/gin-gonic/gin" "github.com/jinzhu/gorm" - "github.com/jinzhu/gorm/dialects/postgres" "github.com/klauspost/compress/zstd" + "gorm.io/datatypes" "inet.af/netaddr" "tailscale.com/tailcfg" "tailscale.com/wgengine/wgcfg" @@ -40,7 +40,7 @@ func (h *Headscale) RegisterWebAPI(c *gin.Context) {
- Run the command below on the headscale server to add this machine to your network: + Run the command below in the headscale server to add this machine to your network:
@@ -174,13 +174,13 @@ func (h *Headscale) PollNetMapHandler(c *gin.Context) { defer db.Close() var m Machine if db.First(&m, "machine_key = ?", mKey.HexString()).RecordNotFound() { - log.Printf("Cannot find machine: %s", err) + log.Printf("Cannot fingitd machine: %s", err) return } hostinfo, _ := json.Marshal(req.Hostinfo) m.Name = req.Hostinfo.Hostname - m.HostInfo = postgres.Jsonb{RawMessage: json.RawMessage(hostinfo)} + m.HostInfo = datatypes.JSON(hostinfo) m.DiscoKey = wgcfg.Key(req.DiscoKey).HexString() now := time.Now().UTC() @@ -194,7 +194,7 @@ func (h *Headscale) PollNetMapHandler(c *gin.Context) { // before their first real endpoint update. if !req.ReadOnly { endpoints, _ := json.Marshal(req.Endpoints) - m.Endpoints = postgres.Jsonb{RawMessage: json.RawMessage(endpoints)} + m.Endpoints = datatypes.JSON(endpoints) m.LastSeen = &now } db.Save(&m) diff --git a/machine.go b/machine.go index b67c2a68..265c5261 100644 --- a/machine.go +++ b/machine.go @@ -8,7 +8,7 @@ import ( "strconv" "time" - "github.com/jinzhu/gorm/dialects/postgres" + "gorm.io/datatypes" "inet.af/netaddr" "tailscale.com/tailcfg" "tailscale.com/wgengine/wgcfg" @@ -33,9 +33,9 @@ type Machine struct { LastSeen *time.Time Expiry *time.Time - HostInfo postgres.Jsonb - Endpoints postgres.Jsonb - EnabledRoutes postgres.Jsonb + HostInfo datatypes.JSON + Endpoints datatypes.JSON + EnabledRoutes datatypes.JSON CreatedAt time.Time UpdatedAt time.Time @@ -79,7 +79,7 @@ func (m Machine) toNode() (*tailcfg.Node, error) { allowedIPs = append(allowedIPs, ip) // we append the node own IP, as it is required by the clients routesStr := []string{} - if len(m.EnabledRoutes.RawMessage) != 0 { + if len(m.EnabledRoutes) != 0 { allwIps, err := m.EnabledRoutes.MarshalJSON() if err != nil { return nil, err @@ -99,7 +99,7 @@ func (m Machine) toNode() (*tailcfg.Node, error) { } endpoints := []string{} - if len(m.Endpoints.RawMessage) != 0 { + if len(m.Endpoints) != 0 { be, err := m.Endpoints.MarshalJSON() if err != nil { return nil, err @@ -111,7 +111,7 @@ func (m Machine) toNode() (*tailcfg.Node, error) { } hostinfo := tailcfg.Hostinfo{} - if len(m.HostInfo.RawMessage) != 0 { + if len(m.HostInfo) != 0 { hi, err := m.HostInfo.MarshalJSON() if err != nil { return nil, err @@ -198,7 +198,7 @@ func (h *Headscale) GetMachine(namespace string, name string) (*Machine, error) // GetHostInfo returns a Hostinfo struct for the machine func (m *Machine) GetHostInfo() (*tailcfg.Hostinfo, error) { hostinfo := tailcfg.Hostinfo{} - if len(m.HostInfo.RawMessage) != 0 { + if len(m.HostInfo) != 0 { hi, err := m.HostInfo.MarshalJSON() if err != nil { return nil, err diff --git a/routes.go b/routes.go index 77bd72eb..59c32bb7 100644 --- a/routes.go +++ b/routes.go @@ -5,7 +5,7 @@ import ( "errors" "log" - "github.com/jinzhu/gorm/dialects/postgres" + "gorm.io/datatypes" "inet.af/netaddr" ) @@ -49,7 +49,7 @@ func (h *Headscale) EnableNodeRoute(namespace string, nodeName string, routeStr } routes, _ := json.Marshal([]string{routeStr}) // TODO: only one for the time being, so overwriting the rest - m.EnabledRoutes = postgres.Jsonb{RawMessage: json.RawMessage(routes)} + m.EnabledRoutes = datatypes.JSON(routes) db.Save(&m) db.Close() diff --git a/routes_test.go b/routes_test.go index b43e427d..04d449b1 100644 --- a/routes_test.go +++ b/routes_test.go @@ -3,8 +3,8 @@ package headscale import ( "encoding/json" - "github.com/jinzhu/gorm/dialects/postgres" "gopkg.in/check.v1" + "gorm.io/datatypes" "inet.af/netaddr" "tailscale.com/tailcfg" ) @@ -46,7 +46,7 @@ func (s *Suite) TestGetRoutes(c *check.C) { Registered: true, RegisterMethod: "authKey", AuthKeyID: uint(pak.ID), - HostInfo: postgres.Jsonb{RawMessage: json.RawMessage(hostinfo)}, + HostInfo: datatypes.JSON(hostinfo), } db.Save(&m)