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

feat: add validation of tags

This commit is contained in:
Adrien Raffin-Caboisse 2022-05-13 10:17:52 +02:00
parent fdbc9657bc
commit 62cfd60e38
No known key found for this signature in database
GPG Key ID: 7FB60532DEBEAD6A
2 changed files with 10 additions and 4 deletions

View File

@ -543,6 +543,8 @@ var tagCmd = &cobra.Command{
fmt.Sprintf("Error while sending tags to headscale: %s", err),
output,
)
return
}
if resp != nil {

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:'",
)
}
}