And more linting stuff

This commit is contained in:
Juan Font Alonso 2022-08-14 12:44:07 +02:00
parent 3bea20850a
commit eb8d8f142c
2 changed files with 45 additions and 6 deletions

View File

@ -56,7 +56,10 @@ func (h *Headscale) NoiseUpgradeHandler(
server := http.Server{} server := http.Server{}
server.Handler = h2c.NewHandler(h.noiseMux, &http2.Server{}) server.Handler = h2c.NewHandler(h.noiseMux, &http2.Server{})
server.Serve(netutil.NewOneConnListener(noiseConn, nil)) err = server.Serve(netutil.NewOneConnListener(noiseConn, nil))
if err != nil {
log.Error().Err(err).Msg("noise server launch failed")
}
} }
// getNoiseConnection is basically AcceptHTTP from tailscale // getNoiseConnection is basically AcceptHTTP from tailscale

View File

@ -197,7 +197,13 @@ func (h *Headscale) handleNoiseAuthKey(
writer.Header().Set("Content-Type", "application/json") writer.Header().Set("Content-Type", "application/json")
writer.WriteHeader(http.StatusUnauthorized) writer.WriteHeader(http.StatusUnauthorized)
json.NewEncoder(writer).Encode(resp) err = json.NewEncoder(writer).Encode(resp)
if err != nil {
log.Error().
Caller().
Err(err).
Msg("Failed to encode response")
}
log.Error(). log.Error().
Caller(). Caller().
@ -234,7 +240,16 @@ func (h *Headscale) handleNoiseAuthKey(
machine.NodeKey = nodeKey machine.NodeKey = nodeKey
machine.AuthKeyID = uint(pak.ID) machine.AuthKeyID = uint(pak.ID)
h.RefreshMachine(machine, registerRequest.Expiry) err = h.RefreshMachine(machine, registerRequest.Expiry)
if err != nil {
log.Error().
Caller().
Str("machine", machine.Hostname).
Err(err).
Msg("Failed to refresh machine")
return
}
} else { } else {
now := time.Now().UTC() now := time.Now().UTC()
@ -277,7 +292,18 @@ func (h *Headscale) handleNoiseAuthKey(
} }
} }
h.UsePreAuthKey(pak) err = h.UsePreAuthKey(pak)
if err != nil {
log.Error().
Caller().
Err(err).
Msg("Failed to use pre-auth key")
machineRegistrations.WithLabelValues("new", RegisterMethodAuthKey, "error", pak.Namespace.Name).
Inc()
http.Error(writer, "Internal server error", http.StatusInternalServerError)
return
}
resp.MachineAuthorized = true resp.MachineAuthorized = true
resp.User = *pak.Namespace.toUser() resp.User = *pak.Namespace.toUser()
@ -358,7 +384,17 @@ func (h *Headscale) handleNoiseNodeLogOut(
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Msg("Client requested logout") Msg("Client requested logout")
h.ExpireMachine(&machine) err := h.ExpireMachine(&machine)
if err != nil {
log.Error().
Caller().
Str("func", "handleMachineLogOut").
Err(err).
Msg("Failed to expire machine")
http.Error(writer, "Internal server error", http.StatusInternalServerError)
return
}
resp.AuthURL = "" resp.AuthURL = ""
resp.MachineAuthorized = false resp.MachineAuthorized = false
@ -366,7 +402,7 @@ func (h *Headscale) handleNoiseNodeLogOut(
writer.Header().Set("Content-Type", "application/json") writer.Header().Set("Content-Type", "application/json")
writer.WriteHeader(http.StatusOK) writer.WriteHeader(http.StatusOK)
err := json.NewEncoder(writer).Encode(resp) err = json.NewEncoder(writer).Encode(resp)
if err != nil { if err != nil {
log.Error(). log.Error().
Caller(). Caller().