add regex check for tag name

This commit is contained in:
abhishek9686 2024-09-28 18:38:49 +04:00
parent 9f921beb60
commit 025167f115
2 changed files with 6 additions and 15 deletions

View file

@ -4,8 +4,8 @@ import (
"encoding/json"
"errors"
"fmt"
"regexp"
"sort"
"strings"
"sync"
"github.com/gravitl/netmaker/database"
@ -192,11 +192,12 @@ func CheckIDSyntax(id string) error {
if len(id) < 3 {
return errors.New("name should have min 3 characters")
}
if HasSymbol(id) {
return errors.New("symbols are not allowed")
reg, err := regexp.Compile("^[a-zA-Z-]+$")
if err != nil {
return err
}
if strings.Contains(id, ".") {
return errors.New("dots not allowed")
if !reg.MatchString(id) {
return errors.New("invalid name. allowed characters are [a-zA-Z-]")
}
return nil
}

View file

@ -10,7 +10,6 @@ import (
"os"
"strings"
"time"
"unicode"
"github.com/c-robinson/iplib"
"github.com/gravitl/netmaker/database"
@ -149,13 +148,4 @@ func IsSlicesEqual(a, b []string) bool {
return true
}
func HasSymbol(str string) bool {
for _, letter := range str {
if unicode.IsSymbol(letter) {
return true
}
}
return false
}
// == private ==