1
0
mirror of https://github.com/juanfont/headscale.git synced 2024-12-20 19:09:07 +01:00

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")
)
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,

View File

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

View File

@ -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
}