mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 11:38:02 +00:00
VAULT-7256 - Add CustomMetadata to Namespace type (#16491)
* remove CustomMetadata type * add custom metadata to namespace struct
This commit is contained in:
@@ -12,8 +12,9 @@ import (
|
||||
type contextValues struct{}
|
||||
|
||||
type Namespace struct {
|
||||
ID string `json:"id"`
|
||||
Path string `json:"path"`
|
||||
ID string `json:"id"`
|
||||
Path string `json:"path"`
|
||||
CustomMetadata map[string]string `json:"custom_metadata"`
|
||||
}
|
||||
|
||||
func (n *Namespace) String() string {
|
||||
@@ -28,8 +29,9 @@ var (
|
||||
contextNamespace contextValues = struct{}{}
|
||||
ErrNoNamespace error = errors.New("no namespace")
|
||||
RootNamespace *Namespace = &Namespace{
|
||||
ID: RootNamespaceID,
|
||||
Path: "",
|
||||
ID: RootNamespaceID,
|
||||
Path: "",
|
||||
CustomMetadata: make(map[string]string),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -7,10 +7,6 @@ import (
|
||||
"github.com/hashicorp/go-secure-stdlib/strutil"
|
||||
)
|
||||
|
||||
// CustomMetadata should be arbitrary user-provided key-value pairs meant to
|
||||
// provide supplemental information about a resource.
|
||||
type CustomMetadata map[string]string
|
||||
|
||||
// The following constants are used by Validate and are meant to be imposed
|
||||
// broadly for consistency.
|
||||
const (
|
||||
@@ -20,7 +16,9 @@ const (
|
||||
validationErrorPrefix = "custom_metadata validation failed"
|
||||
)
|
||||
|
||||
// Validate will perform input validation for custom metadata. If the key count
|
||||
// Validate will perform input validation for custom metadata.
|
||||
// CustomMetadata should be arbitrary user-provided key-value pairs meant to
|
||||
// provide supplemental information about a resource. If the key count
|
||||
// exceeds maxKeys, the validation will be short-circuited to prevent
|
||||
// unnecessary (and potentially costly) validation to be run. If the key count
|
||||
// falls at or below maxKeys, multiple checks will be made per key and value.
|
||||
@@ -28,7 +26,7 @@ const (
|
||||
// - 0 < length of key <= maxKeyLength
|
||||
// - 0 < length of value <= maxValueLength
|
||||
// - keys and values cannot include unprintable characters
|
||||
func Validate(cm CustomMetadata) error {
|
||||
func Validate(cm map[string]string) error {
|
||||
var errs *multierror.Error
|
||||
|
||||
if keyCount := len(cm); keyCount > maxKeys {
|
||||
|
||||
@@ -9,12 +9,12 @@ import (
|
||||
func TestValidate(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
input CustomMetadata
|
||||
input map[string]string
|
||||
shouldPass bool
|
||||
}{
|
||||
{
|
||||
"valid",
|
||||
CustomMetadata{
|
||||
map[string]string{
|
||||
"foo": "abc",
|
||||
"bar": "def",
|
||||
"baz": "ghi",
|
||||
@@ -23,8 +23,8 @@ func TestValidate(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"too_many_keys",
|
||||
func() CustomMetadata {
|
||||
cm := make(CustomMetadata)
|
||||
func() map[string]string {
|
||||
cm := make(map[string]string)
|
||||
|
||||
for i := 0; i < maxKeyLength+1; i++ {
|
||||
s := strconv.Itoa(i)
|
||||
@@ -37,28 +37,28 @@ func TestValidate(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"key_too_long",
|
||||
CustomMetadata{
|
||||
map[string]string{
|
||||
strings.Repeat("a", maxKeyLength+1): "abc",
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"value_too_long",
|
||||
CustomMetadata{
|
||||
map[string]string{
|
||||
"foo": strings.Repeat("a", maxValueLength+1),
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"unprintable_key",
|
||||
CustomMetadata{
|
||||
map[string]string{
|
||||
"unprint\u200bable": "abc",
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"unprintable_value",
|
||||
CustomMetadata{
|
||||
map[string]string{
|
||||
"foo": "unprint\u200bable",
|
||||
},
|
||||
false,
|
||||
|
||||
Reference in New Issue
Block a user