chore: update formating

This commit is contained in:
Adrien Raffin-Caboisse 2022-02-22 21:05:39 +01:00
parent 717250adb3
commit afd4a3706e
3 changed files with 9 additions and 4 deletions

View file

@ -22,6 +22,11 @@ const (
errInvalidNamespaceName = Error("Invalid namespace name") errInvalidNamespaceName = Error("Invalid namespace name")
) )
const (
// value related to RFC 1123 and 952.
labelHostnameLength = 63
)
var normalizeNamespaceRegex = regexp.MustCompile("[^a-z0-9-.]+") var normalizeNamespaceRegex = regexp.MustCompile("[^a-z0-9-.]+")
// Namespace is the way Headscale implements the concept of users in Tailscale // 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 // 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) { func NormalizeNamespaceName(name string) (string, error) {
name = strings.ToLower(name) name = strings.ToLower(name)
name = strings.ReplaceAll(name, "@", ".") name = strings.ReplaceAll(name, "@", ".")
@ -279,7 +284,7 @@ func NormalizeNamespaceName(name string) (string, error) {
name = normalizeNamespaceRegex.ReplaceAllString(name, "-") name = normalizeNamespaceRegex.ReplaceAllString(name, "-")
for _, elt := range strings.Split(name, ".") { for _, elt := range strings.Split(name, ".") {
if len(elt) > 63 { if len(elt) > labelHostnameLength {
return "", fmt.Errorf( return "", fmt.Errorf(
"label %v is more than 63 chars: %w", "label %v is more than 63 chars: %w",
elt, elt,

View file

@ -292,6 +292,7 @@ func TestNormalizeNamespaceName(t *testing.T) {
err, err,
tt.wantErr, tt.wantErr,
) )
return return
} }
if got != tt.want { if got != tt.want {

View file

@ -288,6 +288,7 @@ func (h *Headscale) OIDCCallback(ctx *gin.Context) {
http.StatusInternalServerError, http.StatusInternalServerError,
"couldn't normalize email", "couldn't normalize email",
) )
return return
} }
// register the machine if it's new // 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()) ctx.Data(http.StatusOK, "text/html; charset=utf-8", content.Bytes())
return
} }