mirror of
https://github.com/juanfont/headscale.git
synced 2025-09-25 17:51:11 +02:00
Merge 75f3b2f29b
into 8e25f7f9dd
This commit is contained in:
commit
faa2d2ad3e
@ -105,10 +105,9 @@ func (h *Headscale) debugHTTPServer() *http.Server {
|
||||
w.Write(dmJSON)
|
||||
}))
|
||||
debug.Handle("registration-cache", "Pending registrations", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO(kradalby): This should be replaced with a proper state method that returns registration info
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("{}")) // For now, return empty object
|
||||
w.Write([]byte(h.state.GetRegistrationCacheDebug()))
|
||||
}))
|
||||
debug.Handle("routes", "Routes", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"io"
|
||||
"net/netip"
|
||||
"os"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
@ -738,6 +739,43 @@ func (s *State) SetRegistrationCacheEntry(id types.RegistrationID, entry types.R
|
||||
s.registrationCache.Set(id, entry)
|
||||
}
|
||||
|
||||
// GetRegistrationCacheDebug returns all registration cache entries as a formatted string
|
||||
func (s *State) GetRegistrationCacheDebug() string {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
|
||||
items := s.registrationCache.Items()
|
||||
if len(items) == 0 {
|
||||
return "No pending registrations"
|
||||
}
|
||||
|
||||
var result strings.Builder
|
||||
result.WriteString(fmt.Sprintf("Registration Cache (%d entries):\n", len(items)))
|
||||
result.WriteString("=====================================\n")
|
||||
|
||||
for id, item := range items {
|
||||
regNode := item.Object
|
||||
result.WriteString(fmt.Sprintf(" ID: %s\n", id))
|
||||
result.WriteString(fmt.Sprintf(" Node ID: %d\n", regNode.Node.ID))
|
||||
result.WriteString(fmt.Sprintf(" Hostname: %s\n", regNode.Node.Hostname))
|
||||
result.WriteString(fmt.Sprintf(" Given Name: %s\n", regNode.Node.GivenName))
|
||||
result.WriteString(fmt.Sprintf(" User ID: %d\n", regNode.Node.UserID))
|
||||
result.WriteString(fmt.Sprintf(" Register Method: %s\n", regNode.Node.RegisterMethod))
|
||||
result.WriteString(fmt.Sprintf(" Expires: %v\n", item.Expiration))
|
||||
result.WriteString(fmt.Sprintf(" Channel Status: %s\n", func() string {
|
||||
select {
|
||||
case <-regNode.Registered:
|
||||
return "closed"
|
||||
default:
|
||||
return "open"
|
||||
}
|
||||
}()))
|
||||
result.WriteString("-------------------------------------\n")
|
||||
}
|
||||
|
||||
return result.String()
|
||||
}
|
||||
|
||||
// HandleNodeFromAuthPath handles node registration through authentication flow (like OIDC).
|
||||
func (s *State) HandleNodeFromAuthPath(
|
||||
registrationID types.RegistrationID,
|
||||
|
@ -188,6 +188,19 @@ type RegisterNode struct {
|
||||
Registered chan *Node
|
||||
}
|
||||
|
||||
// RegisterNodeDebug is a JSON-serializable version of RegisterNode
|
||||
// that excludes the channel field to prevent JSON marshaling errors
|
||||
type RegisterNodeDebug struct {
|
||||
Node Node `json:"node"`
|
||||
}
|
||||
|
||||
// ToDebug converts a RegisterNode to its JSON-serializable form
|
||||
func (rn *RegisterNode) ToDebug() RegisterNodeDebug {
|
||||
return RegisterNodeDebug{
|
||||
Node: rn.Node,
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultBatcherWorkers returns the default number of batcher workers.
|
||||
// Default to 3/4 of CPU cores, minimum 1, no maximum.
|
||||
func DefaultBatcherWorkers() int {
|
||||
|
Loading…
Reference in New Issue
Block a user