feat: add validation of tags

This commit is contained in:
Adrien Raffin-Caboisse committed 2022-05-13 10:18:01 +02:00
1 parent fdbc9657bc
commit 62cfd60e38
2 files changed
+10 -4

No files matched your search

+8 -4
View File
@@ -8,6 +8,8 @@ import (
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
"github.com/rs/zerolog/log"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"tailscale.com/tailcfg"
)
@@ -194,10 +196,12 @@ func (api headscaleV1APIServer) SetTags(
for _, tag := range request.GetTags() {
if strings.Index(tag, "tag:") != 0 {
return &v1.SetTagsResponse{Machine: nil, Error: &v1.Error{
Status: 400,
Message: "Invalid tag detected. Each tag must start with the string 'tag:'",
}}, nil
return &v1.SetTagsResponse{
Machine: nil,
}, status.Error(
codes.InvalidArgument,
"Invalid tag detected. Each tag must start with the string 'tag:'",
)
}
}