Make log keys lowercase

This commit is contained in:
Kristoffer Dalby 2021-08-05 20:57:47 +01:00
parent cd2ca137c0
commit a8c8a358d0
No known key found for this signature in database
GPG key ID: 09F62DC067465735
4 changed files with 99 additions and 99 deletions

164
api.go
View file

@ -65,7 +65,7 @@ func (h *Headscale) RegistrationHandler(c *gin.Context) {
mKey, err := wgkey.ParseHex(mKeyStr) mKey, err := wgkey.ParseHex(mKeyStr)
if err != nil { if err != nil {
log.Error(). log.Error().
Str("Handler", "Registration"). Str("handler", "Registration").
Err(err). Err(err).
Msg("Cannot parse machine key") Msg("Cannot parse machine key")
c.String(http.StatusInternalServerError, "Sad!") c.String(http.StatusInternalServerError, "Sad!")
@ -75,7 +75,7 @@ func (h *Headscale) RegistrationHandler(c *gin.Context) {
err = decode(body, &req, &mKey, h.privateKey) err = decode(body, &req, &mKey, h.privateKey)
if err != nil { if err != nil {
log.Error(). log.Error().
Str("Handler", "Registration"). Str("handler", "Registration").
Err(err). Err(err).
Msg("Cannot decode message") Msg("Cannot decode message")
c.String(http.StatusInternalServerError, "Very sad!") c.String(http.StatusInternalServerError, "Very sad!")
@ -84,7 +84,7 @@ func (h *Headscale) RegistrationHandler(c *gin.Context) {
var m Machine var m Machine
if result := h.db.Preload("Namespace").First(&m, "machine_key = ?", mKey.HexString()); errors.Is(result.Error, gorm.ErrRecordNotFound) { if result := h.db.Preload("Namespace").First(&m, "machine_key = ?", mKey.HexString()); errors.Is(result.Error, gorm.ErrRecordNotFound) {
log.Info().Str("Name", req.Hostinfo.Hostname).Msg("New machine") log.Info().Str("machine", req.Hostinfo.Hostname).Msg("New machine")
m = Machine{ m = Machine{
Expiry: &req.Expiry, Expiry: &req.Expiry,
MachineKey: mKey.HexString(), MachineKey: mKey.HexString(),
@ -93,7 +93,7 @@ func (h *Headscale) RegistrationHandler(c *gin.Context) {
} }
if err := h.db.Create(&m).Error; err != nil { if err := h.db.Create(&m).Error; err != nil {
log.Error(). log.Error().
Str("Handler", "Registration"). Str("handler", "Registration").
Err(err). Err(err).
Msg("Could not create row") Msg("Could not create row")
return return
@ -111,8 +111,8 @@ func (h *Headscale) RegistrationHandler(c *gin.Context) {
if m.NodeKey == wgkey.Key(req.NodeKey).HexString() { if m.NodeKey == wgkey.Key(req.NodeKey).HexString() {
if m.Registered { if m.Registered {
log.Debug(). log.Debug().
Str("Handler", "Registration"). Str("handler", "Registration").
Str("Machine", m.Name). Str("machine", m.Name).
Msg("Client is registered and we have the current NodeKey. All clear to /mSending keepaliveap") Msg("Client is registered and we have the current NodeKey. All clear to /mSending keepaliveap")
resp.AuthURL = "" resp.AuthURL = ""
@ -121,7 +121,7 @@ func (h *Headscale) RegistrationHandler(c *gin.Context) {
respBody, err := encode(resp, &mKey, h.privateKey) respBody, err := encode(resp, &mKey, h.privateKey)
if err != nil { if err != nil {
log.Error(). log.Error().
Str("Handler", "Registration"). Str("handler", "Registration").
Err(err). Err(err).
Msg("Cannot encode message") Msg("Cannot encode message")
c.String(http.StatusInternalServerError, "") c.String(http.StatusInternalServerError, "")
@ -132,15 +132,15 @@ func (h *Headscale) RegistrationHandler(c *gin.Context) {
} }
log.Debug(). log.Debug().
Str("Handler", "Registration"). Str("handler", "Registration").
Str("Machine", m.Name). Str("machine", m.Name).
Msg("Not registered and not NodeKey rotation. Sending a authurl to register") Msg("Not registered and not NodeKey rotation. Sending a authurl to register")
resp.AuthURL = fmt.Sprintf("%s/register?key=%s", resp.AuthURL = fmt.Sprintf("%s/register?key=%s",
h.cfg.ServerURL, mKey.HexString()) h.cfg.ServerURL, mKey.HexString())
respBody, err := encode(resp, &mKey, h.privateKey) respBody, err := encode(resp, &mKey, h.privateKey)
if err != nil { if err != nil {
log.Error(). log.Error().
Str("Handler", "Registration"). Str("handler", "Registration").
Err(err). Err(err).
Msg("Cannot encode message") Msg("Cannot encode message")
c.String(http.StatusInternalServerError, "") c.String(http.StatusInternalServerError, "")
@ -153,8 +153,8 @@ func (h *Headscale) RegistrationHandler(c *gin.Context) {
// The NodeKey we have matches OldNodeKey, which means this is a refresh after an key expiration // The NodeKey we have matches OldNodeKey, which means this is a refresh after an key expiration
if m.NodeKey == wgkey.Key(req.OldNodeKey).HexString() { if m.NodeKey == wgkey.Key(req.OldNodeKey).HexString() {
log.Debug(). log.Debug().
Str("Handler", "Registration"). Str("handler", "Registration").
Str("Machine", m.Name). Str("machine", m.Name).
Msg("We have the OldNodeKey in the database. This is a key refresh") Msg("We have the OldNodeKey in the database. This is a key refresh")
m.NodeKey = wgkey.Key(req.NodeKey).HexString() m.NodeKey = wgkey.Key(req.NodeKey).HexString()
h.db.Save(&m) h.db.Save(&m)
@ -164,7 +164,7 @@ func (h *Headscale) RegistrationHandler(c *gin.Context) {
respBody, err := encode(resp, &mKey, h.privateKey) respBody, err := encode(resp, &mKey, h.privateKey)
if err != nil { if err != nil {
log.Error(). log.Error().
Str("Handler", "Registration"). Str("handler", "Registration").
Err(err). Err(err).
Msg("Cannot encode message") Msg("Cannot encode message")
c.String(http.StatusInternalServerError, "Extremely sad!") c.String(http.StatusInternalServerError, "Extremely sad!")
@ -178,8 +178,8 @@ func (h *Headscale) RegistrationHandler(c *gin.Context) {
// when headscale is stopped in the middle of the auth process. // when headscale is stopped in the middle of the auth process.
if m.Registered { if m.Registered {
log.Debug(). log.Debug().
Str("Handler", "Registration"). Str("handler", "Registration").
Str("Machine", m.Name). Str("machine", m.Name).
Msg("The node is sending us a new NodeKey, but machine is registered. All clear for /map") Msg("The node is sending us a new NodeKey, but machine is registered. All clear for /map")
resp.AuthURL = "" resp.AuthURL = ""
resp.MachineAuthorized = true resp.MachineAuthorized = true
@ -187,7 +187,7 @@ func (h *Headscale) RegistrationHandler(c *gin.Context) {
respBody, err := encode(resp, &mKey, h.privateKey) respBody, err := encode(resp, &mKey, h.privateKey)
if err != nil { if err != nil {
log.Error(). log.Error().
Str("Handler", "Registration"). Str("handler", "Registration").
Err(err). Err(err).
Msg("Cannot encode message") Msg("Cannot encode message")
c.String(http.StatusInternalServerError, "") c.String(http.StatusInternalServerError, "")
@ -198,15 +198,15 @@ func (h *Headscale) RegistrationHandler(c *gin.Context) {
} }
log.Debug(). log.Debug().
Str("Handler", "Registration"). Str("handler", "Registration").
Str("Machine", m.Name). Str("machine", m.Name).
Msg("The node is sending us a new NodeKey, sending auth url") Msg("The node is sending us a new NodeKey, sending auth url")
resp.AuthURL = fmt.Sprintf("%s/register?key=%s", resp.AuthURL = fmt.Sprintf("%s/register?key=%s",
h.cfg.ServerURL, mKey.HexString()) h.cfg.ServerURL, mKey.HexString())
respBody, err := encode(resp, &mKey, h.privateKey) respBody, err := encode(resp, &mKey, h.privateKey)
if err != nil { if err != nil {
log.Error(). log.Error().
Str("Handler", "Registration"). Str("handler", "Registration").
Err(err). Err(err).
Msg("Cannot encode message") Msg("Cannot encode message")
c.String(http.StatusInternalServerError, "") c.String(http.StatusInternalServerError, "")
@ -230,7 +230,7 @@ func (h *Headscale) PollNetMapHandler(c *gin.Context) {
mKey, err := wgkey.ParseHex(mKeyStr) mKey, err := wgkey.ParseHex(mKeyStr)
if err != nil { if err != nil {
log.Error(). log.Error().
Str("Handler", "PollNetMap"). Str("handler", "PollNetMap").
Err(err). Err(err).
Msg("Cannot parse client key") Msg("Cannot parse client key")
c.String(http.StatusBadRequest, "") c.String(http.StatusBadRequest, "")
@ -240,7 +240,7 @@ func (h *Headscale) PollNetMapHandler(c *gin.Context) {
err = decode(body, &req, &mKey, h.privateKey) err = decode(body, &req, &mKey, h.privateKey)
if err != nil { if err != nil {
log.Error(). log.Error().
Str("Handler", "PollNetMap"). Str("handler", "PollNetMap").
Err(err). Err(err).
Msg("Cannot decode message") Msg("Cannot decode message")
c.String(http.StatusBadRequest, "") c.String(http.StatusBadRequest, "")
@ -250,7 +250,7 @@ func (h *Headscale) PollNetMapHandler(c *gin.Context) {
var m Machine var m Machine
if result := h.db.Preload("Namespace").First(&m, "machine_key = ?", mKey.HexString()); errors.Is(result.Error, gorm.ErrRecordNotFound) { if result := h.db.Preload("Namespace").First(&m, "machine_key = ?", mKey.HexString()); errors.Is(result.Error, gorm.ErrRecordNotFound) {
log.Warn(). log.Warn().
Str("Handler", "PollNetMap"). Str("handler", "PollNetMap").
Msgf("Ignoring request, cannot find machine with key %s", mKey.HexString()) Msgf("Ignoring request, cannot find machine with key %s", mKey.HexString())
c.String(http.StatusUnauthorized, "") c.String(http.StatusUnauthorized, "")
return return
@ -298,49 +298,49 @@ func (h *Headscale) PollNetMapHandler(c *gin.Context) {
// Details on the protocol can be found in https://github.com/tailscale/tailscale/blob/main/tailcfg/tailcfg.go#L696 // Details on the protocol can be found in https://github.com/tailscale/tailscale/blob/main/tailcfg/tailcfg.go#L696
log.Debug(). log.Debug().
Str("Handler", "PollNetMap"). Str("handler", "PollNetMap").
Str("Machine", m.Name). Str("machine", m.Name).
Bool("ReadOnly", req.ReadOnly). Bool("readOnly", req.ReadOnly).
Bool("OmitPeers", req.OmitPeers). Bool("omitPeers", req.OmitPeers).
Bool("Stream", req.Stream) Bool("stream", req.Stream)
if req.ReadOnly { if req.ReadOnly {
log.Info(). log.Info().
Str("Handler", "PollNetMap"). Str("handler", "PollNetMap").
Str("Machine", m.Name). Str("machine", m.Name).
Msg("Client is starting up. Asking for DERP map") Msg("Client is starting up. Asking for DERP map")
c.Data(200, "application/json; charset=utf-8", *data) c.Data(200, "application/json; charset=utf-8", *data)
return return
} }
if req.OmitPeers && !req.Stream { if req.OmitPeers && !req.Stream {
log.Info(). log.Info().
Str("Handler", "PollNetMap"). Str("handler", "PollNetMap").
Str("Machine", m.Name). Str("machine", m.Name).
Msg("Client sent endpoint update and is ok with a response without peer list") Msg("Client sent endpoint update and is ok with a response without peer list")
c.Data(200, "application/json; charset=utf-8", *data) c.Data(200, "application/json; charset=utf-8", *data)
return return
} else if req.OmitPeers && req.Stream { } else if req.OmitPeers && req.Stream {
log.Warn(). log.Warn().
Str("Handler", "PollNetMap"). Str("handler", "PollNetMap").
Str("Machine", m.Name). Str("machine", m.Name).
Msg("Ignoring request, don't know how to handle it") Msg("Ignoring request, don't know how to handle it")
c.String(http.StatusBadRequest, "") c.String(http.StatusBadRequest, "")
return return
} }
log.Info(). log.Info().
Str("Handler", "PollNetMap"). Str("handler", "PollNetMap").
Str("Machine", m.Name). Str("machine", m.Name).
Msg("Client is ready to access the tailnet") Msg("Client is ready to access the tailnet")
log.Info(). log.Info().
Str("Handler", "PollNetMap"). Str("handler", "PollNetMap").
Str("Machine", m.Name). Str("machine", m.Name).
Msg("Sending initial map") Msg("Sending initial map")
pollData <- *data pollData <- *data
log.Info(). log.Info().
Str("Handler", "PollNetMap"). Str("handler", "PollNetMap").
Str("Machine", m.Name). Str("machine", m.Name).
Msg("Notifying peers") Msg("Notifying peers")
peers, _ := h.getPeers(m) peers, _ := h.getPeers(m)
h.pollMu.Lock() h.pollMu.Lock()
@ -348,17 +348,17 @@ func (h *Headscale) PollNetMapHandler(c *gin.Context) {
pUp, ok := h.clientsPolling[uint64(p.ID)] pUp, ok := h.clientsPolling[uint64(p.ID)]
if ok { if ok {
log.Info(). log.Info().
Str("Handler", "PollNetMap"). Str("handler", "PollNetMap").
Str("Machine", m.Name). Str("machine", m.Name).
Str("Peer", m.Name). Str("peer", m.Name).
Str("Address", p.Addresses[0].String()). Str("address", p.Addresses[0].String()).
Msgf("Notifying peer %s (%s)", p.Name, p.Addresses[0]) Msgf("Notifying peer %s (%s)", p.Name, p.Addresses[0])
pUp <- []byte{} pUp <- []byte{}
} else { } else {
log.Info(). log.Info().
Str("Handler", "PollNetMap"). Str("handler", "PollNetMap").
Str("Machine", m.Name). Str("machine", m.Name).
Str("Peer", m.Name). Str("peer", m.Name).
Msgf("Peer %s does not appear to be polling", p.Name) Msgf("Peer %s does not appear to be polling", p.Name)
} }
} }
@ -370,15 +370,15 @@ func (h *Headscale) PollNetMapHandler(c *gin.Context) {
select { select {
case data := <-pollData: case data := <-pollData:
log.Trace(). log.Trace().
Str("Handler", "PollNetMap"). Str("handler", "PollNetMap").
Str("Machine", m.Name). Str("machine", m.Name).
Int("Bytes", len(data)). Int("bytes", len(data)).
Msg("Sending data") Msg("Sending data")
_, err := w.Write(data) _, err := w.Write(data)
if err != nil { if err != nil {
log.Error(). log.Error().
Str("Handler", "PollNetMap"). Str("handler", "PollNetMap").
Str("Machine", m.Name). Str("machine", m.Name).
Err(err). Err(err).
Msg("Cannot write data") Msg("Cannot write data")
} }
@ -389,22 +389,22 @@ func (h *Headscale) PollNetMapHandler(c *gin.Context) {
case <-update: case <-update:
log.Debug(). log.Debug().
Str("Handler", "PollNetMap"). Str("handler", "PollNetMap").
Str("Machine", m.Name). Str("machine", m.Name).
Msg("Received a request for update") Msg("Received a request for update")
data, err := h.getMapResponse(mKey, req, m) data, err := h.getMapResponse(mKey, req, m)
if err != nil { if err != nil {
log.Error(). log.Error().
Str("Handler", "PollNetMap"). Str("handler", "PollNetMap").
Str("Machine", m.Name). Str("machine", m.Name).
Err(err). Err(err).
Msg("Could not get the map update") Msg("Could not get the map update")
} }
_, err = w.Write(*data) _, err = w.Write(*data)
if err != nil { if err != nil {
log.Error(). log.Error().
Str("Handler", "PollNetMap"). Str("handler", "PollNetMap").
Str("Machine", m.Name). Str("machine", m.Name).
Err(err). Err(err).
Msg("Could not write the map response") Msg("Could not write the map response")
} }
@ -412,8 +412,8 @@ func (h *Headscale) PollNetMapHandler(c *gin.Context) {
case <-c.Request.Context().Done(): case <-c.Request.Context().Done():
log.Info(). log.Info().
Str("Handler", "PollNetMap"). Str("handler", "PollNetMap").
Str("Machine", m.Name). Str("machine", m.Name).
Msg("The client has closed the connection") Msg("The client has closed the connection")
now := time.Now().UTC() now := time.Now().UTC()
m.LastSeen = &now m.LastSeen = &now
@ -440,14 +440,14 @@ func (h *Headscale) keepAlive(cancel chan []byte, pollData chan []byte, mKey wgk
data, err := h.getMapKeepAliveResponse(mKey, req, m) data, err := h.getMapKeepAliveResponse(mKey, req, m)
if err != nil { if err != nil {
log.Error(). log.Error().
Str("Func", "keepAlive"). Str("func", "keepAlive").
Err(err). Err(err).
Msg("Error generating the keep alive msg") Msg("Error generating the keep alive msg")
return return
} }
log.Debug(). log.Debug().
Str("Func", "keepAlive"). Str("func", "keepAlive").
Str("Machine", m.Name). Str("machine", m.Name).
Msg("Sending keepalive") Msg("Sending keepalive")
pollData <- *data pollData <- *data
h.pollMu.Unlock() h.pollMu.Unlock()
@ -460,7 +460,7 @@ func (h *Headscale) getMapResponse(mKey wgkey.Key, req tailcfg.MapRequest, m Mac
node, err := m.toNode() node, err := m.toNode()
if err != nil { if err != nil {
log.Error(). log.Error().
Str("Func", "getMapResponse"). Str("func", "getMapResponse").
Err(err). Err(err).
Msg("Cannot convert to node") Msg("Cannot convert to node")
return nil, err return nil, err
@ -468,7 +468,7 @@ func (h *Headscale) getMapResponse(mKey wgkey.Key, req tailcfg.MapRequest, m Mac
peers, err := h.getPeers(m) peers, err := h.getPeers(m)
if err != nil { if err != nil {
log.Error(). log.Error().
Str("Func", "getMapResponse"). Str("func", "getMapResponse").
Err(err). Err(err).
Msg("Cannot fetch peers") Msg("Cannot fetch peers")
return nil, err return nil, err
@ -543,8 +543,8 @@ func (h *Headscale) getMapKeepAliveResponse(mKey wgkey.Key, req tailcfg.MapReque
func (h *Headscale) handleAuthKey(c *gin.Context, db *gorm.DB, idKey wgkey.Key, req tailcfg.RegisterRequest, m Machine) { func (h *Headscale) handleAuthKey(c *gin.Context, db *gorm.DB, idKey wgkey.Key, req tailcfg.RegisterRequest, m Machine) {
log.Debug(). log.Debug().
Str("Func", "handleAuthKey"). Str("func", "handleAuthKey").
Str("Machine", req.Hostinfo.Hostname). Str("machine", req.Hostinfo.Hostname).
Msgf("Processing auth key for %s", req.Hostinfo.Hostname) Msgf("Processing auth key for %s", req.Hostinfo.Hostname)
resp := tailcfg.RegisterResponse{} resp := tailcfg.RegisterResponse{}
pak, err := h.checkKeyValidity(req.Auth.AuthKey) pak, err := h.checkKeyValidity(req.Auth.AuthKey)
@ -553,8 +553,8 @@ func (h *Headscale) handleAuthKey(c *gin.Context, db *gorm.DB, idKey wgkey.Key,
respBody, err := encode(resp, &idKey, h.privateKey) respBody, err := encode(resp, &idKey, h.privateKey)
if err != nil { if err != nil {
log.Error(). log.Error().
Str("Func", "handleAuthKey"). Str("func", "handleAuthKey").
Str("Machine", m.Name). Str("machine", m.Name).
Err(err). Err(err).
Msg("Cannot encode message") Msg("Cannot encode message")
c.String(http.StatusInternalServerError, "") c.String(http.StatusInternalServerError, "")
@ -562,28 +562,28 @@ func (h *Headscale) handleAuthKey(c *gin.Context, db *gorm.DB, idKey wgkey.Key,
} }
c.Data(200, "application/json; charset=utf-8", respBody) c.Data(200, "application/json; charset=utf-8", respBody)
log.Error(). log.Error().
Str("Func", "handleAuthKey"). Str("func", "handleAuthKey").
Str("Machine", m.Name). Str("machine", m.Name).
Msg("Failed authentication via AuthKey") Msg("Failed authentication via AuthKey")
return return
} }
log.Debug(). log.Debug().
Str("Func", "handleAuthKey"). Str("func", "handleAuthKey").
Str("Machine", m.Name). Str("machine", m.Name).
Msg("Authentication key was valid, proceeding to acquire an IP address") Msg("Authentication key was valid, proceeding to acquire an IP address")
ip, err := h.getAvailableIP() ip, err := h.getAvailableIP()
if err != nil { if err != nil {
log.Error(). log.Error().
Str("Func", "handleAuthKey"). Str("func", "handleAuthKey").
Str("Machine", m.Name). Str("machine", m.Name).
Msg("Failed to find an available IP") Msg("Failed to find an available IP")
return return
} }
log.Info(). log.Info().
Str("Func", "handleAuthKey"). Str("func", "handleAuthKey").
Str("Machine", m.Name). Str("machine", m.Name).
Str("IP", ip.String()). Str("ip", ip.String()).
Msgf("Assining %s to %s", ip, m.Name) Msgf("Assining %s to %s", ip, m.Name)
m.AuthKeyID = uint(pak.ID) m.AuthKeyID = uint(pak.ID)
@ -599,8 +599,8 @@ func (h *Headscale) handleAuthKey(c *gin.Context, db *gorm.DB, idKey wgkey.Key,
respBody, err := encode(resp, &idKey, h.privateKey) respBody, err := encode(resp, &idKey, h.privateKey)
if err != nil { if err != nil {
log.Error(). log.Error().
Str("Func", "handleAuthKey"). Str("func", "handleAuthKey").
Str("Machine", m.Name). Str("machine", m.Name).
Err(err). Err(err).
Msg("Cannot encode message") Msg("Cannot encode message")
c.String(http.StatusInternalServerError, "Extremely sad!") c.String(http.StatusInternalServerError, "Extremely sad!")
@ -608,8 +608,8 @@ func (h *Headscale) handleAuthKey(c *gin.Context, db *gorm.DB, idKey wgkey.Key,
} }
c.Data(200, "application/json; charset=utf-8", respBody) c.Data(200, "application/json; charset=utf-8", respBody)
log.Info(). log.Info().
Str("Func", "handleAuthKey"). Str("func", "handleAuthKey").
Str("Machine", m.Name). Str("machine", m.Name).
Str("IP", ip.String()). Str("ip", ip.String()).
Msg("Successfully authenticated via AuthKey") Msg("Successfully authenticated via AuthKey")
} }

6
app.go
View file

@ -127,15 +127,15 @@ func (h *Headscale) expireEphemeralNodesWorker() {
for _, ns := range *namespaces { for _, ns := range *namespaces {
machines, err := h.ListMachinesInNamespace(ns.Name) machines, err := h.ListMachinesInNamespace(ns.Name)
if err != nil { if err != nil {
log.Error().Err(err).Str("Namespace", ns.Name).Msg("Error listing machines in namespace") log.Error().Err(err).Str("namespace", ns.Name).Msg("Error listing machines in namespace")
return return
} }
for _, m := range *machines { for _, m := range *machines {
if m.AuthKey != nil && m.LastSeen != nil && m.AuthKey.Ephemeral && time.Now().After(m.LastSeen.Add(h.cfg.EphemeralNodeInactivityTimeout)) { if m.AuthKey != nil && m.LastSeen != nil && m.AuthKey.Ephemeral && time.Now().After(m.LastSeen.Add(h.cfg.EphemeralNodeInactivityTimeout)) {
log.Info().Str("Machine", m.Name).Msg("Ephemeral client removed from database") log.Info().Str("machine", m.Name).Msg("Ephemeral client removed from database")
err = h.db.Unscoped().Delete(m).Error err = h.db.Unscoped().Delete(m).Error
if err != nil { if err != nil {
log.Error().Err(err).Str("Name", m.Name).Msg("🤮 Cannot delete ephemeral machine from the database") log.Error().Err(err).Str("machine", m.Name).Msg("🤮 Cannot delete ephemeral machine from the database")
} }
} }
} }

View file

@ -89,7 +89,7 @@ func getHeadscaleApp() (*headscale.Headscale, error) {
derpMap, err := loadDerpMap(derpPath) derpMap, err := loadDerpMap(derpPath)
if err != nil { if err != nil {
log.Error(). log.Error().
Str("Path", derpPath). Str("path", derpPath).
Err(err). Err(err).
Msg("Could not load DERP servers map file") Msg("Could not load DERP servers map file")
} }
@ -140,7 +140,7 @@ func getHeadscaleApp() (*headscale.Headscale, error) {
err = h.LoadACLPolicy(aclPath) err = h.LoadACLPolicy(aclPath)
if err != nil { if err != nil {
log.Error(). log.Error().
Str("Path", aclPath). Str("path", aclPath).
Err(err). Err(err).
Msg("Could not load the ACL policy") Msg("Could not load the ACL policy")
} }

View file

@ -34,7 +34,7 @@ func (h *Headscale) CreateNamespace(name string) (*Namespace, error) {
n.Name = name n.Name = name
if err := h.db.Create(&n).Error; err != nil { if err := h.db.Create(&n).Error; err != nil {
log.Error(). log.Error().
Str("Func", "CreateNamespace"). Str("func", "CreateNamespace").
Err(err). Err(err).
Msg("Could not create row") Msg("Could not create row")
return nil, err return nil, err
@ -137,7 +137,7 @@ func (h *Headscale) RequestMapUpdates(namespaceID uint) error {
data, err := json.Marshal(names) data, err := json.Marshal(names)
if err != nil { if err != nil {
log.Error(). log.Error().
Str("Func", "RequestMapUpdates"). Str("func", "RequestMapUpdates").
Err(err). Err(err).
Msg("Could not marshal namespaces_pending_updates") Msg("Could not marshal namespaces_pending_updates")
return err return err
@ -161,8 +161,8 @@ func (h *Headscale) checkForNamespacesPendingUpdates() {
} }
for _, name := range names { for _, name := range names {
log.Trace(). log.Trace().
Str("Func", "RequestMapUpdates"). Str("func", "RequestMapUpdates").
Str("Machine", name). Str("machine", name).
Msg("Sending updates to nodes in namespace") Msg("Sending updates to nodes in namespace")
machines, err := h.ListMachinesInNamespace(name) machines, err := h.ListMachinesInNamespace(name)
if err != nil { if err != nil {
@ -175,17 +175,17 @@ func (h *Headscale) checkForNamespacesPendingUpdates() {
pUp, ok := h.clientsPolling[uint64(p.ID)] pUp, ok := h.clientsPolling[uint64(p.ID)]
if ok { if ok {
log.Info(). log.Info().
Str("Func", "checkForNamespacesPendingUpdates"). Str("func", "checkForNamespacesPendingUpdates").
Str("Machine", m.Name). Str("machine", m.Name).
Str("Peer", m.Name). Str("peer", m.Name).
Str("Address", p.Addresses[0].String()). Str("address", p.Addresses[0].String()).
Msgf("Notifying peer %s (%s)", p.Name, p.Addresses[0]) Msgf("Notifying peer %s (%s)", p.Name, p.Addresses[0])
pUp <- []byte{} pUp <- []byte{}
} else { } else {
log.Info(). log.Info().
Str("Func", "checkForNamespacesPendingUpdates"). Str("func", "checkForNamespacesPendingUpdates").
Str("Machine", m.Name). Str("machine", m.Name).
Str("Peer", m.Name). Str("peer", m.Name).
Msgf("Peer %s does not appear to be polling", p.Name) Msgf("Peer %s does not appear to be polling", p.Name)
} }
} }
@ -200,7 +200,7 @@ func (h *Headscale) checkForNamespacesPendingUpdates() {
err = h.setValue("namespaces_pending_updates", "") err = h.setValue("namespaces_pending_updates", "")
if err != nil { if err != nil {
log.Error(). log.Error().
Str("Func", "checkForNamespacesPendingUpdates"). Str("func", "checkForNamespacesPendingUpdates").
Err(err). Err(err).
Msg("Could not save to KV") Msg("Could not save to KV")
return return