You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/12/10 07:50:10 UTC
[GitHub] [apisix-dashboard] nic-chen opened a new pull request #1005: fix: PATCH method bug
nic-chen opened a new pull request #1005:
URL: https://github.com/apache/apisix-dashboard/pull/1005
Please answer these questions before submitting a pull request
- Why submit this pull request?
- [x] Bugfix
- [ ] New feature provided
- [ ] Improve performance
- Related issues
close #570
___
### Bugfix
- Description
The old version uses the data after binding the structure as the data of the patch, and there will be a problem of 0 value after binding.
And the old patch library has some bugs.
- How to fix?
Use raw data as patch data
Replace the patch library
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [apisix-dashboard] tokers commented on a change in pull request #1005: fix: PATCH method bug
Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #1005:
URL: https://github.com/apache/apisix-dashboard/pull/1005#discussion_r540760055
##########
File path: api/internal/handler/ssl/ssl.go
##########
@@ -182,40 +183,29 @@ func (h *Handler) Update(c droplet.Context) (interface{}, error) {
return nil, nil
}
-func (h *Handler) Patch(c droplet.Context) (interface{}, error) {
- input := c.Input().(*UpdateInput)
- arr := strings.Split(input.ID, "/")
- var subPath string
- if len(arr) > 1 {
- input.ID = arr[0]
- subPath = arr[1]
- }
+func Patch(c *gin.Context) (interface{}, error) {
+ reqBody, _ := c.GetRawData()
+ ID := c.Param("id")
+ subPath := c.Param("path")
- stored, err := h.sslStore.Get(input.ID)
+ sslStore := store.GetStore(store.HubKeySsl)
+ stored, err := sslStore.Get(ID)
if err != nil {
return handler.SpecCodeResponse(err), err
}
- var patch jsonpatch.Patch
- if subPath != "" {
- patch = jsonpatch.Patch{
- Operations: []jsonpatch.PatchOperation{
- {Op: jsonpatch.Replace, Path: subPath, Value: c.Input()},
- },
- }
- } else {
- patch, err = jsonpatch.MakePatch(stored, input.SSL)
- if err != nil {
- return handler.SpecCodeResponse(err), err
- }
+ res, err := utils.MergePatch(stored, subPath, reqBody)
Review comment:
OK
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [apisix-dashboard] juzhiyuan commented on pull request #1005: fix: PATCH method bug
Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on pull request #1005:
URL: https://github.com/apache/apisix-dashboard/pull/1005#issuecomment-743036607
hi @nic-chen, please merge this PR[1] first, that PR fixes a bug when deploying to Azure.
[1] https://github.com/apache/apisix-dashboard/pull/1018
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [apisix-dashboard] tokers commented on a change in pull request #1005: fix: PATCH method bug
Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #1005:
URL: https://github.com/apache/apisix-dashboard/pull/1005#discussion_r540741079
##########
File path: api/internal/utils/json_patch_test.go
##########
@@ -0,0 +1,211 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package utils
+
+import (
+ "bytes"
+ "encoding/json"
+ "reflect"
+ "testing"
+)
+
+func compareJSON(a, b string) bool {
+ var objA, objB interface{}
+ json.Unmarshal([]byte(a), &objA)
+ json.Unmarshal([]byte(b), &objB)
+
+ return reflect.DeepEqual(objA, objB)
+}
+
+func formatJSON(j string) string {
+ buf := new(bytes.Buffer)
+
+ json.Indent(buf, []byte(j), "", " ")
+
+ return buf.String()
+}
+
+func TestMergeJson(t *testing.T) {
+ Cases := []struct {
+ doc, patch, result, desc string
+ }{
+ {
+ desc: `simple merge`,
+ doc: `{
+ "id": "1",
+ "status": 1,
+ "key": "fake key",
+ "cert": "fake cert",
+ "create_time": 1,
+ "update_time": 2
+ }`,
+ patch: `{
+ "id": "1",
+ "status": 0,
+ "key": "fake key1",
+ "cert": "fake cert1"
+ }`,
+ result: `{
+ "id": "1",
+ "status": 0,
+ "key": "fake key1",
+ "cert": "fake cert1",
+ "create_time": 1,
+ "update_time": 2
+ }`,
+ },
+ {
+ desc: `array merge`,
+ doc: `{
+ "uri": "/index.html",
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": [{
+ "host": "39.97.63.215",
+ "port": 80,
+ "weight" : 1
+ }]
+ }
+ }`,
+ patch: `{
+ "upstream": {
+ "nodes": [{
+ "host": "39.97.63.216",
+ "port": 80,
+ "weight" : 1
+ },{
+ "host": "39.97.63.217",
+ "port": 80,
+ "weight" : 1
+ }]
+ }
+ }`,
+ result: `{
+ "uri": "/index.html",
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": [{
+ "host": "39.97.63.216",
+ "port": 80,
+ "weight" : 1
+ },{
+ "host": "39.97.63.217",
+ "port": 80,
+ "weight" : 1
+ }]
+ }
+ }`,
+ },
+ }
+ for _, c := range Cases {
+ out, err := MergeJson([]byte(c.doc), []byte(c.patch))
+
+ if err != nil {
+ t.Errorf("Unable to merge patch: %s", err)
+ }
+
+ if !compareJSON(string(out), c.result) {
+ t.Errorf("Merge failed. Expected:\n%s\n\nActual:\n%s",
+ formatJSON(c.result), formatJSON(string(out)))
+ }
+ }
+}
+
+func TestPatchJson(t *testing.T) {
+ Cases := []struct {
+ doc, path, value, result, desc string
+ }{
+ {
+ desc: "patch array",
+ doc: `{
+ "uri": "/index.html",
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": [{
+ "host": "39.97.63.215",
+ "port": 80,
+ "weight" : 1
+ }]
+ }
+ }`,
+ path: `/upstream/nodes`,
+ value: `[{
+ "host": "39.97.63.216",
+ "port": 80,
+ "weight" : 1
+ },{
+ "host": "39.97.63.217",
+ "port": 80,
+ "weight" : 1
+ }]`,
+ result: `{
+ "uri": "/index.html",
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": [{
+ "host": "39.97.63.216",
+ "port": 80,
+ "weight" : 1
+ },{
+ "host": "39.97.63.217",
+ "port": 80,
+ "weight" : 1
+ }]
+ }
+ }`,
+ },
+ {
+ desc: "patch field that not exists",
Review comment:
not exist => non existent
##########
File path: api/internal/handler/ssl/ssl.go
##########
@@ -182,40 +183,29 @@ func (h *Handler) Update(c droplet.Context) (interface{}, error) {
return nil, nil
}
-func (h *Handler) Patch(c droplet.Context) (interface{}, error) {
- input := c.Input().(*UpdateInput)
- arr := strings.Split(input.ID, "/")
- var subPath string
- if len(arr) > 1 {
- input.ID = arr[0]
- subPath = arr[1]
- }
+func Patch(c *gin.Context) (interface{}, error) {
+ reqBody, _ := c.GetRawData()
+ ID := c.Param("id")
+ subPath := c.Param("path")
- stored, err := h.sslStore.Get(input.ID)
+ sslStore := store.GetStore(store.HubKeySsl)
+ stored, err := sslStore.Get(ID)
if err != nil {
return handler.SpecCodeResponse(err), err
}
- var patch jsonpatch.Patch
- if subPath != "" {
- patch = jsonpatch.Patch{
- Operations: []jsonpatch.PatchOperation{
- {Op: jsonpatch.Replace, Path: subPath, Value: c.Input()},
- },
- }
- } else {
- patch, err = jsonpatch.MakePatch(stored, input.SSL)
- if err != nil {
- return handler.SpecCodeResponse(err), err
- }
+ res, err := utils.MergePatch(stored, subPath, reqBody)
Review comment:
We should verify the result after merging.
##########
File path: api/internal/utils/json_patch_test.go
##########
@@ -0,0 +1,211 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package utils
+
+import (
+ "bytes"
+ "encoding/json"
+ "reflect"
+ "testing"
+)
+
+func compareJSON(a, b string) bool {
+ var objA, objB interface{}
+ json.Unmarshal([]byte(a), &objA)
+ json.Unmarshal([]byte(b), &objB)
+
+ return reflect.DeepEqual(objA, objB)
+}
+
+func formatJSON(j string) string {
+ buf := new(bytes.Buffer)
+
+ json.Indent(buf, []byte(j), "", " ")
+
+ return buf.String()
+}
+
+func TestMergeJson(t *testing.T) {
+ Cases := []struct {
Review comment:
use small camel case.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [apisix-dashboard] juzhiyuan merged pull request #1005: fix: PATCH method bug
Posted by GitBox <gi...@apache.org>.
juzhiyuan merged pull request #1005:
URL: https://github.com/apache/apisix-dashboard/pull/1005
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [apisix-dashboard] nic-chen commented on pull request #1005: fix: PATCH method bug
Posted by GitBox <gi...@apache.org>.
nic-chen commented on pull request #1005:
URL: https://github.com/apache/apisix-dashboard/pull/1005#issuecomment-743000073
> need some E2E test cases
we already have E2E test cases for it:
https://github.com/apache/apisix-dashboard/pull/1005/files#diff-c2b7edfd95881ffeb7a02870b56d8c228b7b1f0f83d78be56f4462091bf76dc7R115-R174
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [apisix-dashboard] juzhiyuan commented on a change in pull request #1005: fix: PATCH method bug
Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on a change in pull request #1005:
URL: https://github.com/apache/apisix-dashboard/pull/1005#discussion_r540725371
##########
File path: api/internal/handler/ssl/ssl.go
##########
@@ -62,13 +62,14 @@ func (h *Handler) ApplyRoute(r *gin.Engine) {
wrapper.InputType(reflect.TypeOf(UpdateInput{}))))
r.PUT("/apisix/admin/ssl/:id", wgin.Wraps(h.Update,
wrapper.InputType(reflect.TypeOf(UpdateInput{}))))
- r.PATCH("/apisix/admin/ssl/:id", wgin.Wraps(h.Patch,
- wrapper.InputType(reflect.TypeOf(UpdateInput{}))))
r.DELETE("/apisix/admin/ssl/:ids", wgin.Wraps(h.BatchDelete,
wrapper.InputType(reflect.TypeOf(BatchDelete{}))))
r.POST("/apisix/admin/check_ssl_cert", wgin.Wraps(h.Validate,
wrapper.InputType(reflect.TypeOf(entity.SSL{}))))
+ r.PATCH("/apisix/admin/ssl/:id", consts.ErrorWrapper(Patch))
+ r.PATCH("/apisix/admin/ssl/:id/*path", consts.ErrorWrapper(Patch))
Review comment:
*path means any path?
##########
File path: api/internal/utils/json_patch_test.go
##########
@@ -0,0 +1,211 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package utils
+
+import (
+ "bytes"
+ "encoding/json"
+ "reflect"
+ "testing"
+)
+
+func compareJSON(a, b string) bool {
+ var objA, objB interface{}
+ json.Unmarshal([]byte(a), &objA)
+ json.Unmarshal([]byte(b), &objB)
+
+ return reflect.DeepEqual(objA, objB)
+}
+
+func formatJSON(j string) string {
+ buf := new(bytes.Buffer)
+
+ json.Indent(buf, []byte(j), "", " ")
+
+ return buf.String()
+}
+
+func TestMergeJson(t *testing.T) {
+ Cases := []struct {
+ doc, patch, result, desc string
+ }{
+ {
+ desc: `simple merge`,
Review comment:
![image](https://user-images.githubusercontent.com/2106987/101871919-5ffadb00-3bbf-11eb-8be4-5264cf5e3434.png)
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [apisix-dashboard] nic-chen commented on a change in pull request #1005: fix: PATCH method bug
Posted by GitBox <gi...@apache.org>.
nic-chen commented on a change in pull request #1005:
URL: https://github.com/apache/apisix-dashboard/pull/1005#discussion_r540747328
##########
File path: api/internal/handler/ssl/ssl.go
##########
@@ -182,40 +183,29 @@ func (h *Handler) Update(c droplet.Context) (interface{}, error) {
return nil, nil
}
-func (h *Handler) Patch(c droplet.Context) (interface{}, error) {
- input := c.Input().(*UpdateInput)
- arr := strings.Split(input.ID, "/")
- var subPath string
- if len(arr) > 1 {
- input.ID = arr[0]
- subPath = arr[1]
- }
+func Patch(c *gin.Context) (interface{}, error) {
+ reqBody, _ := c.GetRawData()
+ ID := c.Param("id")
+ subPath := c.Param("path")
- stored, err := h.sslStore.Get(input.ID)
+ sslStore := store.GetStore(store.HubKeySsl)
+ stored, err := sslStore.Get(ID)
if err != nil {
return handler.SpecCodeResponse(err), err
}
- var patch jsonpatch.Patch
- if subPath != "" {
- patch = jsonpatch.Patch{
- Operations: []jsonpatch.PatchOperation{
- {Op: jsonpatch.Replace, Path: subPath, Value: c.Input()},
- },
- }
- } else {
- patch, err = jsonpatch.MakePatch(stored, input.SSL)
- if err != nil {
- return handler.SpecCodeResponse(err), err
- }
+ res, err := utils.MergePatch(stored, subPath, reqBody)
Review comment:
@tokers we have schema verify before create or update.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [apisix-dashboard] nic-chen commented on a change in pull request #1005: fix: PATCH method bug
Posted by GitBox <gi...@apache.org>.
nic-chen commented on a change in pull request #1005:
URL: https://github.com/apache/apisix-dashboard/pull/1005#discussion_r540753960
##########
File path: api/internal/utils/json_patch_test.go
##########
@@ -0,0 +1,211 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package utils
+
+import (
+ "bytes"
+ "encoding/json"
+ "reflect"
+ "testing"
+)
+
+func compareJSON(a, b string) bool {
+ var objA, objB interface{}
+ json.Unmarshal([]byte(a), &objA)
+ json.Unmarshal([]byte(b), &objB)
+
+ return reflect.DeepEqual(objA, objB)
+}
+
+func formatJSON(j string) string {
+ buf := new(bytes.Buffer)
+
+ json.Indent(buf, []byte(j), "", " ")
+
+ return buf.String()
+}
+
+func TestMergeJson(t *testing.T) {
+ Cases := []struct {
+ doc, patch, result, desc string
+ }{
+ {
+ desc: `simple merge`,
+ doc: `{
+ "id": "1",
+ "status": 1,
+ "key": "fake key",
+ "cert": "fake cert",
+ "create_time": 1,
+ "update_time": 2
+ }`,
+ patch: `{
+ "id": "1",
+ "status": 0,
+ "key": "fake key1",
+ "cert": "fake cert1"
+ }`,
+ result: `{
+ "id": "1",
+ "status": 0,
+ "key": "fake key1",
+ "cert": "fake cert1",
+ "create_time": 1,
+ "update_time": 2
+ }`,
+ },
+ {
+ desc: `array merge`,
+ doc: `{
+ "uri": "/index.html",
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": [{
+ "host": "39.97.63.215",
+ "port": 80,
+ "weight" : 1
+ }]
+ }
+ }`,
+ patch: `{
+ "upstream": {
+ "nodes": [{
+ "host": "39.97.63.216",
+ "port": 80,
+ "weight" : 1
+ },{
+ "host": "39.97.63.217",
+ "port": 80,
+ "weight" : 1
+ }]
+ }
+ }`,
+ result: `{
+ "uri": "/index.html",
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": [{
+ "host": "39.97.63.216",
+ "port": 80,
+ "weight" : 1
+ },{
+ "host": "39.97.63.217",
+ "port": 80,
+ "weight" : 1
+ }]
+ }
+ }`,
+ },
+ }
+ for _, c := range Cases {
+ out, err := MergeJson([]byte(c.doc), []byte(c.patch))
+
+ if err != nil {
+ t.Errorf("Unable to merge patch: %s", err)
+ }
+
+ if !compareJSON(string(out), c.result) {
+ t.Errorf("Merge failed. Expected:\n%s\n\nActual:\n%s",
+ formatJSON(c.result), formatJSON(string(out)))
+ }
+ }
+}
+
+func TestPatchJson(t *testing.T) {
+ Cases := []struct {
+ doc, path, value, result, desc string
+ }{
+ {
+ desc: "patch array",
+ doc: `{
+ "uri": "/index.html",
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": [{
+ "host": "39.97.63.215",
+ "port": 80,
+ "weight" : 1
+ }]
+ }
+ }`,
+ path: `/upstream/nodes`,
+ value: `[{
+ "host": "39.97.63.216",
+ "port": 80,
+ "weight" : 1
+ },{
+ "host": "39.97.63.217",
+ "port": 80,
+ "weight" : 1
+ }]`,
+ result: `{
+ "uri": "/index.html",
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": [{
+ "host": "39.97.63.216",
+ "port": 80,
+ "weight" : 1
+ },{
+ "host": "39.97.63.217",
+ "port": 80,
+ "weight" : 1
+ }]
+ }
+ }`,
+ },
+ {
+ desc: "patch field that not exists",
Review comment:
fixed
##########
File path: api/internal/utils/json_patch_test.go
##########
@@ -0,0 +1,211 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package utils
+
+import (
+ "bytes"
+ "encoding/json"
+ "reflect"
+ "testing"
+)
+
+func compareJSON(a, b string) bool {
+ var objA, objB interface{}
+ json.Unmarshal([]byte(a), &objA)
+ json.Unmarshal([]byte(b), &objB)
+
+ return reflect.DeepEqual(objA, objB)
+}
+
+func formatJSON(j string) string {
+ buf := new(bytes.Buffer)
+
+ json.Indent(buf, []byte(j), "", " ")
+
+ return buf.String()
+}
+
+func TestMergeJson(t *testing.T) {
+ Cases := []struct {
Review comment:
fixed
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [apisix-dashboard] codecov-io commented on pull request #1005: fix: PATCH method bug
Posted by GitBox <gi...@apache.org>.
codecov-io commented on pull request #1005:
URL: https://github.com/apache/apisix-dashboard/pull/1005#issuecomment-743003798
# [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1005?src=pr&el=h1) Report
> Merging [#1005](https://codecov.io/gh/apache/apisix-dashboard/pull/1005?src=pr&el=desc) (0b8aa42) into [master](https://codecov.io/gh/apache/apisix-dashboard/commit/e611cd36c85bdb9c5cbc6b11ad52afe092ed6582?el=desc) (e611cd3) will **decrease** coverage by `2.07%`.
> The diff coverage is `23.80%`.
[![Impacted file tree graph](https://codecov.io/gh/apache/apisix-dashboard/pull/1005/graphs/tree.svg?width=650&height=150&src=pr&token=Q1HERXN96P)](https://codecov.io/gh/apache/apisix-dashboard/pull/1005?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #1005 +/- ##
==========================================
- Coverage 43.96% 41.89% -2.08%
==========================================
Files 18 24 +6
Lines 1310 1449 +139
==========================================
+ Hits 576 607 +31
- Misses 643 747 +104
- Partials 91 95 +4
```
| [Impacted Files](https://codecov.io/gh/apache/apisix-dashboard/pull/1005?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [api/internal/handler/ssl/ssl.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1005/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvc3NsL3NzbC5nbw==) | `29.47% <0.00%> (+1.30%)` | :arrow_up: |
| [api/internal/utils/json\_patch.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1005/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL3V0aWxzL2pzb25fcGF0Y2guZ28=) | `34.48% <34.48%> (ø)` | |
| [api/internal/core/store/validate.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1005/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvdmFsaWRhdGUuZ28=) | `61.29% <0.00%> (-0.40%)` | :arrow_down: |
| [api/filter/authentication.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1005/diff?src=pr&el=tree#diff-YXBpL2ZpbHRlci9hdXRoZW50aWNhdGlvbi5nbw==) | `0.00% <0.00%> (ø)` | |
| [api/filter/cors.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1005/diff?src=pr&el=tree#diff-YXBpL2ZpbHRlci9jb3JzLmdv) | `0.00% <0.00%> (ø)` | |
| [api/filter/recover.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1005/diff?src=pr&el=tree#diff-YXBpL2ZpbHRlci9yZWNvdmVyLmdv) | `0.00% <0.00%> (ø)` | |
| [api/filter/request\_id.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1005/diff?src=pr&el=tree#diff-YXBpL2ZpbHRlci9yZXF1ZXN0X2lkLmdv) | `0.00% <0.00%> (ø)` | |
| [api/filter/logging.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1005/diff?src=pr&el=tree#diff-YXBpL2ZpbHRlci9sb2dnaW5nLmdv) | `86.95% <0.00%> (ø)` | |
| [api/internal/core/store/store.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1005/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvc3RvcmUuZ28=) | `79.22% <0.00%> (+0.64%)` | :arrow_up: |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1005?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1005?src=pr&el=footer). Last update [e611cd3...0b8aa42](https://codecov.io/gh/apache/apisix-dashboard/pull/1005?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [apisix-dashboard] codecov-io edited a comment on pull request #1005: fix: PATCH method bug
Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #1005:
URL: https://github.com/apache/apisix-dashboard/pull/1005#issuecomment-743003798
# [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1005?src=pr&el=h1) Report
> Merging [#1005](https://codecov.io/gh/apache/apisix-dashboard/pull/1005?src=pr&el=desc) (12a9298) into [master](https://codecov.io/gh/apache/apisix-dashboard/commit/84ff9f8c87746f236f71b49b4ae77a07722f0f5e?el=desc) (84ff9f8) will **increase** coverage by `0.08%`.
> The diff coverage is `23.80%`.
[![Impacted file tree graph](https://codecov.io/gh/apache/apisix-dashboard/pull/1005/graphs/tree.svg?width=650&height=150&src=pr&token=Q1HERXN96P)](https://codecov.io/gh/apache/apisix-dashboard/pull/1005?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #1005 +/- ##
==========================================
+ Coverage 41.80% 41.89% +0.08%
==========================================
Files 23 24 +1
Lines 1428 1449 +21
==========================================
+ Hits 597 607 +10
- Misses 740 747 +7
- Partials 91 95 +4
```
| [Impacted Files](https://codecov.io/gh/apache/apisix-dashboard/pull/1005?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [api/internal/handler/ssl/ssl.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1005/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvc3NsL3NzbC5nbw==) | `29.47% <0.00%> (+1.30%)` | :arrow_up: |
| [api/internal/utils/json\_patch.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1005/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL3V0aWxzL2pzb25fcGF0Y2guZ28=) | `34.48% <34.48%> (ø)` | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1005?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1005?src=pr&el=footer). Last update [84ff9f8...12a9298](https://codecov.io/gh/apache/apisix-dashboard/pull/1005?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [apisix-dashboard] nic-chen commented on a change in pull request #1005: fix: PATCH method bug
Posted by GitBox <gi...@apache.org>.
nic-chen commented on a change in pull request #1005:
URL: https://github.com/apache/apisix-dashboard/pull/1005#discussion_r540719075
##########
File path: api/internal/utils/json_patch.go
##########
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package utils
+
+import (
+ "encoding/json"
+ jsonpatch "github.com/evanphx/json-patch/v5"
+)
+
+func MergeJson(doc, patch []byte) ([]byte, error) {
+ out, err := jsonpatch.MergePatch(doc, patch)
+
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+func PatchJson(doc []byte, path, val string) ([]byte, error) {
+ patch := []byte(`[ { "op": "replace", "path": "` + path + `", "value": ` + val + `}]`)
+ obj, err := jsonpatch.DecodePatch(patch)
+ if err != nil {
+ return nil, err
+ }
+
+ out, err := obj.Apply(doc)
+
+ if err != nil {
+ // try to add if field not exist
+ patch = []byte(`[ { "op": "add", "path": "` + path + `", "value": ` + val + `}]`)
+ obj, err = jsonpatch.DecodePatch(patch)
+ if err != nil {
+ return nil, err
+ }
+ out, err = obj.Apply(doc)
+ if err != nil {
+ return nil, err
+ }
+ }
+
+ return out, nil
+}
+
+func MakePatch(obj interface{}, subPath string, reqBody []byte) ([]byte, error) {
Review comment:
ok
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [apisix-dashboard] nic-chen commented on a change in pull request #1005: fix: PATCH method bug
Posted by GitBox <gi...@apache.org>.
nic-chen commented on a change in pull request #1005:
URL: https://github.com/apache/apisix-dashboard/pull/1005#discussion_r540760284
##########
File path: api/internal/utils/json_patch_test.go
##########
@@ -0,0 +1,211 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package utils
+
+import (
+ "bytes"
+ "encoding/json"
+ "reflect"
+ "testing"
+)
+
+func compareJSON(a, b string) bool {
+ var objA, objB interface{}
+ json.Unmarshal([]byte(a), &objA)
+ json.Unmarshal([]byte(b), &objB)
+
+ return reflect.DeepEqual(objA, objB)
+}
+
+func formatJSON(j string) string {
+ buf := new(bytes.Buffer)
+
+ json.Indent(buf, []byte(j), "", " ")
+
+ return buf.String()
+}
+
+func TestMergeJson(t *testing.T) {
+ Cases := []struct {
+ doc, patch, result, desc string
+ }{
+ {
+ desc: `simple merge`,
Review comment:
fixed
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [apisix-dashboard] nic-chen commented on a change in pull request #1005: fix: PATCH method bug
Posted by GitBox <gi...@apache.org>.
nic-chen commented on a change in pull request #1005:
URL: https://github.com/apache/apisix-dashboard/pull/1005#discussion_r540729291
##########
File path: api/internal/handler/ssl/ssl.go
##########
@@ -62,13 +62,14 @@ func (h *Handler) ApplyRoute(r *gin.Engine) {
wrapper.InputType(reflect.TypeOf(UpdateInput{}))))
r.PUT("/apisix/admin/ssl/:id", wgin.Wraps(h.Update,
wrapper.InputType(reflect.TypeOf(UpdateInput{}))))
- r.PATCH("/apisix/admin/ssl/:id", wgin.Wraps(h.Patch,
- wrapper.InputType(reflect.TypeOf(UpdateInput{}))))
r.DELETE("/apisix/admin/ssl/:ids", wgin.Wraps(h.BatchDelete,
wrapper.InputType(reflect.TypeOf(BatchDelete{}))))
r.POST("/apisix/admin/check_ssl_cert", wgin.Wraps(h.Validate,
wrapper.InputType(reflect.TypeOf(entity.SSL{}))))
+ r.PATCH("/apisix/admin/ssl/:id", consts.ErrorWrapper(Patch))
+ r.PATCH("/apisix/admin/ssl/:id/*path", consts.ErrorWrapper(Patch))
Review comment:
* means any, `path` is a variable name for it.
usage of gin framework
----------------------------------------------------------------
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:
users@infra.apache.org