mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-23 18:15:26 +00:00
And more linting stuff
This commit is contained in:
parent
3bea20850a
commit
eb8d8f142c
5
noise.go
5
noise.go
@ -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
|
||||||
|
46
noise_api.go
46
noise_api.go
@ -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().
|
||||||
|
Loading…
Reference in New Issue
Block a user