From fdbc9657bcaa5d511452639152a2bb82e6de534a Mon Sep 17 00:00:00 2001 From: Adrien Raffin-Caboisse Date: Fri, 13 May 2022 09:47:34 +0200 Subject: [PATCH] feat: return error if validation is failed --- grpcv1.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/grpcv1.go b/grpcv1.go index 83cd5bf2..e008a4f1 100644 --- a/grpcv1.go +++ b/grpcv1.go @@ -3,6 +3,7 @@ package headscale import ( "context" + "strings" "time" v1 "github.com/juanfont/headscale/gen/go/headscale/v1" @@ -191,6 +192,15 @@ func (api headscaleV1APIServer) SetTags( return nil, err } + 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 + } + } + api.h.SetTags(machine, request.GetTags()) log.Trace().