tailcfg: add Hostinfo.CheckRequestTags helper method

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
Josh Bleecher Snyder 2020-11-03 16:10:23 -08:00
parent ed17f5ddae
commit fb9f80cd61

View File

@ -214,7 +214,7 @@ func (m MachineStatus) String() string {
func isNum(r rune) bool { return r >= '0' && r <= '9' } func isNum(r rune) bool { return r >= '0' && r <= '9' }
func isAlpha(r rune) bool { return (r >= 'A' && r <= 'Z') || (r >= 'a' && r <= 'z') } func isAlpha(r rune) bool { return (r >= 'A' && r <= 'Z') || (r >= 'a' && r <= 'z') }
// CheckTag valids whether a given string can be used as an ACL tag. // CheckTag validates tag for use as an ACL tag.
// For now we allow only ascii alphanumeric tags, and they need to start // For now we allow only ascii alphanumeric tags, and they need to start
// with a letter. No unicode shenanigans allowed, and we reserve punctuation // with a letter. No unicode shenanigans allowed, and we reserve punctuation
// marks other than '-' for a possible future URI scheme. // marks other than '-' for a possible future URI scheme.
@ -258,6 +258,20 @@ func CheckTagSuffix(tag string) error {
return nil return nil
} }
// CheckRequestTags checks that all of h.RequestTags are valid.
func (h *Hostinfo) CheckRequestTags() error {
if h == nil {
return nil
}
for _, tag := range h.RequestTags {
err := CheckTag(tag)
if err != nil {
return err
}
}
return nil
}
type ServiceProto string type ServiceProto string
const ( const (