Add worker tagging (#862)

This allows workers to have tags assigned to them, which can then be filtered to control which targets they are allowed to serve.
This commit is contained in:
Jeff Mitchell authored and GitHub committed 2021-01-21 16:27:20 -05:00
1 parent 595a86508e
commit 717a3b52ee
54 files changed
+2150 -666

No files matched your search

+11
View File
@@ -6,6 +6,7 @@ import (
"fmt"
"sort"
"strings"
"unicode"
"github.com/hashicorp/errwrap"
glob "github.com/ryanuber/go-glob"
@@ -446,6 +447,16 @@ func Difference(a, b []string, lowercase bool) []string {
return items
}
// Printable returns true if all characters in the string are printable
// according to Unicode
func Printable(s string) bool {
return strings.IndexFunc(s, func(c rune) bool {
return !unicode.IsPrint(c)
}) == -1
}
// StringListToInterfaceList simply takes a []string and turns it into a
// []interface{} to satisfy the input requirements for other library functions
func StringListToInterfaceList(in []string) []interface{} {
ret := make([]interface{}, len(in))
for i, v := range in {
+35
View File
@@ -3,8 +3,11 @@ package strutil
import (
"encoding/base64"
"encoding/json"
"fmt"
"reflect"
"testing"
"github.com/stretchr/testify/require"
)
func TestStrUtil_StrListDelete(t *testing.T) {
@@ -598,3 +601,35 @@ func TestStrUtil_EqualStringMaps(t *testing.T) {
}
}
}
func TestPrintable(t *testing.T) {
cases := []struct {
input string
err bool
}{
{
input: "/valid",
},
{
input: "foobarvalid",
},
{
input: "/invalid\u000A",
err: true,
},
{
input: "/invalid\u000D",
err: true,
},
{
input: "/invalid\u0000",
err: true,
},
}
for i, tc := range cases {
t.Run(fmt.Sprint(i), func(t *testing.T) {
require.True(t, Printable(tc.input) != tc.err)
})
}
}