From 62cfd60e38fc24f7335e3b2ffd0d8ccb0e4fe11b Mon Sep 17 00:00:00 2001 From: Adrien Raffin-Caboisse Date: Fri, 13 May 2022 10:17:52 +0200 Subject: [PATCH] feat: add validation of tags --- cmd/headscale/cli/nodes.go | 2 ++ grpcv1.go | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cmd/headscale/cli/nodes.go b/cmd/headscale/cli/nodes.go index 6397c9da..51dbd2c3 100644 --- a/cmd/headscale/cli/nodes.go +++ b/cmd/headscale/cli/nodes.go @@ -543,6 +543,8 @@ var tagCmd = &cobra.Command{ fmt.Sprintf("Error while sending tags to headscale: %s", err), output, ) + + return } if resp != nil { diff --git a/grpcv1.go b/grpcv1.go index e008a4f1..fb6d8e98 100644 --- a/grpcv1.go +++ b/grpcv1.go @@ -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:'", + ) } }