[GitHub] [servicecomb-kie] humingcheng commented on a change in pull request #124: Support parameter validation

2020-04-07 Thread GitBox
humingcheng commented on a change in pull request #124: Support parameter 
validation
URL: https://github.com/apache/servicecomb-kie/pull/124#discussion_r404767120
 
 

 ##
 File path: pkg/model/db_schema.go
 ##
 @@ -31,19 +31,19 @@ type LabelDoc struct {
 type KVDoc struct {
ID string `json:"id,omitempty" bson:"id,omitempty" 
yaml:"id,omitempty" swag:"string"`
LabelIDstring `json:"label_id,omitempty" 
bson:"label_id,omitempty" yaml:"label_id,omitempty"`
-   Keystring `json:"key" yaml:"key"`
-   Value  string `json:"value,omitempty" yaml:"value,omitempty"`
-   ValueType  string `json:"value_type,omitempty" 
bson:"value_type,omitempty" yaml:"value_type,omitempty"` 
//ini,json,text,yaml,properties
-   Checkerstring `json:"check,omitempty" yaml:"check,omitempty"`   
//python script
+   Keystring `json:"key" yaml:"key" validate:"key"`
+   Value  string `json:"value,omitempty" yaml:"value,omitempty" 
validate:"ascii,min=1,max=2097152"`
+   ValueType  string `json:"value_type,omitempty" 
bson:"value_type,omitempty" yaml:"value_type,omitempty" validate:"valueType"` 
//ini,json,text,yaml,properties
+   Checkerstring `json:"check,omitempty" yaml:"check,omitempty"`   
 //python script
CreateRevision int64  `json:"create_revision,omitempty" 
bson:"create_revision," yaml:"create_revision,omitempty"`
UpdateRevision int64  `json:"update_revision,omitempty" 
bson:"update_revision," yaml:"update_revision,omitempty"`
-   Projectstring `json:"project,omitempty" 
yaml:"project,omitempty"`
-   Status string `json:"status,omitempty" yaml:"status,omitempty"`
+   Projectstring `json:"project,omitempty" 
yaml:"project,omitempty" validate:"key"`
 
 Review comment:
   已修改为commonName


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [servicecomb-kie] humingcheng commented on a change in pull request #124: Support parameter validation

2020-04-07 Thread GitBox
humingcheng commented on a change in pull request #124: Support parameter 
validation
URL: https://github.com/apache/servicecomb-kie/pull/124#discussion_r404767218
 
 

 ##
 File path: server/resource/v1/kv_resource.go
 ##
 @@ -99,13 +100,13 @@ func (r *KVResource) Put(rctx *restful.Context) {
kv.Project = project
err = validatePut(kv)
if err != nil {
-   WriteErrResponse(rctx, http.StatusBadRequest, err.Error(), 
common.ContentTypeText)
+   WriteErrResponse(rctx, http.StatusBadRequest, err.Error(), 
common.ContentTypeJSON)
 
 Review comment:
   已修改


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [servicecomb-kie] humingcheng commented on a change in pull request #124: Support parameter validation

2020-03-26 Thread GitBox
humingcheng commented on a change in pull request #124: Support parameter 
validation
URL: https://github.com/apache/servicecomb-kie/pull/124#discussion_r399029370
 
 

 ##
 File path: server/resource/v1/kv_resource.go
 ##
 @@ -49,9 +51,9 @@ func (r *KVResource) Put(context *restful.Context) {
kv.Key = key
kv.Domain = domain.(string)
kv.Project = project
-   _, err = checkStatus(kv.Status)
+   err = validate.Validate(kv)
if err != nil {
-   WriteErrResponse(context, http.StatusInternalServerError, 
err.Error(), common.ContentTypeText)
+   WriteErrResponse(context, http.StatusBadRequest, err.Error(), 
common.ContentTypeText)
 
 Review comment:
   已修改为json


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [servicecomb-kie] humingcheng commented on a change in pull request #124: Support parameter validation

2020-03-26 Thread GitBox
humingcheng commented on a change in pull request #124: Support parameter 
validation
URL: https://github.com/apache/servicecomb-kie/pull/124#discussion_r399028387
 
 

 ##
 File path: pkg/model/db_schema.go
 ##
 @@ -31,19 +31,19 @@ type LabelDoc struct {
 type KVDoc struct {
ID string `json:"id,omitempty" bson:"id,omitempty" 
yaml:"id,omitempty" swag:"string"`
LabelIDstring `json:"label_id,omitempty" 
bson:"label_id,omitempty" yaml:"label_id,omitempty"`
-   Keystring `json:"key" yaml:"key"`
-   Value  string `json:"value,omitempty" yaml:"value,omitempty"`
-   ValueType  string `json:"value_type,omitempty" 
bson:"value_type,omitempty" yaml:"value_type,omitempty"` 
//ini,json,text,yaml,properties
-   Checkerstring `json:"check,omitempty" yaml:"check,omitempty"`   
//python script
+   Keystring `json:"key" yaml:"key" validate:"kieKey"`
+   Value  string `json:"value,omitempty" yaml:"value,omitempty" 
validate:"ascii,min=1,max=2097152"`
+   ValueType  string `json:"value_type,omitempty" 
bson:"value_type,omitempty" yaml:"value_type,omitempty" 
validate:"kieValueType"` //ini,json,text,yaml,properties
+   Checkerstring `json:"check,omitempty" yaml:"check,omitempty"`   
//python script
CreateRevision int64  `json:"create_revision,omitempty" 
bson:"create_revision," yaml:"create_revision,omitempty"`
UpdateRevision int64  `json:"update_revision,omitempty" 
bson:"update_revision," yaml:"update_revision,omitempty"`
Projectstring `json:"project,omitempty" 
yaml:"project,omitempty"`
-   Status string `json:"status,omitempty" yaml:"status,omitempty"`
+   Status string `json:"status,omitempty" yaml:"status,omitempty" 
validate:"kieKvStatus"`
 
 Review comment:
   已修改


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [servicecomb-kie] humingcheng commented on a change in pull request #124: Support parameter validation

2020-03-26 Thread GitBox
humingcheng commented on a change in pull request #124: Support parameter 
validation
URL: https://github.com/apache/servicecomb-kie/pull/124#discussion_r399028507
 
 

 ##
 File path: cmd/kieserver/main.go
 ##
 @@ -94,6 +96,9 @@ func main() {
if err := service.DBInit(); err != nil {
openlogging.Fatal(err.Error())
}
+   if err := validate.Init(); err != nil {
+   openlogging.Fatal("Validate init failed: " + err.Error())
 
 Review comment:
   已修改


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [servicecomb-kie] humingcheng commented on a change in pull request #124: Support parameter validation

2020-03-25 Thread GitBox
humingcheng commented on a change in pull request #124: Support parameter 
validation
URL: https://github.com/apache/servicecomb-kie/pull/124#discussion_r398261445
 
 

 ##
 File path: pkg/model/db_schema.go
 ##
 @@ -31,19 +31,19 @@ type LabelDoc struct {
 type KVDoc struct {
ID string `json:"id,omitempty" bson:"id,omitempty" 
yaml:"id,omitempty" swag:"string"`
LabelIDstring `json:"label_id,omitempty" 
bson:"label_id,omitempty" yaml:"label_id,omitempty"`
-   Keystring `json:"key" yaml:"key"`
-   Value  string `json:"value,omitempty" yaml:"value,omitempty"`
-   ValueType  string `json:"value_type,omitempty" 
bson:"value_type,omitempty" yaml:"value_type,omitempty"` 
//ini,json,text,yaml,properties
-   Checkerstring `json:"check,omitempty" yaml:"check,omitempty"`   
//python script
+   Keystring `json:"key" yaml:"key" validate:"kieKey"`
+   Value  string `json:"value,omitempty" yaml:"value,omitempty" 
validate:"ascii,min=1,max=2097152"`
+   ValueType  string `json:"value_type,omitempty" 
bson:"value_type,omitempty" yaml:"value_type,omitempty" 
validate:"kieValueType"` //ini,json,text,yaml,properties
 
 Review comment:
   已修改


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [servicecomb-kie] humingcheng commented on a change in pull request #124: Support parameter validation

2020-03-25 Thread GitBox
humingcheng commented on a change in pull request #124: Support parameter 
validation
URL: https://github.com/apache/servicecomb-kie/pull/124#discussion_r398261391
 
 

 ##
 File path: pkg/model/db_schema.go
 ##
 @@ -31,19 +31,19 @@ type LabelDoc struct {
 type KVDoc struct {
ID string `json:"id,omitempty" bson:"id,omitempty" 
yaml:"id,omitempty" swag:"string"`
LabelIDstring `json:"label_id,omitempty" 
bson:"label_id,omitempty" yaml:"label_id,omitempty"`
-   Keystring `json:"key" yaml:"key"`
-   Value  string `json:"value,omitempty" yaml:"value,omitempty"`
-   ValueType  string `json:"value_type,omitempty" 
bson:"value_type,omitempty" yaml:"value_type,omitempty"` 
//ini,json,text,yaml,properties
-   Checkerstring `json:"check,omitempty" yaml:"check,omitempty"`   
//python script
+   Keystring `json:"key" yaml:"key" validate:"kieKey"`
 
 Review comment:
   已修改


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [servicecomb-kie] humingcheng commented on a change in pull request #124: Support parameter validation

2020-03-25 Thread GitBox
humingcheng commented on a change in pull request #124: Support parameter 
validation
URL: https://github.com/apache/servicecomb-kie/pull/124#discussion_r398261315
 
 

 ##
 File path: pkg/validate/instance.go
 ##
 @@ -0,0 +1,37 @@
+package validate
+
+import "github.com/go-mesh/openlogging"
+
+var defaultValidator *Validator
+
+// custom validate rules
+// tag names suggested to be "kie*", to distinguish from third party tags
+var customRules = []*RegexValidateRule{
+   NewRule("kieKey", 
`^[a-zA-Z0-9]*$|^[a-zA-Z0-9][a-zA-Z0-9_\-.]*[a-zA-Z0-9]$`, &Option{Min: 1, Max: 
256}),
+   NewRule("kieValueType", `^(string|ini|json|text|yaml|properties)$`, 
nil),
 
 Review comment:
   已修改,正则允许为空


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [servicecomb-kie] humingcheng commented on a change in pull request #124: Support parameter validation

2020-03-25 Thread GitBox
humingcheng commented on a change in pull request #124: Support parameter 
validation
URL: https://github.com/apache/servicecomb-kie/pull/124#discussion_r397913599
 
 

 ##
 File path: pkg/validate/validator_test.go
 ##
 @@ -0,0 +1,36 @@
+package validate_test
+
+import (
+   "testing"
+
+   "github.com/apache/servicecomb-kie/pkg/validate"
+   "github.com/stretchr/testify/assert"
+)
+
+type student struct {
+   Namestring `validate:"kieTest"`
 
 Review comment:
   instance_test.go用真实业务模型做了测试


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [servicecomb-kie] humingcheng commented on a change in pull request #124: Support parameter validation

2020-03-25 Thread GitBox
humingcheng commented on a change in pull request #124: Support parameter 
validation
URL: https://github.com/apache/servicecomb-kie/pull/124#discussion_r397799086
 
 

 ##
 File path: pkg/validate/instance.go
 ##
 @@ -0,0 +1,37 @@
+package validate
+
+import "github.com/go-mesh/openlogging"
+
+var defaultValidator *Validator
+
+// custom validate rules
+// tag names suggested to be "kie*", to distinguish from third party tags
+var customRules = []*RegexValidateRule{
+   NewRule("kieKey", 
`^[a-zA-Z0-9]*$|^[a-zA-Z0-9][a-zA-Z0-9_\-.]*[a-zA-Z0-9]$`, &Option{Min: 1, Max: 
256}),
+   NewRule("kieValueType", `^(string|ini|json|text|yaml|properties)$`, 
nil),
+   NewRule("kieKvStatus", `^(enabled|disabled){0,1}$`, nil),
 
 Review comment:
   正则允许为空


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [servicecomb-kie] humingcheng commented on a change in pull request #124: Support parameter validation

2020-03-25 Thread GitBox
humingcheng commented on a change in pull request #124: Support parameter 
validation
URL: https://github.com/apache/servicecomb-kie/pull/124#discussion_r397796526
 
 

 ##
 File path: go.mod
 ##
 @@ -6,8 +6,11 @@ require (
github.com/go-chassis/go-chassis v0.0.0-20200322084331-36849ab2cb10
github.com/go-chassis/paas-lager v1.1.1
github.com/go-mesh/openlogging v1.0.1
+   github.com/go-playground/universal-translator v0.17.0
+   github.com/go-playground/validator v9.29.0+incompatible
 
 Review comment:
   v10的版本通过goproxy下载不下来,没办法


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services