Fixed some linting errors
This commit is contained in:
parent
39b85b02bb
commit
9994fce9d5
1 changed files with 41 additions and 32 deletions
73
noise_api.go
73
noise_api.go
|
@ -14,7 +14,7 @@ import (
|
||||||
"tailscale.com/tailcfg"
|
"tailscale.com/tailcfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
// // NoiseRegistrationHandler handles the actual registration process of a machine
|
// // NoiseRegistrationHandler handles the actual registration process of a machine.
|
||||||
func (h *Headscale) NoiseRegistrationHandler(
|
func (h *Headscale) NoiseRegistrationHandler(
|
||||||
writer http.ResponseWriter,
|
writer http.ResponseWriter,
|
||||||
req *http.Request,
|
req *http.Request,
|
||||||
|
@ -175,8 +175,8 @@ func (h *Headscale) NoiseRegistrationHandler(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Headscale) handleNoiseAuthKey(
|
func (h *Headscale) handleNoiseAuthKey(
|
||||||
w http.ResponseWriter,
|
writer http.ResponseWriter,
|
||||||
r *http.Request,
|
req *http.Request,
|
||||||
registerRequest tailcfg.RegisterRequest,
|
registerRequest tailcfg.RegisterRequest,
|
||||||
) {
|
) {
|
||||||
log.Debug().
|
log.Debug().
|
||||||
|
@ -194,9 +194,9 @@ func (h *Headscale) handleNoiseAuthKey(
|
||||||
Msg("Failed authentication via AuthKey")
|
Msg("Failed authentication via AuthKey")
|
||||||
resp.MachineAuthorized = false
|
resp.MachineAuthorized = false
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
writer.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
writer.WriteHeader(http.StatusUnauthorized)
|
||||||
json.NewEncoder(w).Encode(resp)
|
json.NewEncoder(writer).Encode(resp)
|
||||||
|
|
||||||
log.Error().
|
log.Error().
|
||||||
Caller().
|
Caller().
|
||||||
|
@ -270,7 +270,7 @@ func (h *Headscale) handleNoiseAuthKey(
|
||||||
Msg("could not register machine")
|
Msg("could not register machine")
|
||||||
machineRegistrations.WithLabelValues("new", RegisterMethodAuthKey, "error", pak.Namespace.Name).
|
machineRegistrations.WithLabelValues("new", RegisterMethodAuthKey, "error", pak.Namespace.Name).
|
||||||
Inc()
|
Inc()
|
||||||
http.Error(w, "Internal error", http.StatusInternalServerError)
|
http.Error(writer, "Internal error", http.StatusInternalServerError)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -284,9 +284,9 @@ func (h *Headscale) handleNoiseAuthKey(
|
||||||
machineRegistrations.WithLabelValues("new", RegisterMethodAuthKey, "success", pak.Namespace.Name).
|
machineRegistrations.WithLabelValues("new", RegisterMethodAuthKey, "success", pak.Namespace.Name).
|
||||||
Inc()
|
Inc()
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
writer.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusOK)
|
writer.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(resp)
|
json.NewEncoder(writer).Encode(resp)
|
||||||
|
|
||||||
log.Info().
|
log.Info().
|
||||||
Caller().
|
Caller().
|
||||||
|
@ -320,8 +320,8 @@ func (h *Headscale) handleNoiseNodeValidRegistration(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Headscale) handleNoiseMachineRegistrationNew(
|
func (h *Headscale) handleNoiseMachineRegistrationNew(
|
||||||
w http.ResponseWriter,
|
writer http.ResponseWriter,
|
||||||
r *http.Request,
|
req *http.Request,
|
||||||
registerRequest tailcfg.RegisterRequest,
|
registerRequest tailcfg.RegisterRequest,
|
||||||
) {
|
) {
|
||||||
resp := tailcfg.RegisterResponse{}
|
resp := tailcfg.RegisterResponse{}
|
||||||
|
@ -337,18 +337,18 @@ func (h *Headscale) handleNoiseMachineRegistrationNew(
|
||||||
NodePublicKeyStripPrefix(registerRequest.NodeKey),
|
NodePublicKeyStripPrefix(registerRequest.NodeKey),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
resp.AuthURL = fmt.Sprintf("%s/register?key=%s",
|
resp.AuthURL = fmt.Sprintf("%s/register/%s",
|
||||||
strings.TrimSuffix(h.cfg.ServerURL, "/"), NodePublicKeyStripPrefix(registerRequest.NodeKey))
|
strings.TrimSuffix(h.cfg.ServerURL, "/"), NodePublicKeyStripPrefix(registerRequest.NodeKey))
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
writer.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusOK)
|
writer.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(resp)
|
json.NewEncoder(writer).Encode(resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Headscale) handleNoiseNodeLogOut(
|
func (h *Headscale) handleNoiseNodeLogOut(
|
||||||
w http.ResponseWriter,
|
writer http.ResponseWriter,
|
||||||
r *http.Request,
|
req *http.Request,
|
||||||
machine Machine,
|
machine Machine,
|
||||||
) {
|
) {
|
||||||
resp := tailcfg.RegisterResponse{}
|
resp := tailcfg.RegisterResponse{}
|
||||||
|
@ -363,14 +363,20 @@ func (h *Headscale) handleNoiseNodeLogOut(
|
||||||
resp.MachineAuthorized = false
|
resp.MachineAuthorized = false
|
||||||
resp.User = *machine.Namespace.toUser()
|
resp.User = *machine.Namespace.toUser()
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
writer.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusOK)
|
writer.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(resp)
|
err := json.NewEncoder(writer).Encode(resp)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().
|
||||||
|
Caller().
|
||||||
|
Err(err).
|
||||||
|
Msg("could not encode response")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Headscale) handleNoiseNodeRefreshKey(
|
func (h *Headscale) handleNoiseNodeRefreshKey(
|
||||||
w http.ResponseWriter,
|
writer http.ResponseWriter,
|
||||||
r *http.Request,
|
req *http.Request,
|
||||||
registerRequest tailcfg.RegisterRequest,
|
registerRequest tailcfg.RegisterRequest,
|
||||||
machine Machine,
|
machine Machine,
|
||||||
) {
|
) {
|
||||||
|
@ -385,14 +391,14 @@ func (h *Headscale) handleNoiseNodeRefreshKey(
|
||||||
resp.AuthURL = ""
|
resp.AuthURL = ""
|
||||||
resp.User = *machine.Namespace.toUser()
|
resp.User = *machine.Namespace.toUser()
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
writer.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusOK)
|
writer.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(resp)
|
json.NewEncoder(writer).Encode(resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Headscale) handleNoiseNodeExpired(
|
func (h *Headscale) handleNoiseNodeExpired(
|
||||||
w http.ResponseWriter,
|
writer http.ResponseWriter,
|
||||||
r *http.Request,
|
req *http.Request,
|
||||||
registerRequest tailcfg.RegisterRequest,
|
registerRequest tailcfg.RegisterRequest,
|
||||||
machine Machine,
|
machine Machine,
|
||||||
) {
|
) {
|
||||||
|
@ -405,7 +411,7 @@ func (h *Headscale) handleNoiseNodeExpired(
|
||||||
Msg("Machine registration has expired. Sending a authurl to register")
|
Msg("Machine registration has expired. Sending a authurl to register")
|
||||||
|
|
||||||
if registerRequest.Auth.AuthKey != "" {
|
if registerRequest.Auth.AuthKey != "" {
|
||||||
h.handleNoiseAuthKey(w, r, registerRequest)
|
h.handleNoiseAuthKey(writer, req, registerRequest)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -421,7 +427,10 @@ func (h *Headscale) handleNoiseNodeExpired(
|
||||||
machineRegistrations.WithLabelValues("reauth", "web", "success", machine.Namespace.Name).
|
machineRegistrations.WithLabelValues("reauth", "web", "success", machine.Namespace.Name).
|
||||||
Inc()
|
Inc()
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
writer.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusOK)
|
writer.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(resp)
|
err := json.NewEncoder(writer).Encode(resp)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Caller().Err(err).Msg("Failed to encode response")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue