From afd4a3706ebe1d93f4ee9c4714df8de9bc7f4715 Mon Sep 17 00:00:00 2001 From: Adrien Raffin-Caboisse Date: Tue, 22 Feb 2022 21:05:39 +0100 Subject: [PATCH] chore: update formating --- namespaces.go | 9 +++++++-- namespaces_test.go | 1 + oidc.go | 3 +-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/namespaces.go b/namespaces.go index 8160b031..ec674b91 100644 --- a/namespaces.go +++ b/namespaces.go @@ -22,6 +22,11 @@ const ( errInvalidNamespaceName = Error("Invalid namespace name") ) +const ( + // value related to RFC 1123 and 952. + labelHostnameLength = 63 +) + var normalizeNamespaceRegex = regexp.MustCompile("[^a-z0-9-.]+") // Namespace is the way Headscale implements the concept of users in Tailscale @@ -271,7 +276,7 @@ func (n *Namespace) toProto() *v1.Namespace { } // NormalizeNamespaceName will replace forbidden chars in namespace -// it can also return an error if the namespace doesn't respect RFC 952 and 1123 +// it can also return an error if the namespace doesn't respect RFC 952 and 1123. func NormalizeNamespaceName(name string) (string, error) { name = strings.ToLower(name) name = strings.ReplaceAll(name, "@", ".") @@ -279,7 +284,7 @@ func NormalizeNamespaceName(name string) (string, error) { name = normalizeNamespaceRegex.ReplaceAllString(name, "-") for _, elt := range strings.Split(name, ".") { - if len(elt) > 63 { + if len(elt) > labelHostnameLength { return "", fmt.Errorf( "label %v is more than 63 chars: %w", elt, diff --git a/namespaces_test.go b/namespaces_test.go index cf2b323e..d3519f9e 100644 --- a/namespaces_test.go +++ b/namespaces_test.go @@ -292,6 +292,7 @@ func TestNormalizeNamespaceName(t *testing.T) { err, tt.wantErr, ) + return } if got != tt.want { diff --git a/oidc.go b/oidc.go index 495832a5..78caa641 100644 --- a/oidc.go +++ b/oidc.go @@ -288,6 +288,7 @@ func (h *Headscale) OIDCCallback(ctx *gin.Context) { http.StatusInternalServerError, "couldn't normalize email", ) + return } // register the machine if it's new @@ -365,6 +366,4 @@ func (h *Headscale) OIDCCallback(ctx *gin.Context) { } ctx.Data(http.StatusOK, "text/html; charset=utf-8", content.Bytes()) - - return }