mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-29 18:33:05 +00:00
Use new machine types
This commit is contained in:
parent
8a95fe517a
commit
6477e6a583
4 changed files with 10 additions and 92 deletions
17
acls.go
17
acls.go
|
@ -247,13 +247,7 @@ func expandAlias(
|
|||
for _, namespace := range owners {
|
||||
machines := filterMachinesByNamespace(machines, namespace)
|
||||
for _, machine := range machines {
|
||||
if len(machine.HostInfo) == 0 {
|
||||
continue
|
||||
}
|
||||
hi, err := machine.GetHostInfo()
|
||||
if err != nil {
|
||||
return ips, err
|
||||
}
|
||||
hi := machine.GetHostInfo()
|
||||
for _, t := range hi.RequestTags {
|
||||
if alias == t {
|
||||
ips = append(ips, machine.IPAddresses.ToStringSlice()...)
|
||||
|
@ -315,15 +309,8 @@ func excludeCorrectlyTaggedNodes(
|
|||
}
|
||||
// for each machine if tag is in tags list, don't append it.
|
||||
for _, machine := range nodes {
|
||||
if len(machine.HostInfo) == 0 {
|
||||
out = append(out, machine)
|
||||
hi := machine.GetHostInfo()
|
||||
|
||||
continue
|
||||
}
|
||||
hi, err := machine.GetHostInfo()
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
found := false
|
||||
for _, t := range hi.RequestTags {
|
||||
if containsString(tags, t) {
|
||||
|
|
25
grpcv1.go
25
grpcv1.go
|
@ -3,12 +3,10 @@ package headscale
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/juanfont/headscale/gen/go/headscale/v1"
|
||||
"github.com/rs/zerolog/log"
|
||||
"gorm.io/datatypes"
|
||||
"tailscale.com/tailcfg"
|
||||
)
|
||||
|
||||
|
@ -262,13 +260,8 @@ func (api headscaleV1APIServer) GetMachineRoute(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
routes, err := machine.RoutesToProto()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &v1.GetMachineRouteResponse{
|
||||
Routes: routes,
|
||||
Routes: machine.RoutesToProto(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -286,13 +279,8 @@ func (api headscaleV1APIServer) EnableMachineRoutes(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
routes, err := machine.RoutesToProto()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &v1.EnableMachineRoutesResponse{
|
||||
Routes: routes,
|
||||
Routes: machine.RoutesToProto(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -379,13 +367,6 @@ func (api headscaleV1APIServer) DebugCreateMachine(
|
|||
Hostname: "DebugTestMachine",
|
||||
}
|
||||
|
||||
log.Trace().Caller().Interface("hostinfo", hostinfo).Msg("")
|
||||
|
||||
hostinfoJson, err := json.Marshal(hostinfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
newMachine := Machine{
|
||||
MachineKey: request.GetKey(),
|
||||
Name: request.GetName(),
|
||||
|
@ -395,7 +376,7 @@ func (api headscaleV1APIServer) DebugCreateMachine(
|
|||
LastSeen: &time.Time{},
|
||||
LastSuccessfulUpdate: &time.Time{},
|
||||
|
||||
HostInfo: datatypes.JSON(hostinfoJson),
|
||||
HostInfo: HostInfo(hostinfo),
|
||||
}
|
||||
|
||||
// log.Trace().Caller().Interface("machine", newMachine).Msg("")
|
||||
|
|
21
poll.go
21
poll.go
|
@ -2,7 +2,6 @@ package headscale
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -11,7 +10,6 @@ import (
|
|||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/rs/zerolog/log"
|
||||
"gorm.io/datatypes"
|
||||
"gorm.io/gorm"
|
||||
"tailscale.com/tailcfg"
|
||||
"tailscale.com/types/key"
|
||||
|
@ -85,12 +83,8 @@ func (h *Headscale) PollNetMapHandler(ctx *gin.Context) {
|
|||
Str("machine", machine.Name).
|
||||
Msg("Found machine in database")
|
||||
|
||||
hostinfo, err := json.Marshal(req.Hostinfo)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
machine.Name = req.Hostinfo.Hostname
|
||||
machine.HostInfo = datatypes.JSON(hostinfo)
|
||||
machine.HostInfo = HostInfo(*req.Hostinfo)
|
||||
machine.DiscoKey = DiscoPublicKeyStripPrefix(req.DiscoKey)
|
||||
now := time.Now().UTC()
|
||||
|
||||
|
@ -114,18 +108,7 @@ func (h *Headscale) PollNetMapHandler(ctx *gin.Context) {
|
|||
// The intended use is for clients to discover the DERP map at start-up
|
||||
// before their first real endpoint update.
|
||||
if !req.ReadOnly {
|
||||
endpoints, err := json.Marshal(req.Endpoints)
|
||||
if err != nil {
|
||||
log.Error().
|
||||
Caller().
|
||||
Str("func", "PollNetMapHandler").
|
||||
Err(err).
|
||||
Msg("Failed to mashal requested endpoints for the client")
|
||||
ctx.String(http.StatusInternalServerError, ":(")
|
||||
|
||||
return
|
||||
}
|
||||
machine.Endpoints = datatypes.JSON(endpoints)
|
||||
machine.Endpoints = req.Endpoints
|
||||
machine.LastSeen = &now
|
||||
}
|
||||
h.db.Updates(machine)
|
||||
|
|
39
routes.go
39
routes.go
|
@ -1,9 +1,6 @@
|
|||
package headscale
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"gorm.io/datatypes"
|
||||
"inet.af/netaddr"
|
||||
)
|
||||
|
||||
|
@ -23,12 +20,7 @@ func (h *Headscale) GetAdvertisedNodeRoutes(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
hostInfo, err := machine.GetHostInfo()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &hostInfo.RoutableIPs, nil
|
||||
return &machine.HostInfo.RoutableIPs, nil
|
||||
}
|
||||
|
||||
// Deprecated: use machine function instead
|
||||
|
@ -43,27 +35,7 @@ func (h *Headscale) GetEnabledNodeRoutes(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
data, err := machine.EnabledRoutes.MarshalJSON()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
routesStr := []string{}
|
||||
err = json.Unmarshal(data, &routesStr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
routes := make([]netaddr.IPPrefix, len(routesStr))
|
||||
for index, routeStr := range routesStr {
|
||||
route, err := netaddr.ParseIPPrefix(routeStr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
routes[index] = route
|
||||
}
|
||||
|
||||
return routes, nil
|
||||
return machine.EnabledRoutes, nil
|
||||
}
|
||||
|
||||
// Deprecated: use machine function instead
|
||||
|
@ -135,12 +107,7 @@ func (h *Headscale) EnableNodeRoute(
|
|||
return errRouteIsNotAvailable
|
||||
}
|
||||
|
||||
routes, err := json.Marshal(enabledRoutes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
machine.EnabledRoutes = datatypes.JSON(routes)
|
||||
machine.EnabledRoutes = enabledRoutes
|
||||
h.db.Save(&machine)
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Reference in a new issue