mirror of
https://github.com/juanfont/headscale.git
synced 2026-09-18 14:32:01 +09:00
hscontrol: remove the proto, gRPC and grpc-gateway stack
With the v1 API served by Huma and the CLI on the HTTP client, nothing uses the gRPC service or its generated code. Delete proto/, the generated gen/go and gen/openapiv2, grpcv1.go, the buf config, the proto .Proto() helpers and gRPC config, and the proto build tooling from the flake and CI.
This commit is contained in:
+3
-78
@@ -10,13 +10,11 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
|
||||
"github.com/juanfont/headscale/hscontrol/policy/matcher"
|
||||
"github.com/juanfont/headscale/hscontrol/util"
|
||||
"github.com/juanfont/headscale/hscontrol/util/zlog/zf"
|
||||
"github.com/rs/zerolog"
|
||||
"go4.org/netipx"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
"tailscale.com/net/tsaddr"
|
||||
"tailscale.com/tailcfg"
|
||||
"tailscale.com/types/key"
|
||||
@@ -483,55 +481,6 @@ func (nodes Nodes) ContainsNodeKey(nodeKey key.NodePublic) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (node *Node) Proto() *v1.Node {
|
||||
nodeProto := &v1.Node{
|
||||
Id: uint64(node.ID),
|
||||
MachineKey: node.MachineKey.String(),
|
||||
|
||||
NodeKey: node.NodeKey.String(),
|
||||
DiscoKey: node.DiscoKey.String(),
|
||||
|
||||
// TODO(kradalby): replace list with v4, v6 field?
|
||||
IpAddresses: node.IPsAsString(),
|
||||
Name: node.Hostname,
|
||||
GivenName: node.GivenName,
|
||||
User: nil, // Will be set below based on node type
|
||||
Tags: node.Tags,
|
||||
Online: node.IsOnline != nil && *node.IsOnline,
|
||||
|
||||
// Only ApprovedRoutes and AvailableRoutes is set here. SubnetRoutes has
|
||||
// to be populated manually with PrimaryRoute, to ensure it includes the
|
||||
// routes that are actively served from the node.
|
||||
ApprovedRoutes: util.PrefixesToString(node.ApprovedRoutes),
|
||||
AvailableRoutes: util.PrefixesToString(node.AnnouncedRoutes()),
|
||||
|
||||
RegisterMethod: node.RegisterMethodToV1Enum(),
|
||||
|
||||
CreatedAt: timestamppb.New(node.CreatedAt),
|
||||
}
|
||||
|
||||
// Set User field based on node ownership
|
||||
// Note: User will be set to [TaggedDevices] in the gRPC layer (grpcv1.go)
|
||||
// for proper [tailcfg.MapResponse] formatting
|
||||
if node.User != nil {
|
||||
nodeProto.User = node.User.Proto()
|
||||
}
|
||||
|
||||
if node.AuthKey != nil {
|
||||
nodeProto.PreAuthKey = node.AuthKey.Proto()
|
||||
}
|
||||
|
||||
if node.LastSeen != nil {
|
||||
nodeProto.LastSeen = timestamppb.New(*node.LastSeen)
|
||||
}
|
||||
|
||||
if node.Expiry != nil {
|
||||
nodeProto.Expiry = timestamppb.New(*node.Expiry)
|
||||
}
|
||||
|
||||
return nodeProto
|
||||
}
|
||||
|
||||
func (node *Node) GetFQDN(baseDomain string) (string, error) {
|
||||
if node.GivenName == "" {
|
||||
return "", fmt.Errorf("creating valid FQDN: %w", ErrNodeHasNoGivenName)
|
||||
@@ -574,11 +523,9 @@ func (node *Node) AnnouncedRoutes() []netip.Prefix {
|
||||
// announces and are approved. Also used by [Node.CanAccess] and [Node.CanAccessRoute] as part
|
||||
// of the subnet-router-as-source identity.
|
||||
//
|
||||
// IMPORTANT: This method is used for internal data structures and should NOT be
|
||||
// used for the gRPC Proto conversion. For Proto, SubnetRoutes must be populated
|
||||
// manually with PrimaryRoutes to ensure it includes only routes actively served
|
||||
// by the node. See the comment in [Node.Proto] method and the implementation in
|
||||
// grpcv1.go/nodesToProto.
|
||||
// IMPORTANT: This method reflects announced-and-approved routes. API
|
||||
// responses that need the routes actively served by the node must
|
||||
// populate SubnetRoutes from the primary-route election instead.
|
||||
func (node *Node) SubnetRoutes() []netip.Prefix {
|
||||
var routes []netip.Prefix
|
||||
|
||||
@@ -684,19 +631,6 @@ func EndpointsChanged(oldEndpoints, newEndpoints []netip.AddrPort) bool {
|
||||
return !equalUnordered(oldEndpoints, newEndpoints, netip.AddrPort.Compare)
|
||||
}
|
||||
|
||||
func (node *Node) RegisterMethodToV1Enum() v1.RegisterMethod {
|
||||
switch node.RegisterMethod {
|
||||
case "authkey":
|
||||
return v1.RegisterMethod_REGISTER_METHOD_AUTH_KEY
|
||||
case "oidc":
|
||||
return v1.RegisterMethod_REGISTER_METHOD_OIDC
|
||||
case "cli":
|
||||
return v1.RegisterMethod_REGISTER_METHOD_CLI
|
||||
default:
|
||||
return v1.RegisterMethod_REGISTER_METHOD_UNSPECIFIED
|
||||
}
|
||||
}
|
||||
|
||||
// ApplyPeerChange takes a [tailcfg.PeerChange] struct and updates the node.
|
||||
func (node *Node) ApplyPeerChange(change *tailcfg.PeerChange) {
|
||||
if change.Key != nil {
|
||||
@@ -998,15 +932,6 @@ func (nv NodeView) RequestTags() []string {
|
||||
return nv.Hostinfo().RequestTags().AsSlice()
|
||||
}
|
||||
|
||||
// Proto converts the [NodeView] to a protobuf representation.
|
||||
func (nv NodeView) Proto() *v1.Node {
|
||||
if !nv.Valid() {
|
||||
return nil
|
||||
}
|
||||
|
||||
return nv.ж.Proto()
|
||||
}
|
||||
|
||||
// HasIP reports if a node has a given IP address.
|
||||
func (nv NodeView) HasIP(i netip.Addr) bool {
|
||||
if !nv.Valid() {
|
||||
|
||||
Reference in New Issue
Block a user