fix: change normalization function name
This commit is contained in:
parent
6cc8bbc24f
commit
f19c048569
2
api.go
2
api.go
|
@ -134,7 +134,7 @@ func (h *Headscale) RegistrationHandler(ctx *gin.Context) {
|
|||
|
||||
return
|
||||
}
|
||||
hname, err := NormalizeName(
|
||||
hname, err := NormalizeToFQDNRules(
|
||||
req.Hostinfo.Hostname,
|
||||
h.cfg.OIDC.StripEmaildomain,
|
||||
)
|
||||
|
|
|
@ -41,7 +41,7 @@ type Namespace struct {
|
|||
// CreateNamespace creates a new Namespace. Returns error if could not be created
|
||||
// or another namespace already exists.
|
||||
func (h *Headscale) CreateNamespace(name string) (*Namespace, error) {
|
||||
err := CheckName(name)
|
||||
err := CheckForFQDNRules(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ func (h *Headscale) RenameNamespace(oldName, newName string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = CheckName(newName)
|
||||
err = CheckForFQDNRules(newName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ func (h *Headscale) ListNamespaces() ([]Namespace, error) {
|
|||
|
||||
// ListMachinesInNamespace gets all the nodes in a given namespace.
|
||||
func (h *Headscale) ListMachinesInNamespace(name string) ([]Machine, error) {
|
||||
err := CheckName(name)
|
||||
err := CheckForFQDNRules(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ func (h *Headscale) ListMachinesInNamespace(name string) ([]Machine, error) {
|
|||
|
||||
// SetMachineNamespace assigns a Machine to a namespace.
|
||||
func (h *Headscale) SetMachineNamespace(machine *Machine, namespaceName string) error {
|
||||
err := CheckName(namespaceName)
|
||||
err := CheckForFQDNRules(namespaceName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -237,9 +237,9 @@ func (n *Namespace) toProto() *v1.Namespace {
|
|||
}
|
||||
}
|
||||
|
||||
// NormalizeName will replace forbidden chars in namespace
|
||||
// NormalizeToFQDNRules will replace forbidden chars in namespace
|
||||
// it can also return an error if the namespace doesn't respect RFC 952 and 1123.
|
||||
func NormalizeName(name string, stripEmailDomain bool) (string, error) {
|
||||
func NormalizeToFQDNRules(name string, stripEmailDomain bool) (string, error) {
|
||||
name = strings.ToLower(name)
|
||||
name = strings.ReplaceAll(name, "'", "")
|
||||
atIdx := strings.Index(name, "@")
|
||||
|
@ -263,7 +263,7 @@ func NormalizeName(name string, stripEmailDomain bool) (string, error) {
|
|||
return name, nil
|
||||
}
|
||||
|
||||
func CheckName(name string) error {
|
||||
func CheckForFQDNRules(name string) error {
|
||||
if len(name) > labelHostnameLength {
|
||||
return fmt.Errorf(
|
||||
"Namespace must not be over 63 chars. %v doesn't comply with this rule: %w",
|
||||
|
|
|
@ -233,7 +233,7 @@ func (s *Suite) TestGetMapResponseUserProfiles(c *check.C) {
|
|||
c.Assert(found, check.Equals, true)
|
||||
}
|
||||
|
||||
func TestNormalizeName(t *testing.T) {
|
||||
func TestNormalizeToFQDNRules(t *testing.T) {
|
||||
type args struct {
|
||||
name string
|
||||
stripEmailDomain bool
|
||||
|
@ -310,10 +310,10 @@ func TestNormalizeName(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := NormalizeName(tt.args.name, tt.args.stripEmailDomain)
|
||||
got, err := NormalizeToFQDNRules(tt.args.name, tt.args.stripEmailDomain)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf(
|
||||
"NormalizeNamespaceName() error = %v, wantErr %v",
|
||||
"NormalizeToFQDNRules() error = %v, wantErr %v",
|
||||
err,
|
||||
tt.wantErr,
|
||||
)
|
||||
|
@ -321,13 +321,13 @@ func TestNormalizeName(t *testing.T) {
|
|||
return
|
||||
}
|
||||
if got != tt.want {
|
||||
t.Errorf("NormalizeNamespaceName() = %v, want %v", got, tt.want)
|
||||
t.Errorf("NormalizeToFQDNRules() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckName(t *testing.T) {
|
||||
func TestCheckForFQDNRules(t *testing.T) {
|
||||
type args struct {
|
||||
name string
|
||||
}
|
||||
|
@ -366,8 +366,8 @@ func TestCheckName(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if err := CheckName(tt.args.name); (err != nil) != tt.wantErr {
|
||||
t.Errorf("CheckNamespaceName() error = %v, wantErr %v", err, tt.wantErr)
|
||||
if err := CheckForFQDNRules(tt.args.name); (err != nil) != tt.wantErr {
|
||||
t.Errorf("CheckForFQDNRules() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue