Skip to content

Commit

Permalink
Merge 7bebca1 into f89a952
Browse files Browse the repository at this point in the history
  • Loading branch information
humingcheng committed Jun 29, 2020
2 parents f89a952 + 7bebca1 commit fe34022
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pkg/model/db_schema.go
Expand Up @@ -42,7 +42,7 @@ type KVDoc struct {
CreateTime int64 `json:"create_time,omitempty" bson:"create_time," yaml:"create_time,omitempty"`
UpdateTime int64 `json:"update_time,omitempty" bson:"update_time," yaml:"update_time,omitempty"`

Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty" validate:"max=8,dive,keys,lableKV,endkeys,lableKV"` //redundant
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty" validate:"max=6,dive,keys,labelKV,endkeys,labelKV"` //redundant
Domain string `json:"domain,omitempty" yaml:"domain,omitempty" validate:"commonName"` //redundant
}

Expand Down Expand Up @@ -90,7 +90,7 @@ type ListKVRequest struct {
Project string `json:"project,omitempty" yaml:"project,omitempty" validate:"commonName"`
Domain string `json:"domain,omitempty" yaml:"domain,omitempty" validate:"commonName"` //redundant
Key string `json:"key" yaml:"key" validate:"getKey"`
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty" validate:"max=8,dive,keys,lableKV,endkeys,lableKV"` //redundant
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty" validate:"max=8,dive,keys,labelKV,endkeys,labelKV"` //redundant
Offset int64 `validate:"min=0"`
Limit int64 `validate:"min=0,max=100"`
Status string `json:"status,omitempty" yaml:"status,omitempty" validate:"kvStatus"`
Expand Down
6 changes: 3 additions & 3 deletions pkg/validate/instance.go
Expand Up @@ -11,13 +11,13 @@ const (
// custom validate rules
// please use different tag names from third party tags
var customRules = []*RegexValidateRule{
NewRule(key, commonNameRegexString, &Option{Min: 1, Max: 512}), //0.5K
NewRule("getKey", commonNameRegexString, &Option{Max: 512}), //0.5K
NewRule(key, commonNameRegexString, &Option{Min: 1, Max: 128}),
NewRule("getKey", commonNameRegexString, &Option{Max: 128}),
NewRule("commonName", commonNameRegexString, &Option{Min: 1, Max: 256}),
NewRule("valueType", `^$|^(ini|json|text|yaml|properties)$`, nil),
NewRule("kvStatus", `^$|^(enabled|disabled)$`, nil),
NewRule("value", asciiRegexString, &Option{Max: 2097152}), //ASCII, 2M
NewRule("lableKV", commonNameRegexString, &Option{Max: 32}),
NewRule("labelKV", commonNameRegexString, &Option{Max: 32}),
NewRule("check", asciiRegexString, &Option{Max: 1048576}), //ASCII, 1M
}

Expand Down
7 changes: 2 additions & 5 deletions pkg/validate/instance_test.go
Expand Up @@ -11,10 +11,7 @@ import (

func TestValidate(t *testing.T) {
string32 := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" //32
string512 := "a"
for i := 0; i < 9; i++ { //512
string512 = string512 + string512
}
string128 := string32 + string32 + string32 + string32
err := validate.Init()
assert.NoError(t, err)

Expand All @@ -37,7 +34,7 @@ func TestValidate(t *testing.T) {
assert.Error(t, validate.Validate(kvDoc))

kvDoc = &model.KVDoc{Project: "a", Domain: "a",
Key: string512 + "a",
Key: string128 + "a",
Value: "a",
}
assert.Error(t, validate.Validate(kvDoc))
Expand Down

0 comments on commit fe34022

Please sign in to comment.