diff --git a/acls.go b/acls.go index c7a84af..b485ce3 100644 --- a/acls.go +++ b/acls.go @@ -37,7 +37,7 @@ const ( 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 ( protocolICMP = 1 // Internet Control Message protocolIGMP = 2 // Internet Group Management diff --git a/db.go b/db.go index 17d8323..b3222d0 100644 --- a/db.go +++ b/db.go @@ -111,7 +111,6 @@ func (h *Headscale) initDB() error { Err(err). Msg("Failed to save normalized machine name in DB migration") } - } } } diff --git a/derp_server.go b/derp_server.go index 9f99033..97a6fc0 100644 --- a/derp_server.go +++ b/derp_server.go @@ -89,6 +89,7 @@ func (h *Headscale) generateRegionLocalDERP() (tailcfg.DERPRegion, error) { localDERPregion.Nodes[0].STUNPort = portSTUN log.Info().Caller().Msgf("DERP region: %+v", localDERPregion) + return localDERPregion, nil } @@ -150,16 +151,16 @@ func (h *Headscale) DERPHandler( // DERPProbeHandler is the endpoint that js/wasm clients hit to measure // DERP latency, since they can't do UDP STUN queries. func (h *Headscale) DERPProbeHandler( - w http.ResponseWriter, - r *http.Request, + writer http.ResponseWriter, + req *http.Request, ) { - switch r.Method { + switch req.Method { case "HEAD", "GET": - w.Header().Set("Access-Control-Allow-Origin", "*") - w.WriteHeader(http.StatusOK) + writer.Header().Set("Access-Control-Allow-Origin", "*") + writer.WriteHeader(http.StatusOK) default: - w.WriteHeader(http.StatusMethodNotAllowed) - w.Write([]byte("bogus probe method")) + writer.WriteHeader(http.StatusMethodNotAllowed) + 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. // An example implementation is found here https://derp.tailscale.com/bootstrap-dns func (h *Headscale) DERPBootstrapDNSHandler( - w http.ResponseWriter, - r *http.Request, + writer http.ResponseWriter, + req *http.Request, ) { dnsEntries := make(map[string][]net.IP) @@ -193,9 +194,9 @@ func (h *Headscale) DERPBootstrapDNSHandler( dnsEntries[node.HostName] = addrs } } - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - json.NewEncoder(w).Encode(dnsEntries) + writer.Header().Set("Content-Type", "application/json") + writer.WriteHeader(http.StatusOK) + json.NewEncoder(writer).Encode(dnsEntries) } // ServeSTUN starts a STUN server on the configured addr. diff --git a/machine.go b/machine.go index cf6b887..1bed295 100644 --- a/machine.go +++ b/machine.go @@ -27,6 +27,7 @@ const ( errCouldNotConvertMachineInterface = Error("failed to convert machine interface") errHostnameTooLong = Error("Hostname too long") MachineGivenNameHashLength = 8 + MachineGivenNameTrimSize = 2 ) const ( @@ -898,7 +899,7 @@ func (machine *Machine) RoutesToProto() *v1.Routes { func (h *Headscale) GenerateGivenName(suppliedName string) (string, error) { // If a hostname is or will be longer than 63 chars after adding the hash, // it needs to be trimmed. - trimmedHostnameLength := labelHostnameLength - MachineGivenNameHashLength - 2 + trimmedHostnameLength := labelHostnameLength - MachineGivenNameHashLength - MachineGivenNameTrimSize normalizedHostname, err := NormalizeToFQDNRules( suppliedName, diff --git a/machine_test.go b/machine_test.go index 48ccb15..0287b0c 100644 --- a/machine_test.go +++ b/machine_test.go @@ -918,6 +918,7 @@ func TestHeadscale_GenerateGivenName(t *testing.T) { err, tt.wantErr, ) + return } diff --git a/platform_config.go b/platform_config.go index e38996f..4aa58ec 100644 --- a/platform_config.go +++ b/platform_config.go @@ -13,8 +13,8 @@ import ( // WindowsConfigMessage shows a simple message in the browser for how to configure the Windows Tailscale client. func (h *Headscale) WindowsConfigMessage( - w http.ResponseWriter, - r *http.Request, + writer http.ResponseWriter, + req *http.Request, ) { winTemplate := template.Must(template.New("windows").Parse(` @@ -67,22 +67,22 @@ REG ADD "HKLM\Software\Tailscale IPN" /v LoginURL /t REG_SZ /d "{{.URL}}" Err(err). Msg("Could not render Windows index template") - w.Header().Set("Content-Type", "text/plain; charset=utf-8") - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte("Could not render Windows index template")) + writer.Header().Set("Content-Type", "text/plain; charset=utf-8") + writer.WriteHeader(http.StatusInternalServerError) + writer.Write([]byte("Could not render Windows index template")) return } - w.Header().Set("Content-Type", "text/html; charset=utf-8") - w.WriteHeader(http.StatusOK) - w.Write(payload.Bytes()) + writer.Header().Set("Content-Type", "text/html; charset=utf-8") + writer.WriteHeader(http.StatusOK) + writer.Write(payload.Bytes()) } // WindowsRegConfig generates and serves a .reg file configured with the Headscale server address. func (h *Headscale) WindowsRegConfig( - w http.ResponseWriter, - r *http.Request, + writer http.ResponseWriter, + req *http.Request, ) { config := WindowsRegistryConfig{ URL: h.cfg.ServerURL, @@ -95,22 +95,22 @@ func (h *Headscale) WindowsRegConfig( Err(err). Msg("Could not render Apple macOS template") - w.Header().Set("Content-Type", "text/plain; charset=utf-8") - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte("Could not render Windows registry template")) + writer.Header().Set("Content-Type", "text/plain; charset=utf-8") + writer.WriteHeader(http.StatusInternalServerError) + writer.Write([]byte("Could not render Windows registry template")) return } - w.Header().Set("Content-Type", "text/x-ms-regedit; charset=utf-8") - w.WriteHeader(http.StatusOK) - w.Write(content.Bytes()) + writer.Header().Set("Content-Type", "text/x-ms-regedit; charset=utf-8") + writer.WriteHeader(http.StatusOK) + 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. func (h *Headscale) AppleConfigMessage( - w http.ResponseWriter, - r *http.Request, + writer http.ResponseWriter, + req *http.Request, ) { appleTemplate := template.Must(template.New("apple").Parse(` @@ -173,29 +173,29 @@ func (h *Headscale) AppleConfigMessage( Err(err). Msg("Could not render Apple index template") - w.Header().Set("Content-Type", "text/plain; charset=utf-8") - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte("Could not render Apple index template")) + writer.Header().Set("Content-Type", "text/plain; charset=utf-8") + writer.WriteHeader(http.StatusInternalServerError) + writer.Write([]byte("Could not render Apple index template")) return } - w.Header().Set("Content-Type", "text/html; charset=utf-8") - w.WriteHeader(http.StatusOK) - w.Write(payload.Bytes()) + writer.Header().Set("Content-Type", "text/html; charset=utf-8") + writer.WriteHeader(http.StatusOK) + writer.Write(payload.Bytes()) } func (h *Headscale) ApplePlatformConfig( - w http.ResponseWriter, - r *http.Request, + writer http.ResponseWriter, + req *http.Request, ) { - vars := mux.Vars(r) + vars := mux.Vars(req) platform, ok := vars["platform"] if !ok { log.Error(). Str("handler", "ApplePlatformConfig"). Msg("No platform specified") - http.Error(w, "No platform specified", http.StatusBadRequest) + http.Error(writer, "No platform specified", http.StatusBadRequest) return } @@ -207,9 +207,9 @@ func (h *Headscale) ApplePlatformConfig( Err(err). Msg("Failed not create UUID") - w.Header().Set("Content-Type", "text/plain; charset=utf-8") - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte("Failed to create UUID")) + writer.Header().Set("Content-Type", "text/plain; charset=utf-8") + writer.WriteHeader(http.StatusInternalServerError) + writer.Write([]byte("Failed to create UUID")) return } @@ -221,9 +221,9 @@ func (h *Headscale) ApplePlatformConfig( Err(err). Msg("Failed not create UUID") - w.Header().Set("Content-Type", "text/plain; charset=utf-8") - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte("Failed to create content UUID")) + writer.Header().Set("Content-Type", "text/plain; charset=utf-8") + writer.WriteHeader(http.StatusInternalServerError) + writer.Write([]byte("Failed to create content UUID")) return } @@ -243,9 +243,9 @@ func (h *Headscale) ApplePlatformConfig( Err(err). Msg("Could not render Apple macOS template") - w.Header().Set("Content-Type", "text/plain; charset=utf-8") - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte("Could not render Apple macOS template")) + writer.Header().Set("Content-Type", "text/plain; charset=utf-8") + writer.WriteHeader(http.StatusInternalServerError) + writer.Write([]byte("Could not render Apple macOS template")) return } @@ -256,16 +256,16 @@ func (h *Headscale) ApplePlatformConfig( Err(err). Msg("Could not render Apple iOS template") - w.Header().Set("Content-Type", "text/plain; charset=utf-8") - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte("Could not render Apple iOS template")) + writer.Header().Set("Content-Type", "text/plain; charset=utf-8") + writer.WriteHeader(http.StatusInternalServerError) + writer.Write([]byte("Could not render Apple iOS template")) return } default: - w.Header().Set("Content-Type", "text/plain; charset=utf-8") - w.WriteHeader(http.StatusBadRequest) - w.Write([]byte("Invalid platform, only ios and macos is supported")) + writer.Header().Set("Content-Type", "text/plain; charset=utf-8") + writer.WriteHeader(http.StatusBadRequest) + writer.Write([]byte("Invalid platform, only ios and macos is supported")) return } @@ -283,16 +283,16 @@ func (h *Headscale) ApplePlatformConfig( Err(err). Msg("Could not render Apple platform template") - w.Header().Set("Content-Type", "text/plain; charset=utf-8") - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte("Could not render Apple platform template")) + writer.Header().Set("Content-Type", "text/plain; charset=utf-8") + writer.WriteHeader(http.StatusInternalServerError) + writer.Write([]byte("Could not render Apple platform template")) return } - w.Header().Set("Content-Type", "application/x-apple-aspen-config; charset=utf-8") - w.WriteHeader(http.StatusOK) - w.Write(content.Bytes()) + writer.Header().Set("Content-Type", "application/x-apple-aspen-config; charset=utf-8") + writer.WriteHeader(http.StatusOK) + writer.Write(content.Bytes()) } type WindowsRegistryConfig struct { diff --git a/poll.go b/poll.go index 394f1aa..bbe58c1 100644 --- a/poll.go +++ b/poll.go @@ -527,7 +527,6 @@ func (h *Headscale) PollNetMapStream( return } - } else { var lastUpdate time.Time if machine.LastSuccessfulUpdate != nil { diff --git a/routes_test.go b/routes_test.go index 0108d88..89b712b 100644 --- a/routes_test.go +++ b/routes_test.go @@ -28,7 +28,7 @@ func (s *Suite) TestGetRoutes(c *check.C) { MachineKey: "foo", NodeKey: "bar", DiscoKey: "faa", - Hostname: "test_get_route_machine", + Hostname: "test_get_route_machine", NamespaceID: namespace.ID, RegisterMethod: RegisterMethodAuthKey, AuthKeyID: uint(pak.ID), @@ -79,7 +79,7 @@ func (s *Suite) TestGetEnableRoutes(c *check.C) { MachineKey: "foo", NodeKey: "bar", DiscoKey: "faa", - Hostname: "test_enable_route_machine", + Hostname: "test_enable_route_machine", NamespaceID: namespace.ID, RegisterMethod: RegisterMethodAuthKey, AuthKeyID: uint(pak.ID), diff --git a/swagger.go b/swagger.go index 473c834..082117d 100644 --- a/swagger.go +++ b/swagger.go @@ -13,8 +13,8 @@ import ( var apiV1JSON []byte func SwaggerUI( - w http.ResponseWriter, - r *http.Request, + writer http.ResponseWriter, + req *http.Request, ) { swaggerTemplate := template.Must(template.New("swagger").Parse(` @@ -55,23 +55,23 @@ func SwaggerUI( Err(err). Msg("Could not render Swagger") - w.Header().Set("Content-Type", "text/plain; charset=utf-8") - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte("Could not render Swagger")) + writer.Header().Set("Content-Type", "text/plain; charset=utf-8") + writer.WriteHeader(http.StatusInternalServerError) + writer.Write([]byte("Could not render Swagger")) return } - w.Header().Set("Content-Type", "text/html; charset=utf-8") - w.WriteHeader(http.StatusOK) - w.Write(payload.Bytes()) + writer.Header().Set("Content-Type", "text/html; charset=utf-8") + writer.WriteHeader(http.StatusOK) + writer.Write(payload.Bytes()) } func SwaggerAPIv1( - w http.ResponseWriter, - r *http.Request, + writer http.ResponseWriter, + req *http.Request, ) { - w.Header().Set("Content-Type", "application/json; charset=utf-88") - w.WriteHeader(http.StatusOK) - w.Write(apiV1JSON) + writer.Header().Set("Content-Type", "application/json; charset=utf-88") + writer.WriteHeader(http.StatusOK) + writer.Write(apiV1JSON) }