mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-29 18:33:05 +00:00
Lint fixes 1/n
This commit is contained in:
parent
58c336e7f4
commit
10cd87e5a2
9 changed files with 81 additions and 80 deletions
2
acls.go
2
acls.go
|
@ -37,7 +37,7 @@ const (
|
||||||
expectedTokenItems = 2
|
expectedTokenItems = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
// For some reason golang.org/x/net/internal/iana is an internal package
|
// For some reason golang.org/x/net/internal/iana is an internal package.
|
||||||
const (
|
const (
|
||||||
protocolICMP = 1 // Internet Control Message
|
protocolICMP = 1 // Internet Control Message
|
||||||
protocolIGMP = 2 // Internet Group Management
|
protocolIGMP = 2 // Internet Group Management
|
||||||
|
|
1
db.go
1
db.go
|
@ -111,7 +111,6 @@ func (h *Headscale) initDB() error {
|
||||||
Err(err).
|
Err(err).
|
||||||
Msg("Failed to save normalized machine name in DB migration")
|
Msg("Failed to save normalized machine name in DB migration")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,6 +89,7 @@ func (h *Headscale) generateRegionLocalDERP() (tailcfg.DERPRegion, error) {
|
||||||
localDERPregion.Nodes[0].STUNPort = portSTUN
|
localDERPregion.Nodes[0].STUNPort = portSTUN
|
||||||
|
|
||||||
log.Info().Caller().Msgf("DERP region: %+v", localDERPregion)
|
log.Info().Caller().Msgf("DERP region: %+v", localDERPregion)
|
||||||
|
|
||||||
return localDERPregion, nil
|
return localDERPregion, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,16 +151,16 @@ func (h *Headscale) DERPHandler(
|
||||||
// DERPProbeHandler is the endpoint that js/wasm clients hit to measure
|
// DERPProbeHandler is the endpoint that js/wasm clients hit to measure
|
||||||
// DERP latency, since they can't do UDP STUN queries.
|
// DERP latency, since they can't do UDP STUN queries.
|
||||||
func (h *Headscale) DERPProbeHandler(
|
func (h *Headscale) DERPProbeHandler(
|
||||||
w http.ResponseWriter,
|
writer http.ResponseWriter,
|
||||||
r *http.Request,
|
req *http.Request,
|
||||||
) {
|
) {
|
||||||
switch r.Method {
|
switch req.Method {
|
||||||
case "HEAD", "GET":
|
case "HEAD", "GET":
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
writer.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
w.WriteHeader(http.StatusOK)
|
writer.WriteHeader(http.StatusOK)
|
||||||
default:
|
default:
|
||||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
writer.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
w.Write([]byte("bogus probe method"))
|
writer.Write([]byte("bogus probe method"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,8 +172,8 @@ func (h *Headscale) DERPProbeHandler(
|
||||||
// They have a cache, but not clear if that is really necessary at Headscale, uh, scale.
|
// They have a cache, but not clear if that is really necessary at Headscale, uh, scale.
|
||||||
// An example implementation is found here https://derp.tailscale.com/bootstrap-dns
|
// An example implementation is found here https://derp.tailscale.com/bootstrap-dns
|
||||||
func (h *Headscale) DERPBootstrapDNSHandler(
|
func (h *Headscale) DERPBootstrapDNSHandler(
|
||||||
w http.ResponseWriter,
|
writer http.ResponseWriter,
|
||||||
r *http.Request,
|
req *http.Request,
|
||||||
) {
|
) {
|
||||||
dnsEntries := make(map[string][]net.IP)
|
dnsEntries := make(map[string][]net.IP)
|
||||||
|
|
||||||
|
@ -193,9 +194,9 @@ func (h *Headscale) DERPBootstrapDNSHandler(
|
||||||
dnsEntries[node.HostName] = addrs
|
dnsEntries[node.HostName] = addrs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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(dnsEntries)
|
json.NewEncoder(writer).Encode(dnsEntries)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServeSTUN starts a STUN server on the configured addr.
|
// ServeSTUN starts a STUN server on the configured addr.
|
||||||
|
|
|
@ -27,6 +27,7 @@ const (
|
||||||
errCouldNotConvertMachineInterface = Error("failed to convert machine interface")
|
errCouldNotConvertMachineInterface = Error("failed to convert machine interface")
|
||||||
errHostnameTooLong = Error("Hostname too long")
|
errHostnameTooLong = Error("Hostname too long")
|
||||||
MachineGivenNameHashLength = 8
|
MachineGivenNameHashLength = 8
|
||||||
|
MachineGivenNameTrimSize = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -898,7 +899,7 @@ func (machine *Machine) RoutesToProto() *v1.Routes {
|
||||||
func (h *Headscale) GenerateGivenName(suppliedName string) (string, error) {
|
func (h *Headscale) GenerateGivenName(suppliedName string) (string, error) {
|
||||||
// If a hostname is or will be longer than 63 chars after adding the hash,
|
// If a hostname is or will be longer than 63 chars after adding the hash,
|
||||||
// it needs to be trimmed.
|
// it needs to be trimmed.
|
||||||
trimmedHostnameLength := labelHostnameLength - MachineGivenNameHashLength - 2
|
trimmedHostnameLength := labelHostnameLength - MachineGivenNameHashLength - MachineGivenNameTrimSize
|
||||||
|
|
||||||
normalizedHostname, err := NormalizeToFQDNRules(
|
normalizedHostname, err := NormalizeToFQDNRules(
|
||||||
suppliedName,
|
suppliedName,
|
||||||
|
|
|
@ -918,6 +918,7 @@ func TestHeadscale_GenerateGivenName(t *testing.T) {
|
||||||
err,
|
err,
|
||||||
tt.wantErr,
|
tt.wantErr,
|
||||||
)
|
)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,8 @@ import (
|
||||||
|
|
||||||
// WindowsConfigMessage shows a simple message in the browser for how to configure the Windows Tailscale client.
|
// WindowsConfigMessage shows a simple message in the browser for how to configure the Windows Tailscale client.
|
||||||
func (h *Headscale) WindowsConfigMessage(
|
func (h *Headscale) WindowsConfigMessage(
|
||||||
w http.ResponseWriter,
|
writer http.ResponseWriter,
|
||||||
r *http.Request,
|
req *http.Request,
|
||||||
) {
|
) {
|
||||||
winTemplate := template.Must(template.New("windows").Parse(`
|
winTemplate := template.Must(template.New("windows").Parse(`
|
||||||
<html>
|
<html>
|
||||||
|
@ -67,22 +67,22 @@ REG ADD "HKLM\Software\Tailscale IPN" /v LoginURL /t REG_SZ /d "{{.URL}}"</code>
|
||||||
Err(err).
|
Err(err).
|
||||||
Msg("Could not render Windows index template")
|
Msg("Could not render Windows index template")
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
writer.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
writer.WriteHeader(http.StatusInternalServerError)
|
||||||
w.Write([]byte("Could not render Windows index template"))
|
writer.Write([]byte("Could not render Windows index template"))
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
writer.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusOK)
|
writer.WriteHeader(http.StatusOK)
|
||||||
w.Write(payload.Bytes())
|
writer.Write(payload.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
// WindowsRegConfig generates and serves a .reg file configured with the Headscale server address.
|
// WindowsRegConfig generates and serves a .reg file configured with the Headscale server address.
|
||||||
func (h *Headscale) WindowsRegConfig(
|
func (h *Headscale) WindowsRegConfig(
|
||||||
w http.ResponseWriter,
|
writer http.ResponseWriter,
|
||||||
r *http.Request,
|
req *http.Request,
|
||||||
) {
|
) {
|
||||||
config := WindowsRegistryConfig{
|
config := WindowsRegistryConfig{
|
||||||
URL: h.cfg.ServerURL,
|
URL: h.cfg.ServerURL,
|
||||||
|
@ -95,22 +95,22 @@ func (h *Headscale) WindowsRegConfig(
|
||||||
Err(err).
|
Err(err).
|
||||||
Msg("Could not render Apple macOS template")
|
Msg("Could not render Apple macOS template")
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
writer.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
writer.WriteHeader(http.StatusInternalServerError)
|
||||||
w.Write([]byte("Could not render Windows registry template"))
|
writer.Write([]byte("Could not render Windows registry template"))
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "text/x-ms-regedit; charset=utf-8")
|
writer.Header().Set("Content-Type", "text/x-ms-regedit; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusOK)
|
writer.WriteHeader(http.StatusOK)
|
||||||
w.Write(content.Bytes())
|
writer.Write(content.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppleConfigMessage shows a simple message in the browser to point the user to the iOS/MacOS profile and instructions for how to install it.
|
// AppleConfigMessage shows a simple message in the browser to point the user to the iOS/MacOS profile and instructions for how to install it.
|
||||||
func (h *Headscale) AppleConfigMessage(
|
func (h *Headscale) AppleConfigMessage(
|
||||||
w http.ResponseWriter,
|
writer http.ResponseWriter,
|
||||||
r *http.Request,
|
req *http.Request,
|
||||||
) {
|
) {
|
||||||
appleTemplate := template.Must(template.New("apple").Parse(`
|
appleTemplate := template.Must(template.New("apple").Parse(`
|
||||||
<html>
|
<html>
|
||||||
|
@ -173,29 +173,29 @@ func (h *Headscale) AppleConfigMessage(
|
||||||
Err(err).
|
Err(err).
|
||||||
Msg("Could not render Apple index template")
|
Msg("Could not render Apple index template")
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
writer.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
writer.WriteHeader(http.StatusInternalServerError)
|
||||||
w.Write([]byte("Could not render Apple index template"))
|
writer.Write([]byte("Could not render Apple index template"))
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
writer.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusOK)
|
writer.WriteHeader(http.StatusOK)
|
||||||
w.Write(payload.Bytes())
|
writer.Write(payload.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Headscale) ApplePlatformConfig(
|
func (h *Headscale) ApplePlatformConfig(
|
||||||
w http.ResponseWriter,
|
writer http.ResponseWriter,
|
||||||
r *http.Request,
|
req *http.Request,
|
||||||
) {
|
) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(req)
|
||||||
platform, ok := vars["platform"]
|
platform, ok := vars["platform"]
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Error().
|
log.Error().
|
||||||
Str("handler", "ApplePlatformConfig").
|
Str("handler", "ApplePlatformConfig").
|
||||||
Msg("No platform specified")
|
Msg("No platform specified")
|
||||||
http.Error(w, "No platform specified", http.StatusBadRequest)
|
http.Error(writer, "No platform specified", http.StatusBadRequest)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -207,9 +207,9 @@ func (h *Headscale) ApplePlatformConfig(
|
||||||
Err(err).
|
Err(err).
|
||||||
Msg("Failed not create UUID")
|
Msg("Failed not create UUID")
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
writer.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
writer.WriteHeader(http.StatusInternalServerError)
|
||||||
w.Write([]byte("Failed to create UUID"))
|
writer.Write([]byte("Failed to create UUID"))
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -221,9 +221,9 @@ func (h *Headscale) ApplePlatformConfig(
|
||||||
Err(err).
|
Err(err).
|
||||||
Msg("Failed not create UUID")
|
Msg("Failed not create UUID")
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
writer.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
writer.WriteHeader(http.StatusInternalServerError)
|
||||||
w.Write([]byte("Failed to create content UUID"))
|
writer.Write([]byte("Failed to create content UUID"))
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -243,9 +243,9 @@ func (h *Headscale) ApplePlatformConfig(
|
||||||
Err(err).
|
Err(err).
|
||||||
Msg("Could not render Apple macOS template")
|
Msg("Could not render Apple macOS template")
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
writer.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
writer.WriteHeader(http.StatusInternalServerError)
|
||||||
w.Write([]byte("Could not render Apple macOS template"))
|
writer.Write([]byte("Could not render Apple macOS template"))
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -256,16 +256,16 @@ func (h *Headscale) ApplePlatformConfig(
|
||||||
Err(err).
|
Err(err).
|
||||||
Msg("Could not render Apple iOS template")
|
Msg("Could not render Apple iOS template")
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
writer.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
writer.WriteHeader(http.StatusInternalServerError)
|
||||||
w.Write([]byte("Could not render Apple iOS template"))
|
writer.Write([]byte("Could not render Apple iOS template"))
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
writer.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
writer.WriteHeader(http.StatusBadRequest)
|
||||||
w.Write([]byte("Invalid platform, only ios and macos is supported"))
|
writer.Write([]byte("Invalid platform, only ios and macos is supported"))
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -283,16 +283,16 @@ func (h *Headscale) ApplePlatformConfig(
|
||||||
Err(err).
|
Err(err).
|
||||||
Msg("Could not render Apple platform template")
|
Msg("Could not render Apple platform template")
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
writer.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
writer.WriteHeader(http.StatusInternalServerError)
|
||||||
w.Write([]byte("Could not render Apple platform template"))
|
writer.Write([]byte("Could not render Apple platform template"))
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/x-apple-aspen-config; charset=utf-8")
|
writer.Header().Set("Content-Type", "application/x-apple-aspen-config; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusOK)
|
writer.WriteHeader(http.StatusOK)
|
||||||
w.Write(content.Bytes())
|
writer.Write(content.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
type WindowsRegistryConfig struct {
|
type WindowsRegistryConfig struct {
|
||||||
|
|
1
poll.go
1
poll.go
|
@ -527,7 +527,6 @@ func (h *Headscale) PollNetMapStream(
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
var lastUpdate time.Time
|
var lastUpdate time.Time
|
||||||
if machine.LastSuccessfulUpdate != nil {
|
if machine.LastSuccessfulUpdate != nil {
|
||||||
|
|
|
@ -28,7 +28,7 @@ func (s *Suite) TestGetRoutes(c *check.C) {
|
||||||
MachineKey: "foo",
|
MachineKey: "foo",
|
||||||
NodeKey: "bar",
|
NodeKey: "bar",
|
||||||
DiscoKey: "faa",
|
DiscoKey: "faa",
|
||||||
Hostname: "test_get_route_machine",
|
Hostname: "test_get_route_machine",
|
||||||
NamespaceID: namespace.ID,
|
NamespaceID: namespace.ID,
|
||||||
RegisterMethod: RegisterMethodAuthKey,
|
RegisterMethod: RegisterMethodAuthKey,
|
||||||
AuthKeyID: uint(pak.ID),
|
AuthKeyID: uint(pak.ID),
|
||||||
|
@ -79,7 +79,7 @@ func (s *Suite) TestGetEnableRoutes(c *check.C) {
|
||||||
MachineKey: "foo",
|
MachineKey: "foo",
|
||||||
NodeKey: "bar",
|
NodeKey: "bar",
|
||||||
DiscoKey: "faa",
|
DiscoKey: "faa",
|
||||||
Hostname: "test_enable_route_machine",
|
Hostname: "test_enable_route_machine",
|
||||||
NamespaceID: namespace.ID,
|
NamespaceID: namespace.ID,
|
||||||
RegisterMethod: RegisterMethodAuthKey,
|
RegisterMethod: RegisterMethodAuthKey,
|
||||||
AuthKeyID: uint(pak.ID),
|
AuthKeyID: uint(pak.ID),
|
||||||
|
|
26
swagger.go
26
swagger.go
|
@ -13,8 +13,8 @@ import (
|
||||||
var apiV1JSON []byte
|
var apiV1JSON []byte
|
||||||
|
|
||||||
func SwaggerUI(
|
func SwaggerUI(
|
||||||
w http.ResponseWriter,
|
writer http.ResponseWriter,
|
||||||
r *http.Request,
|
req *http.Request,
|
||||||
) {
|
) {
|
||||||
swaggerTemplate := template.Must(template.New("swagger").Parse(`
|
swaggerTemplate := template.Must(template.New("swagger").Parse(`
|
||||||
<html>
|
<html>
|
||||||
|
@ -55,23 +55,23 @@ func SwaggerUI(
|
||||||
Err(err).
|
Err(err).
|
||||||
Msg("Could not render Swagger")
|
Msg("Could not render Swagger")
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
writer.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
writer.WriteHeader(http.StatusInternalServerError)
|
||||||
w.Write([]byte("Could not render Swagger"))
|
writer.Write([]byte("Could not render Swagger"))
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
writer.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusOK)
|
writer.WriteHeader(http.StatusOK)
|
||||||
w.Write(payload.Bytes())
|
writer.Write(payload.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
func SwaggerAPIv1(
|
func SwaggerAPIv1(
|
||||||
w http.ResponseWriter,
|
writer http.ResponseWriter,
|
||||||
r *http.Request,
|
req *http.Request,
|
||||||
) {
|
) {
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-88")
|
writer.Header().Set("Content-Type", "application/json; charset=utf-88")
|
||||||
w.WriteHeader(http.StatusOK)
|
writer.WriteHeader(http.StatusOK)
|
||||||
w.Write(apiV1JSON)
|
writer.Write(apiV1JSON)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue