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 2021/02/24 15:42:34 UTC
[GitHub] [apisix-dashboard] nic-chen opened a new pull request #1509: feat: support plugin config
nic-chen opened a new pull request #1509:
URL: https://github.com/apache/apisix-dashboard/pull/1509
Please answer these questions before submitting a pull request
- Why submit this pull request?
- [ ] Bugfix
- [x] New feature provided
- [ ] Improve performance
- [ ] Backport patches
support plugin config in Manager API
related pr in APISIX https://github.com/apache/apisix/pull/3567
----------------------------------------------------------------
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 #1509: feat: support plugin config
Posted by GitBox <gi...@apache.org>.
nic-chen commented on a change in pull request #1509:
URL: https://github.com/apache/apisix-dashboard/pull/1509#discussion_r586171786
##########
File path: api/test/e2e/label_test.go
##########
@@ -302,6 +333,14 @@ func TestLabel(t *testing.T) {
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusOK,
},
+ {
Review comment:
updated.
----------------------------------------------------------------
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 #1509: feat: support plugin config
Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #1509:
URL: https://github.com/apache/apisix-dashboard/pull/1509#issuecomment-787705132
# [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?src=pr&el=h1) Report
> Merging [#1509](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?src=pr&el=desc) (25ea754) into [master](https://codecov.io/gh/apache/apisix-dashboard/commit/2dbd204d1f42fb9eb425b4cdc7f190adedfc667e?el=desc) (2dbd204) will **decrease** coverage by `31.84%`.
> The diff coverage is `58.26%`.
[![Impacted file tree graph](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/graphs/tree.svg?width=650&height=150&src=pr&token=Q1HERXN96P)](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #1509 +/- ##
===========================================
- Coverage 70.12% 38.27% -31.85%
===========================================
Files 129 49 -80
Lines 5231 3164 -2067
Branches 549 0 -549
===========================================
- Hits 3668 1211 -2457
- Misses 1323 1699 +376
- Partials 240 254 +14
```
| Flag | Coverage Δ | |
|---|---|---|
| backend-e2e-test | `?` | |
| backend-e2e-test-ginkgo | `38.27% <58.26%> (+4.69%)` | :arrow_up: |
| backend-unit-test | `?` | |
| frontend-e2e-test | `?` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.
| [Impacted Files](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [api/internal/core/entity/entity.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvZW50aXR5L2VudGl0eS5nbw==) | `75.00% <ø> (-25.00%)` | :arrow_down: |
| [api/internal/handler/label/label.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvbGFiZWwvbGFiZWwuZ28=) | `9.43% <54.54%> (-71.76%)` | :arrow_down: |
| [...pi/internal/handler/plugin\_config/plugin\_config.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvcGx1Z2luX2NvbmZpZy9wbHVnaW5fY29uZmlnLmdv) | `56.38% <56.38%> (ø)` | |
| [api/internal/core/store/storehub.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvc3RvcmVodWIuZ28=) | `59.81% <77.77%> (-14.68%)` | :arrow_down: |
| [api/internal/route.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL3JvdXRlLmdv) | `77.14% <100.00%> (-8.16%)` | :arrow_down: |
| [api/internal/core/store/query.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvcXVlcnkuZ28=) | `0.00% <0.00%> (-88.10%)` | :arrow_down: |
| [api/internal/core/store/selector.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvc2VsZWN0b3IuZ28=) | `0.00% <0.00%> (-75.93%)` | :arrow_down: |
| [api/internal/handler/plugin/plugin.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvcGx1Z2luL3BsdWdpbi5nbw==) | `15.15% <0.00%> (-72.73%)` | :arrow_down: |
| [api/internal/handler/service/service.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvc2VydmljZS9zZXJ2aWNlLmdv) | `21.27% <0.00%> (-70.22%)` | :arrow_down: |
| [api/internal/handler/data\_loader/route\_export.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvZGF0YV9sb2FkZXIvcm91dGVfZXhwb3J0Lmdv) | `3.38% <0.00%> (-65.79%)` | :arrow_down: |
| ... and [107 more](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree-more) | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?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/1509?src=pr&el=footer). Last update [2dbd204...25ea754](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?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 #1509: feat: support plugin config
Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #1509:
URL: https://github.com/apache/apisix-dashboard/pull/1509#issuecomment-787705132
# [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?src=pr&el=h1) Report
> Merging [#1509](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?src=pr&el=desc) (b3644c8) into [master](https://codecov.io/gh/apache/apisix-dashboard/commit/2dbd204d1f42fb9eb425b4cdc7f190adedfc667e?el=desc) (2dbd204) will **decrease** coverage by `18.43%`.
> The diff coverage is `50.87%`.
[![Impacted file tree graph](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/graphs/tree.svg?width=650&height=150&src=pr&token=Q1HERXN96P)](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #1509 +/- ##
===========================================
- Coverage 70.12% 51.68% -18.44%
===========================================
Files 129 40 -89
Lines 5231 2707 -2524
Branches 549 0 -549
===========================================
- Hits 3668 1399 -2269
+ Misses 1323 1127 -196
+ Partials 240 181 -59
```
| Flag | Coverage Δ | |
|---|---|---|
| backend-e2e-test | `?` | |
| backend-e2e-test-ginkgo | `?` | |
| backend-unit-test | `51.68% <50.87%> (+0.04%)` | :arrow_up: |
| frontend-e2e-test | `?` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.
| [Impacted Files](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [api/internal/core/entity/entity.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvZW50aXR5L2VudGl0eS5nbw==) | `0.00% <ø> (-100.00%)` | :arrow_down: |
| [api/internal/core/store/storehub.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvc3RvcmVodWIuZ28=) | `0.00% <0.00%> (-74.49%)` | :arrow_down: |
| [api/internal/handler/label/label.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvbGFiZWwvbGFiZWwuZ28=) | `70.75% <45.45%> (-10.44%)` | :arrow_down: |
| [...pi/internal/handler/plugin\_config/plugin\_config.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvcGx1Z2luX2NvbmZpZy9wbHVnaW5fY29uZmlnLmdv) | `56.38% <56.38%> (ø)` | |
| [api/internal/utils/version.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL3V0aWxzL3ZlcnNpb24uZ28=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [api/internal/filter/request\_id.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2ZpbHRlci9yZXF1ZXN0X2lkLmdv) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [api/internal/filter/cors.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2ZpbHRlci9jb3JzLmdv) | `0.00% <0.00%> (-66.67%)` | :arrow_down: |
| [api/internal/filter/schema.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2ZpbHRlci9zY2hlbWEuZ28=) | `0.00% <0.00%> (-55.47%)` | :arrow_down: |
| ... and [114 more](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree-more) | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?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/1509?src=pr&el=footer). Last update [2dbd204...b3644c8](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?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 #1509: feat: support plugin config
Posted by GitBox <gi...@apache.org>.
nic-chen commented on a change in pull request #1509:
URL: https://github.com/apache/apisix-dashboard/pull/1509#discussion_r586086963
##########
File path: api/test/e2enew/plugin_config/plugin_config_test.go
##########
@@ -0,0 +1,197 @@
+/*
+ * 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 plugin_config
+
+import (
+ "net/http"
+
+ "github.com/onsi/ginkgo"
+ "github.com/onsi/ginkgo/extensions/table"
+
+ "e2enew/base"
+)
+
+var _ = ginkgo.Describe("Plugin Config", func() {
+ table.DescribeTable("test plugin config",
+ func(tc base.HttpTestCase) {
+ base.RunTestCase(tc)
+ },
+ table.Entry("make sure the route doesn't exist", base.HttpTestCase{
+ Object: base.APISIXExpect(),
+ Method: http.MethodGet,
+ Path: "/hello",
+ ExpectStatus: http.StatusNotFound,
+ ExpectBody: `{"error_msg":"404 Route Not Found"}`,
+ }),
+ table.Entry("create plugin config", base.HttpTestCase{
+ Object: base.ManagerApiExpect(),
+ Path: "/apisix/admin/plugin_configs/1",
+ Method: http.MethodPut,
+ Body: `{
+ "plugins": {
+ "response-rewrite": {
+ "headers": {
+ "X-VERSION":"1.0"
+ }
+ },
+ "uri-blocker": {
+ "block_rules": ["select.+(from|limit)", "(?:(union(.*?)select))"]
+ }
+ }
+ }`,
+ Headers: map[string]string{"Authorization": base.GetToken()},
+ ExpectStatus: http.StatusOK,
+ }),
+ table.Entry("create plugin config", base.HttpTestCase{
Review comment:
fixed.
##########
File path: api/test/e2enew/plugin_config/plugin_config_test.go
##########
@@ -0,0 +1,197 @@
+/*
+ * 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 plugin_config
+
+import (
+ "net/http"
+
+ "github.com/onsi/ginkgo"
+ "github.com/onsi/ginkgo/extensions/table"
+
+ "e2enew/base"
+)
+
+var _ = ginkgo.Describe("Plugin Config", func() {
+ table.DescribeTable("test plugin config",
+ func(tc base.HttpTestCase) {
+ base.RunTestCase(tc)
+ },
+ table.Entry("make sure the route doesn't exist", base.HttpTestCase{
+ Object: base.APISIXExpect(),
+ Method: http.MethodGet,
+ Path: "/hello",
+ ExpectStatus: http.StatusNotFound,
+ ExpectBody: `{"error_msg":"404 Route Not Found"}`,
+ }),
+ table.Entry("create plugin config", base.HttpTestCase{
+ Object: base.ManagerApiExpect(),
+ Path: "/apisix/admin/plugin_configs/1",
+ Method: http.MethodPut,
+ Body: `{
+ "plugins": {
+ "response-rewrite": {
+ "headers": {
+ "X-VERSION":"1.0"
+ }
+ },
+ "uri-blocker": {
+ "block_rules": ["select.+(from|limit)", "(?:(union(.*?)select))"]
+ }
+ }
+ }`,
+ Headers: map[string]string{"Authorization": base.GetToken()},
+ ExpectStatus: http.StatusOK,
+ }),
+ table.Entry("create plugin config", base.HttpTestCase{
+ Object: base.ManagerApiExpect(),
+ Path: "/apisix/admin/plugin_configs/1",
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] starsz commented on a change in pull request #1509: feat: support plugin config
Posted by GitBox <gi...@apache.org>.
starsz commented on a change in pull request #1509:
URL: https://github.com/apache/apisix-dashboard/pull/1509#discussion_r582494143
##########
File path: api/internal/core/store/storehub.go
##########
@@ -36,6 +36,7 @@ const (
HubKeyScript HubKey = "script"
HubKeyGlobalRule HubKey = "global_rule"
HubKeyServerInfo HubKey = "server_info"
+ HubKeyPluginConfig HubKey = "plugin_config"
Review comment:
Code style.
##########
File path: api/internal/handler/plugin_config/plugin_config.go
##########
@@ -0,0 +1,228 @@
+/*
+ * 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 plugin_config
+
+import (
+ "encoding/json"
+ "net/http"
+ "reflect"
+ "strings"
+
+ "github.com/gin-gonic/gin"
+ "github.com/shiningrush/droplet"
+ "github.com/shiningrush/droplet/data"
+ "github.com/shiningrush/droplet/wrapper"
+ wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+ "github.com/apisix/manager-api/internal/core/entity"
+ "github.com/apisix/manager-api/internal/core/store"
+ "github.com/apisix/manager-api/internal/handler"
+ "github.com/apisix/manager-api/internal/log"
+ "github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+ pluginConfigStore store.Interface
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+ return &Handler{
+ pluginConfigStore: store.GetStore(store.HubKeyPluginConfig),
+ }, nil
+}
+
+func (h *Handler) ApplyRoute(r *gin.Engine) {
+ r.GET("/apisix/admin/plugin_configs/:id", wgin.Wraps(h.Get,
+ wrapper.InputType(reflect.TypeOf(GetInput{}))))
+ r.GET("/apisix/admin/plugin_configs", wgin.Wraps(h.List,
+ wrapper.InputType(reflect.TypeOf(ListInput{}))))
+ r.POST("/apisix/admin/plugin_configs", wgin.Wraps(h.Create,
+ wrapper.InputType(reflect.TypeOf(entity.PluginConfig{}))))
+ r.PUT("/apisix/admin/plugin_configs", wgin.Wraps(h.Update,
+ wrapper.InputType(reflect.TypeOf(UpdateInput{}))))
+ r.PUT("/apisix/admin/plugin_configs/:id", wgin.Wraps(h.Update,
+ wrapper.InputType(reflect.TypeOf(UpdateInput{}))))
+ r.PATCH("/apisix/admin/plugin_configs/:id", wgin.Wraps(h.Patch,
+ wrapper.InputType(reflect.TypeOf(PatchInput{}))))
+ r.PATCH("/apisix/admin/plugin_configs/:id/*path", wgin.Wraps(h.Patch,
+ wrapper.InputType(reflect.TypeOf(PatchInput{}))))
+ r.DELETE("/apisix/admin/plugin_configs/:ids", wgin.Wraps(h.BatchDelete,
+ wrapper.InputType(reflect.TypeOf(BatchDelete{}))))
+}
+
+type GetInput struct {
+ ID string `auto_read:"id,path" validate:"required"`
+}
+
+func (h *Handler) Get(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*GetInput)
+
+ pluginConfig, err := h.pluginConfigStore.Get(c.Context(), input.ID)
+ if err != nil {
+ return handler.SpecCodeResponse(err), err
+ }
+
+ return pluginConfig, nil
+}
+
+type ListInput struct {
+ Search string `auto_read:"search,query"`
+ store.Pagination
+}
+
+// swagger:operation GET /apisix/admin/plugin_configs getPluginConfigList
+//
+// Return the plugin_config list according to the specified page number and page size, and support search.
+//
+// ---
+// produces:
+// - application/json
+// parameters:
+// - name: page
+// in: query
+// description: page number
+// required: false
+// type: integer
+// - name: page_size
+// in: query
+// description: page size
+// required: false
+// type: integer
+// - name: search
+// in: query
+// description: search keyword
+// required: false
+// type: string
+// responses:
+// '0':
+// description: list response
+// schema:
+// type: array
+// items:
+// "$ref": "#/definitions/pluginConfig"
+// default:
+// description: unexpected error
+// schema:
+// "$ref": "#/definitions/ApiError"
+func (h *Handler) List(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*ListInput)
+
+ ret, err := h.pluginConfigStore.List(c.Context(), store.ListInput{
+ Predicate: func(obj interface{}) bool {
+ if input.Search != "" {
+ return strings.Contains(obj.(*entity.PluginConfig).Desc, input.Search)
+ }
+ return true
+ },
+ PageSize: input.PageSize,
+ PageNumber: input.PageNumber,
+ })
+ if err != nil {
+ return nil, err
+ }
+
+ return ret, nil
+}
+
+func (h *Handler) Create(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*entity.PluginConfig)
+
+ ret, err := h.pluginConfigStore.Create(c.Context(), input)
+ if err != nil {
+ return handler.SpecCodeResponse(err), err
+ }
+
+ return ret, nil
+}
+
+type UpdateInput struct {
+ ID string `auto_read:"id,path"`
+ entity.PluginConfig
+}
+
+func (h *Handler) Update(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*UpdateInput)
+
+ // check if ID in body is equal ID in path
+ if err := handler.IDCompare(input.ID, input.PluginConfig.ID); err != nil {
+ return &data.SpecCodeResponse{StatusCode: http.StatusBadRequest}, err
+ }
+
+ if input.ID != "" {
+ input.PluginConfig.ID = input.ID
+ }
+
+ ret, err := h.pluginConfigStore.Update(c.Context(), &input.PluginConfig, true)
Review comment:
Please make sure about the third args in `h.pluginConfigStore.Update`.
We should create it if not exist?
##########
File path: api/internal/handler/plugin_config/plugin_config.go
##########
@@ -0,0 +1,228 @@
+/*
+ * 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 plugin_config
+
+import (
+ "encoding/json"
+ "net/http"
+ "reflect"
+ "strings"
+
+ "github.com/gin-gonic/gin"
+ "github.com/shiningrush/droplet"
+ "github.com/shiningrush/droplet/data"
+ "github.com/shiningrush/droplet/wrapper"
+ wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+ "github.com/apisix/manager-api/internal/core/entity"
+ "github.com/apisix/manager-api/internal/core/store"
+ "github.com/apisix/manager-api/internal/handler"
+ "github.com/apisix/manager-api/internal/log"
+ "github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+ pluginConfigStore store.Interface
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+ return &Handler{
+ pluginConfigStore: store.GetStore(store.HubKeyPluginConfig),
+ }, nil
+}
+
+func (h *Handler) ApplyRoute(r *gin.Engine) {
+ r.GET("/apisix/admin/plugin_configs/:id", wgin.Wraps(h.Get,
+ wrapper.InputType(reflect.TypeOf(GetInput{}))))
+ r.GET("/apisix/admin/plugin_configs", wgin.Wraps(h.List,
+ wrapper.InputType(reflect.TypeOf(ListInput{}))))
+ r.POST("/apisix/admin/plugin_configs", wgin.Wraps(h.Create,
+ wrapper.InputType(reflect.TypeOf(entity.PluginConfig{}))))
+ r.PUT("/apisix/admin/plugin_configs", wgin.Wraps(h.Update,
+ wrapper.InputType(reflect.TypeOf(UpdateInput{}))))
+ r.PUT("/apisix/admin/plugin_configs/:id", wgin.Wraps(h.Update,
+ wrapper.InputType(reflect.TypeOf(UpdateInput{}))))
+ r.PATCH("/apisix/admin/plugin_configs/:id", wgin.Wraps(h.Patch,
+ wrapper.InputType(reflect.TypeOf(PatchInput{}))))
+ r.PATCH("/apisix/admin/plugin_configs/:id/*path", wgin.Wraps(h.Patch,
+ wrapper.InputType(reflect.TypeOf(PatchInput{}))))
+ r.DELETE("/apisix/admin/plugin_configs/:ids", wgin.Wraps(h.BatchDelete,
+ wrapper.InputType(reflect.TypeOf(BatchDelete{}))))
+}
+
+type GetInput struct {
+ ID string `auto_read:"id,path" validate:"required"`
+}
+
+func (h *Handler) Get(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*GetInput)
+
+ pluginConfig, err := h.pluginConfigStore.Get(c.Context(), input.ID)
+ if err != nil {
+ return handler.SpecCodeResponse(err), err
+ }
+
+ return pluginConfig, nil
+}
+
+type ListInput struct {
+ Search string `auto_read:"search,query"`
+ store.Pagination
+}
+
+// swagger:operation GET /apisix/admin/plugin_configs getPluginConfigList
+//
+// Return the plugin_config list according to the specified page number and page size, and support search.
+//
+// ---
+// produces:
+// - application/json
+// parameters:
+// - name: page
+// in: query
+// description: page number
+// required: false
+// type: integer
+// - name: page_size
+// in: query
+// description: page size
+// required: false
+// type: integer
+// - name: search
+// in: query
+// description: search keyword
+// required: false
+// type: string
+// responses:
+// '0':
+// description: list response
+// schema:
+// type: array
+// items:
+// "$ref": "#/definitions/pluginConfig"
+// default:
+// description: unexpected error
+// schema:
+// "$ref": "#/definitions/ApiError"
+func (h *Handler) List(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*ListInput)
+
+ ret, err := h.pluginConfigStore.List(c.Context(), store.ListInput{
+ Predicate: func(obj interface{}) bool {
+ if input.Search != "" {
+ return strings.Contains(obj.(*entity.PluginConfig).Desc, input.Search)
+ }
+ return true
+ },
+ PageSize: input.PageSize,
+ PageNumber: input.PageNumber,
+ })
+ if err != nil {
+ return nil, err
+ }
+
+ return ret, nil
+}
+
+func (h *Handler) Create(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*entity.PluginConfig)
+
+ ret, err := h.pluginConfigStore.Create(c.Context(), input)
+ if err != nil {
+ return handler.SpecCodeResponse(err), err
+ }
+
+ return ret, nil
+}
+
+type UpdateInput struct {
+ ID string `auto_read:"id,path"`
+ entity.PluginConfig
+}
+
+func (h *Handler) Update(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*UpdateInput)
+
+ // check if ID in body is equal ID in path
+ if err := handler.IDCompare(input.ID, input.PluginConfig.ID); err != nil {
+ return &data.SpecCodeResponse{StatusCode: http.StatusBadRequest}, err
+ }
+
+ if input.ID != "" {
+ input.PluginConfig.ID = input.ID
+ }
+
+ ret, err := h.pluginConfigStore.Update(c.Context(), &input.PluginConfig, true)
+ if err != nil {
+ return handler.SpecCodeResponse(err), err
+ }
+
+ return ret, nil
+}
+
+type BatchDelete struct {
+ IDs string `auto_read:"ids,path"`
+}
+
+func (h *Handler) BatchDelete(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*BatchDelete)
+
+ if err := h.pluginConfigStore.BatchDelete(c.Context(), strings.Split(input.IDs, ",")); err != nil {
+ return handler.SpecCodeResponse(err), err
+ }
+
+ return nil, nil
+}
+
+type PatchInput struct {
+ ID string `auto_read:"id,path"`
+ SubPath string `auto_read:"path,path"`
+ Body []byte `auto_read:"@body"`
+}
+
+func (h *Handler) Patch(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*PatchInput)
+ reqBody := input.Body
+ id := input.ID
+ subPath := input.SubPath
+
+ stored, err := h.pluginConfigStore.Get(c.Context(), id)
+ if err != nil {
+ log.Warnf("%s", err)
+ return handler.SpecCodeResponse(err), err
+ }
+
+ res, err := utils.MergePatch(stored, subPath, reqBody)
+ if err != nil {
+ log.Warnf("%s", err)
+ return handler.SpecCodeResponse(err), err
+ }
+
+ var pluginConfig entity.PluginConfig
+ if err := json.Unmarshal(res, &pluginConfig); err != nil {
+ log.Warnf("%s", err)
+ return handler.SpecCodeResponse(err), err
+ }
+
+ ret, err := h.pluginConfigStore.Update(c.Context(), &pluginConfig, false)
+ if err != nil {
+ log.Warnf("%s", err)
Review comment:
The log seems not very good.
##########
File path: api/internal/handler/plugin_config/plugin_config.go
##########
@@ -0,0 +1,228 @@
+/*
+ * 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 plugin_config
+
+import (
+ "encoding/json"
+ "net/http"
+ "reflect"
+ "strings"
+
+ "github.com/gin-gonic/gin"
+ "github.com/shiningrush/droplet"
+ "github.com/shiningrush/droplet/data"
+ "github.com/shiningrush/droplet/wrapper"
+ wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+ "github.com/apisix/manager-api/internal/core/entity"
+ "github.com/apisix/manager-api/internal/core/store"
+ "github.com/apisix/manager-api/internal/handler"
+ "github.com/apisix/manager-api/internal/log"
+ "github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+ pluginConfigStore store.Interface
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+ return &Handler{
+ pluginConfigStore: store.GetStore(store.HubKeyPluginConfig),
+ }, nil
+}
+
+func (h *Handler) ApplyRoute(r *gin.Engine) {
+ r.GET("/apisix/admin/plugin_configs/:id", wgin.Wraps(h.Get,
+ wrapper.InputType(reflect.TypeOf(GetInput{}))))
+ r.GET("/apisix/admin/plugin_configs", wgin.Wraps(h.List,
+ wrapper.InputType(reflect.TypeOf(ListInput{}))))
+ r.POST("/apisix/admin/plugin_configs", wgin.Wraps(h.Create,
+ wrapper.InputType(reflect.TypeOf(entity.PluginConfig{}))))
+ r.PUT("/apisix/admin/plugin_configs", wgin.Wraps(h.Update,
+ wrapper.InputType(reflect.TypeOf(UpdateInput{}))))
+ r.PUT("/apisix/admin/plugin_configs/:id", wgin.Wraps(h.Update,
+ wrapper.InputType(reflect.TypeOf(UpdateInput{}))))
+ r.PATCH("/apisix/admin/plugin_configs/:id", wgin.Wraps(h.Patch,
+ wrapper.InputType(reflect.TypeOf(PatchInput{}))))
+ r.PATCH("/apisix/admin/plugin_configs/:id/*path", wgin.Wraps(h.Patch,
+ wrapper.InputType(reflect.TypeOf(PatchInput{}))))
+ r.DELETE("/apisix/admin/plugin_configs/:ids", wgin.Wraps(h.BatchDelete,
+ wrapper.InputType(reflect.TypeOf(BatchDelete{}))))
+}
+
+type GetInput struct {
+ ID string `auto_read:"id,path" validate:"required"`
+}
+
+func (h *Handler) Get(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*GetInput)
+
+ pluginConfig, err := h.pluginConfigStore.Get(c.Context(), input.ID)
+ if err != nil {
+ return handler.SpecCodeResponse(err), err
+ }
+
+ return pluginConfig, nil
+}
+
+type ListInput struct {
+ Search string `auto_read:"search,query"`
+ store.Pagination
+}
+
+// swagger:operation GET /apisix/admin/plugin_configs getPluginConfigList
+//
+// Return the plugin_config list according to the specified page number and page size, and support search.
+//
+// ---
+// produces:
+// - application/json
+// parameters:
+// - name: page
+// in: query
+// description: page number
+// required: false
+// type: integer
+// - name: page_size
+// in: query
+// description: page size
+// required: false
+// type: integer
+// - name: search
+// in: query
+// description: search keyword
+// required: false
+// type: string
+// responses:
+// '0':
+// description: list response
+// schema:
+// type: array
+// items:
+// "$ref": "#/definitions/pluginConfig"
+// default:
+// description: unexpected error
+// schema:
+// "$ref": "#/definitions/ApiError"
+func (h *Handler) List(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*ListInput)
+
+ ret, err := h.pluginConfigStore.List(c.Context(), store.ListInput{
+ Predicate: func(obj interface{}) bool {
+ if input.Search != "" {
+ return strings.Contains(obj.(*entity.PluginConfig).Desc, input.Search)
+ }
+ return true
+ },
+ PageSize: input.PageSize,
+ PageNumber: input.PageNumber,
+ })
+ if err != nil {
+ return nil, err
+ }
+
+ return ret, nil
+}
+
+func (h *Handler) Create(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*entity.PluginConfig)
+
+ ret, err := h.pluginConfigStore.Create(c.Context(), input)
+ if err != nil {
+ return handler.SpecCodeResponse(err), err
+ }
+
+ return ret, nil
+}
+
+type UpdateInput struct {
+ ID string `auto_read:"id,path"`
+ entity.PluginConfig
+}
+
+func (h *Handler) Update(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*UpdateInput)
+
+ // check if ID in body is equal ID in path
+ if err := handler.IDCompare(input.ID, input.PluginConfig.ID); err != nil {
+ return &data.SpecCodeResponse{StatusCode: http.StatusBadRequest}, err
+ }
+
+ if input.ID != "" {
+ input.PluginConfig.ID = input.ID
+ }
+
+ ret, err := h.pluginConfigStore.Update(c.Context(), &input.PluginConfig, true)
+ if err != nil {
+ return handler.SpecCodeResponse(err), err
+ }
+
+ return ret, nil
+}
+
+type BatchDelete struct {
+ IDs string `auto_read:"ids,path"`
+}
+
+func (h *Handler) BatchDelete(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*BatchDelete)
+
+ if err := h.pluginConfigStore.BatchDelete(c.Context(), strings.Split(input.IDs, ",")); err != nil {
+ return handler.SpecCodeResponse(err), err
+ }
Review comment:
IMO, we need to check whether it is used when deleting it.
----------------------------------------------------------------
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 #1509: feat: support plugin config
Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #1509:
URL: https://github.com/apache/apisix-dashboard/pull/1509#issuecomment-787705132
----------------------------------------------------------------
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 #1509: feat: support plugin config
Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #1509:
URL: https://github.com/apache/apisix-dashboard/pull/1509#issuecomment-787705132
----------------------------------------------------------------
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 #1509: feat: support plugin config
Posted by GitBox <gi...@apache.org>.
nic-chen commented on a change in pull request #1509:
URL: https://github.com/apache/apisix-dashboard/pull/1509#discussion_r584492294
##########
File path: api/internal/core/store/storehub.go
##########
@@ -36,6 +36,7 @@ const (
HubKeyScript HubKey = "script"
HubKeyGlobalRule HubKey = "global_rule"
HubKeyServerInfo HubKey = "server_info"
+ HubKeyPluginConfig HubKey = "plugin_config"
Review comment:
fixed.
##########
File path: api/internal/handler/plugin_config/plugin_config.go
##########
@@ -0,0 +1,228 @@
+/*
+ * 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 plugin_config
+
+import (
+ "encoding/json"
+ "net/http"
+ "reflect"
+ "strings"
+
+ "github.com/gin-gonic/gin"
+ "github.com/shiningrush/droplet"
+ "github.com/shiningrush/droplet/data"
+ "github.com/shiningrush/droplet/wrapper"
+ wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+ "github.com/apisix/manager-api/internal/core/entity"
+ "github.com/apisix/manager-api/internal/core/store"
+ "github.com/apisix/manager-api/internal/handler"
+ "github.com/apisix/manager-api/internal/log"
+ "github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+ pluginConfigStore store.Interface
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+ return &Handler{
+ pluginConfigStore: store.GetStore(store.HubKeyPluginConfig),
+ }, nil
+}
+
+func (h *Handler) ApplyRoute(r *gin.Engine) {
+ r.GET("/apisix/admin/plugin_configs/:id", wgin.Wraps(h.Get,
+ wrapper.InputType(reflect.TypeOf(GetInput{}))))
+ r.GET("/apisix/admin/plugin_configs", wgin.Wraps(h.List,
+ wrapper.InputType(reflect.TypeOf(ListInput{}))))
+ r.POST("/apisix/admin/plugin_configs", wgin.Wraps(h.Create,
+ wrapper.InputType(reflect.TypeOf(entity.PluginConfig{}))))
+ r.PUT("/apisix/admin/plugin_configs", wgin.Wraps(h.Update,
+ wrapper.InputType(reflect.TypeOf(UpdateInput{}))))
+ r.PUT("/apisix/admin/plugin_configs/:id", wgin.Wraps(h.Update,
+ wrapper.InputType(reflect.TypeOf(UpdateInput{}))))
+ r.PATCH("/apisix/admin/plugin_configs/:id", wgin.Wraps(h.Patch,
+ wrapper.InputType(reflect.TypeOf(PatchInput{}))))
+ r.PATCH("/apisix/admin/plugin_configs/:id/*path", wgin.Wraps(h.Patch,
+ wrapper.InputType(reflect.TypeOf(PatchInput{}))))
+ r.DELETE("/apisix/admin/plugin_configs/:ids", wgin.Wraps(h.BatchDelete,
+ wrapper.InputType(reflect.TypeOf(BatchDelete{}))))
+}
+
+type GetInput struct {
+ ID string `auto_read:"id,path" validate:"required"`
+}
+
+func (h *Handler) Get(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*GetInput)
+
+ pluginConfig, err := h.pluginConfigStore.Get(c.Context(), input.ID)
+ if err != nil {
+ return handler.SpecCodeResponse(err), err
+ }
+
+ return pluginConfig, nil
+}
+
+type ListInput struct {
+ Search string `auto_read:"search,query"`
+ store.Pagination
+}
+
+// swagger:operation GET /apisix/admin/plugin_configs getPluginConfigList
+//
+// Return the plugin_config list according to the specified page number and page size, and support search.
+//
+// ---
+// produces:
+// - application/json
+// parameters:
+// - name: page
+// in: query
+// description: page number
+// required: false
+// type: integer
+// - name: page_size
+// in: query
+// description: page size
+// required: false
+// type: integer
+// - name: search
+// in: query
+// description: search keyword
+// required: false
+// type: string
+// responses:
+// '0':
+// description: list response
+// schema:
+// type: array
+// items:
+// "$ref": "#/definitions/pluginConfig"
+// default:
+// description: unexpected error
+// schema:
+// "$ref": "#/definitions/ApiError"
+func (h *Handler) List(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*ListInput)
+
+ ret, err := h.pluginConfigStore.List(c.Context(), store.ListInput{
+ Predicate: func(obj interface{}) bool {
+ if input.Search != "" {
+ return strings.Contains(obj.(*entity.PluginConfig).Desc, input.Search)
+ }
+ return true
+ },
+ PageSize: input.PageSize,
+ PageNumber: input.PageNumber,
+ })
+ if err != nil {
+ return nil, err
+ }
+
+ return ret, nil
+}
+
+func (h *Handler) Create(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*entity.PluginConfig)
+
+ ret, err := h.pluginConfigStore.Create(c.Context(), input)
+ if err != nil {
+ return handler.SpecCodeResponse(err), err
+ }
+
+ return ret, nil
+}
+
+type UpdateInput struct {
+ ID string `auto_read:"id,path"`
+ entity.PluginConfig
+}
+
+func (h *Handler) Update(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*UpdateInput)
+
+ // check if ID in body is equal ID in path
+ if err := handler.IDCompare(input.ID, input.PluginConfig.ID); err != nil {
+ return &data.SpecCodeResponse{StatusCode: http.StatusBadRequest}, err
+ }
+
+ if input.ID != "" {
+ input.PluginConfig.ID = input.ID
+ }
+
+ ret, err := h.pluginConfigStore.Update(c.Context(), &input.PluginConfig, true)
+ if err != nil {
+ return handler.SpecCodeResponse(err), err
+ }
+
+ return ret, nil
+}
+
+type BatchDelete struct {
+ IDs string `auto_read:"ids,path"`
+}
+
+func (h *Handler) BatchDelete(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*BatchDelete)
+
+ if err := h.pluginConfigStore.BatchDelete(c.Context(), strings.Split(input.IDs, ",")); err != nil {
+ return handler.SpecCodeResponse(err), err
+ }
Review comment:
updated.
##########
File path: api/internal/handler/plugin_config/plugin_config.go
##########
@@ -0,0 +1,228 @@
+/*
+ * 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 plugin_config
+
+import (
+ "encoding/json"
+ "net/http"
+ "reflect"
+ "strings"
+
+ "github.com/gin-gonic/gin"
+ "github.com/shiningrush/droplet"
+ "github.com/shiningrush/droplet/data"
+ "github.com/shiningrush/droplet/wrapper"
+ wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+ "github.com/apisix/manager-api/internal/core/entity"
+ "github.com/apisix/manager-api/internal/core/store"
+ "github.com/apisix/manager-api/internal/handler"
+ "github.com/apisix/manager-api/internal/log"
+ "github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+ pluginConfigStore store.Interface
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+ return &Handler{
+ pluginConfigStore: store.GetStore(store.HubKeyPluginConfig),
+ }, nil
+}
+
+func (h *Handler) ApplyRoute(r *gin.Engine) {
+ r.GET("/apisix/admin/plugin_configs/:id", wgin.Wraps(h.Get,
+ wrapper.InputType(reflect.TypeOf(GetInput{}))))
+ r.GET("/apisix/admin/plugin_configs", wgin.Wraps(h.List,
+ wrapper.InputType(reflect.TypeOf(ListInput{}))))
+ r.POST("/apisix/admin/plugin_configs", wgin.Wraps(h.Create,
+ wrapper.InputType(reflect.TypeOf(entity.PluginConfig{}))))
+ r.PUT("/apisix/admin/plugin_configs", wgin.Wraps(h.Update,
+ wrapper.InputType(reflect.TypeOf(UpdateInput{}))))
+ r.PUT("/apisix/admin/plugin_configs/:id", wgin.Wraps(h.Update,
+ wrapper.InputType(reflect.TypeOf(UpdateInput{}))))
+ r.PATCH("/apisix/admin/plugin_configs/:id", wgin.Wraps(h.Patch,
+ wrapper.InputType(reflect.TypeOf(PatchInput{}))))
+ r.PATCH("/apisix/admin/plugin_configs/:id/*path", wgin.Wraps(h.Patch,
+ wrapper.InputType(reflect.TypeOf(PatchInput{}))))
+ r.DELETE("/apisix/admin/plugin_configs/:ids", wgin.Wraps(h.BatchDelete,
+ wrapper.InputType(reflect.TypeOf(BatchDelete{}))))
+}
+
+type GetInput struct {
+ ID string `auto_read:"id,path" validate:"required"`
+}
+
+func (h *Handler) Get(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*GetInput)
+
+ pluginConfig, err := h.pluginConfigStore.Get(c.Context(), input.ID)
+ if err != nil {
+ return handler.SpecCodeResponse(err), err
+ }
+
+ return pluginConfig, nil
+}
+
+type ListInput struct {
+ Search string `auto_read:"search,query"`
+ store.Pagination
+}
+
+// swagger:operation GET /apisix/admin/plugin_configs getPluginConfigList
+//
+// Return the plugin_config list according to the specified page number and page size, and support search.
+//
+// ---
+// produces:
+// - application/json
+// parameters:
+// - name: page
+// in: query
+// description: page number
+// required: false
+// type: integer
+// - name: page_size
+// in: query
+// description: page size
+// required: false
+// type: integer
+// - name: search
+// in: query
+// description: search keyword
+// required: false
+// type: string
+// responses:
+// '0':
+// description: list response
+// schema:
+// type: array
+// items:
+// "$ref": "#/definitions/pluginConfig"
+// default:
+// description: unexpected error
+// schema:
+// "$ref": "#/definitions/ApiError"
+func (h *Handler) List(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*ListInput)
+
+ ret, err := h.pluginConfigStore.List(c.Context(), store.ListInput{
+ Predicate: func(obj interface{}) bool {
+ if input.Search != "" {
+ return strings.Contains(obj.(*entity.PluginConfig).Desc, input.Search)
+ }
+ return true
+ },
+ PageSize: input.PageSize,
+ PageNumber: input.PageNumber,
+ })
+ if err != nil {
+ return nil, err
+ }
+
+ return ret, nil
+}
+
+func (h *Handler) Create(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*entity.PluginConfig)
+
+ ret, err := h.pluginConfigStore.Create(c.Context(), input)
+ if err != nil {
+ return handler.SpecCodeResponse(err), err
+ }
+
+ return ret, nil
+}
+
+type UpdateInput struct {
+ ID string `auto_read:"id,path"`
+ entity.PluginConfig
+}
+
+func (h *Handler) Update(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*UpdateInput)
+
+ // check if ID in body is equal ID in path
+ if err := handler.IDCompare(input.ID, input.PluginConfig.ID); err != nil {
+ return &data.SpecCodeResponse{StatusCode: http.StatusBadRequest}, err
+ }
+
+ if input.ID != "" {
+ input.PluginConfig.ID = input.ID
+ }
+
+ ret, err := h.pluginConfigStore.Update(c.Context(), &input.PluginConfig, true)
+ if err != nil {
+ return handler.SpecCodeResponse(err), err
+ }
+
+ return ret, nil
+}
+
+type BatchDelete struct {
+ IDs string `auto_read:"ids,path"`
+}
+
+func (h *Handler) BatchDelete(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*BatchDelete)
+
+ if err := h.pluginConfigStore.BatchDelete(c.Context(), strings.Split(input.IDs, ",")); err != nil {
+ return handler.SpecCodeResponse(err), err
+ }
+
+ return nil, nil
+}
+
+type PatchInput struct {
+ ID string `auto_read:"id,path"`
+ SubPath string `auto_read:"path,path"`
+ Body []byte `auto_read:"@body"`
+}
+
+func (h *Handler) Patch(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*PatchInput)
+ reqBody := input.Body
+ id := input.ID
+ subPath := input.SubPath
+
+ stored, err := h.pluginConfigStore.Get(c.Context(), id)
+ if err != nil {
+ log.Warnf("%s", err)
+ return handler.SpecCodeResponse(err), err
+ }
+
+ res, err := utils.MergePatch(stored, subPath, reqBody)
+ if err != nil {
+ log.Warnf("%s", err)
+ return handler.SpecCodeResponse(err), err
+ }
+
+ var pluginConfig entity.PluginConfig
+ if err := json.Unmarshal(res, &pluginConfig); err != nil {
+ log.Warnf("%s", err)
+ return handler.SpecCodeResponse(err), err
+ }
+
+ ret, err := h.pluginConfigStore.Update(c.Context(), &pluginConfig, false)
+ if err != nil {
+ log.Warnf("%s", err)
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 #1509: feat: support plugin config
Posted by GitBox <gi...@apache.org>.
nic-chen commented on a change in pull request #1509:
URL: https://github.com/apache/apisix-dashboard/pull/1509#discussion_r584825352
##########
File path: api/test/e2enew/plugin_config/plugin_config_test.go
##########
@@ -0,0 +1,189 @@
+/*
+ * 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 plugin_config
+
+import (
+ "net/http"
+
+ "github.com/onsi/ginkgo"
+ "github.com/onsi/ginkgo/extensions/table"
+
+ "e2enew/base"
+)
+
+var _ = ginkgo.Describe("Plugin Config", func() {
+ table.DescribeTable("test plugin config",
+ func(tc base.HttpTestCase) {
+ base.RunTestCase(tc)
+ },
+ table.Entry("make sure the route doesn't exist", base.HttpTestCase{
+ Object: base.APISIXExpect(),
+ Method: http.MethodGet,
+ Path: "/hello",
+ ExpectStatus: http.StatusNotFound,
+ ExpectBody: `{"error_msg":"404 Route Not Found"}`,
+ }),
+ table.Entry("create plugin config", base.HttpTestCase{
+ Object: base.ManagerApiExpect(),
+ Path: "/apisix/admin/plugin_configs/1",
+ Method: http.MethodPut,
+ Body: `{
+ "plugins": {
+ "response-rewrite": {
+ "headers": {
+ "X-VERSION":"1.0"
+ }
+ },
+ "uri-blocker": {
+ "block_rules": ["select.+(from|limit)", "(?:(union(.*?)select))"]
+ }
+ }
+ }`,
+ Headers: map[string]string{"Authorization": base.GetToken()},
+ ExpectStatus: http.StatusOK,
+ }),
+ table.Entry("create route with the plugin config created before", base.HttpTestCase{
+ Object: base.ManagerApiExpect(),
+ Method: http.MethodPut,
+ Path: "/apisix/admin/routes/r1",
+ Body: `{
+ "uri": "/hello",
+ "plugin_config_id": "1",
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": [{
+ "host": "` + base.UpstreamIp + `",
+ "port": 1981,
+ "weight": 1
+ }]
+ }
+ }`,
+ Headers: map[string]string{"Authorization": base.GetToken()},
+ ExpectStatus: http.StatusOK,
+ }),
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] tokers commented on a change in pull request #1509: feat: support plugin config
Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #1509:
URL: https://github.com/apache/apisix-dashboard/pull/1509#discussion_r586151927
##########
File path: api/test/e2e/label_test.go
##########
@@ -302,6 +333,14 @@ func TestLabel(t *testing.T) {
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusOK,
},
+ {
Review comment:
Can `plugin_config` be updated? If so, we should also add update test suites.
----------------------------------------------------------------
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] starsz commented on a change in pull request #1509: feat: support plugin config
Posted by GitBox <gi...@apache.org>.
starsz commented on a change in pull request #1509:
URL: https://github.com/apache/apisix-dashboard/pull/1509#discussion_r585216789
##########
File path: api/test/e2enew/plugin_config/plugin_config_test.go
##########
@@ -0,0 +1,197 @@
+/*
+ * 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 plugin_config
+
+import (
+ "net/http"
+
+ "github.com/onsi/ginkgo"
+ "github.com/onsi/ginkgo/extensions/table"
+
+ "e2enew/base"
+)
+
+var _ = ginkgo.Describe("Plugin Config", func() {
+ table.DescribeTable("test plugin config",
+ func(tc base.HttpTestCase) {
+ base.RunTestCase(tc)
+ },
+ table.Entry("make sure the route doesn't exist", base.HttpTestCase{
+ Object: base.APISIXExpect(),
+ Method: http.MethodGet,
+ Path: "/hello",
+ ExpectStatus: http.StatusNotFound,
+ ExpectBody: `{"error_msg":"404 Route Not Found"}`,
+ }),
+ table.Entry("create plugin config", base.HttpTestCase{
+ Object: base.ManagerApiExpect(),
+ Path: "/apisix/admin/plugin_configs/1",
+ Method: http.MethodPut,
+ Body: `{
+ "plugins": {
+ "response-rewrite": {
+ "headers": {
+ "X-VERSION":"1.0"
+ }
+ },
+ "uri-blocker": {
+ "block_rules": ["select.+(from|limit)", "(?:(union(.*?)select))"]
+ }
+ }
+ }`,
+ Headers: map[string]string{"Authorization": base.GetToken()},
+ ExpectStatus: http.StatusOK,
+ }),
+ table.Entry("create plugin config", base.HttpTestCase{
Review comment:
It seems `create plugin config` => `get plugin config`.
##########
File path: api/test/e2enew/plugin_config/plugin_config_test.go
##########
@@ -0,0 +1,197 @@
+/*
+ * 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 plugin_config
+
+import (
+ "net/http"
+
+ "github.com/onsi/ginkgo"
+ "github.com/onsi/ginkgo/extensions/table"
+
+ "e2enew/base"
+)
+
+var _ = ginkgo.Describe("Plugin Config", func() {
+ table.DescribeTable("test plugin config",
+ func(tc base.HttpTestCase) {
+ base.RunTestCase(tc)
+ },
+ table.Entry("make sure the route doesn't exist", base.HttpTestCase{
+ Object: base.APISIXExpect(),
+ Method: http.MethodGet,
+ Path: "/hello",
+ ExpectStatus: http.StatusNotFound,
+ ExpectBody: `{"error_msg":"404 Route Not Found"}`,
+ }),
+ table.Entry("create plugin config", base.HttpTestCase{
+ Object: base.ManagerApiExpect(),
+ Path: "/apisix/admin/plugin_configs/1",
+ Method: http.MethodPut,
+ Body: `{
+ "plugins": {
+ "response-rewrite": {
+ "headers": {
+ "X-VERSION":"1.0"
+ }
+ },
+ "uri-blocker": {
+ "block_rules": ["select.+(from|limit)", "(?:(union(.*?)select))"]
+ }
+ }
+ }`,
+ Headers: map[string]string{"Authorization": base.GetToken()},
+ ExpectStatus: http.StatusOK,
+ }),
+ table.Entry("create plugin config", base.HttpTestCase{
+ Object: base.ManagerApiExpect(),
+ Path: "/apisix/admin/plugin_configs/1",
Review comment:
Need to test `list` function.
----------------------------------------------------------------
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 #1509: feat: support plugin config
Posted by GitBox <gi...@apache.org>.
nic-chen commented on a change in pull request #1509:
URL: https://github.com/apache/apisix-dashboard/pull/1509#discussion_r584480126
##########
File path: api/internal/handler/plugin_config/plugin_config.go
##########
@@ -0,0 +1,228 @@
+/*
+ * 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 plugin_config
+
+import (
+ "encoding/json"
+ "net/http"
+ "reflect"
+ "strings"
+
+ "github.com/gin-gonic/gin"
+ "github.com/shiningrush/droplet"
+ "github.com/shiningrush/droplet/data"
+ "github.com/shiningrush/droplet/wrapper"
+ wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+ "github.com/apisix/manager-api/internal/core/entity"
+ "github.com/apisix/manager-api/internal/core/store"
+ "github.com/apisix/manager-api/internal/handler"
+ "github.com/apisix/manager-api/internal/log"
+ "github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+ pluginConfigStore store.Interface
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+ return &Handler{
+ pluginConfigStore: store.GetStore(store.HubKeyPluginConfig),
+ }, nil
+}
+
+func (h *Handler) ApplyRoute(r *gin.Engine) {
+ r.GET("/apisix/admin/plugin_configs/:id", wgin.Wraps(h.Get,
+ wrapper.InputType(reflect.TypeOf(GetInput{}))))
+ r.GET("/apisix/admin/plugin_configs", wgin.Wraps(h.List,
+ wrapper.InputType(reflect.TypeOf(ListInput{}))))
+ r.POST("/apisix/admin/plugin_configs", wgin.Wraps(h.Create,
+ wrapper.InputType(reflect.TypeOf(entity.PluginConfig{}))))
+ r.PUT("/apisix/admin/plugin_configs", wgin.Wraps(h.Update,
+ wrapper.InputType(reflect.TypeOf(UpdateInput{}))))
+ r.PUT("/apisix/admin/plugin_configs/:id", wgin.Wraps(h.Update,
+ wrapper.InputType(reflect.TypeOf(UpdateInput{}))))
+ r.PATCH("/apisix/admin/plugin_configs/:id", wgin.Wraps(h.Patch,
+ wrapper.InputType(reflect.TypeOf(PatchInput{}))))
+ r.PATCH("/apisix/admin/plugin_configs/:id/*path", wgin.Wraps(h.Patch,
+ wrapper.InputType(reflect.TypeOf(PatchInput{}))))
+ r.DELETE("/apisix/admin/plugin_configs/:ids", wgin.Wraps(h.BatchDelete,
+ wrapper.InputType(reflect.TypeOf(BatchDelete{}))))
+}
+
+type GetInput struct {
+ ID string `auto_read:"id,path" validate:"required"`
+}
+
+func (h *Handler) Get(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*GetInput)
+
+ pluginConfig, err := h.pluginConfigStore.Get(c.Context(), input.ID)
+ if err != nil {
+ return handler.SpecCodeResponse(err), err
+ }
+
+ return pluginConfig, nil
+}
+
+type ListInput struct {
+ Search string `auto_read:"search,query"`
+ store.Pagination
+}
+
+// swagger:operation GET /apisix/admin/plugin_configs getPluginConfigList
+//
+// Return the plugin_config list according to the specified page number and page size, and support search.
+//
+// ---
+// produces:
+// - application/json
+// parameters:
+// - name: page
+// in: query
+// description: page number
+// required: false
+// type: integer
+// - name: page_size
+// in: query
+// description: page size
+// required: false
+// type: integer
+// - name: search
+// in: query
+// description: search keyword
+// required: false
+// type: string
+// responses:
+// '0':
+// description: list response
+// schema:
+// type: array
+// items:
+// "$ref": "#/definitions/pluginConfig"
+// default:
+// description: unexpected error
+// schema:
+// "$ref": "#/definitions/ApiError"
+func (h *Handler) List(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*ListInput)
+
+ ret, err := h.pluginConfigStore.List(c.Context(), store.ListInput{
+ Predicate: func(obj interface{}) bool {
+ if input.Search != "" {
+ return strings.Contains(obj.(*entity.PluginConfig).Desc, input.Search)
+ }
+ return true
+ },
+ PageSize: input.PageSize,
+ PageNumber: input.PageNumber,
+ })
+ if err != nil {
+ return nil, err
+ }
+
+ return ret, nil
+}
+
+func (h *Handler) Create(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*entity.PluginConfig)
+
+ ret, err := h.pluginConfigStore.Create(c.Context(), input)
+ if err != nil {
+ return handler.SpecCodeResponse(err), err
+ }
+
+ return ret, nil
+}
+
+type UpdateInput struct {
+ ID string `auto_read:"id,path"`
+ entity.PluginConfig
+}
+
+func (h *Handler) Update(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*UpdateInput)
+
+ // check if ID in body is equal ID in path
+ if err := handler.IDCompare(input.ID, input.PluginConfig.ID); err != nil {
+ return &data.SpecCodeResponse{StatusCode: http.StatusBadRequest}, err
+ }
+
+ if input.ID != "" {
+ input.PluginConfig.ID = input.ID
+ }
+
+ ret, err := h.pluginConfigStore.Update(c.Context(), &input.PluginConfig, true)
Review comment:
> Please make sure about the third args in `h.pluginConfigStore.Update`.
> We should create it if not exist?
sure, we support create by `PUT`
----------------------------------------------------------------
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] gxthrj commented on pull request #1509: feat: support plugin config
Posted by GitBox <gi...@apache.org>.
gxthrj commented on pull request #1509:
URL: https://github.com/apache/apisix-dashboard/pull/1509#issuecomment-788793108
E2E test failed
----------------------------------------------------------------
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 #1509: feat: support plugin config
Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #1509:
URL: https://github.com/apache/apisix-dashboard/pull/1509#issuecomment-787705132
# [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?src=pr&el=h1) Report
> Merging [#1509](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?src=pr&el=desc) (6a13c92) into [master](https://codecov.io/gh/apache/apisix-dashboard/commit/2dbd204d1f42fb9eb425b4cdc7f190adedfc667e?el=desc) (2dbd204) will **decrease** coverage by `8.02%`.
> The diff coverage is `62.60%`.
[![Impacted file tree graph](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/graphs/tree.svg?width=650&height=150&src=pr&token=Q1HERXN96P)](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #1509 +/- ##
==========================================
- Coverage 70.12% 62.09% -8.03%
==========================================
Files 129 130 +1
Lines 5231 5340 +109
Branches 549 549
==========================================
- Hits 3668 3316 -352
- Misses 1323 1723 +400
- Partials 240 301 +61
```
| Flag | Coverage Δ | |
|---|---|---|
| backend-e2e-test | `55.46% <62.60%> (-0.15%)` | :arrow_down: |
| backend-e2e-test-ginkgo | `38.27% <58.26%> (+4.69%)` | :arrow_up: |
| backend-unit-test | `?` | |
| frontend-e2e-test | `71.73% <ø> (ø)` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.
| [Impacted Files](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [api/internal/core/entity/entity.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvZW50aXR5L2VudGl0eS5nbw==) | `100.00% <ø> (ø)` | |
| [...pi/internal/handler/plugin\_config/plugin\_config.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvcGx1Z2luX2NvbmZpZy9wbHVnaW5fY29uZmlnLmdv) | `56.38% <56.38%> (ø)` | |
| [api/internal/core/store/storehub.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvc3RvcmVodWIuZ28=) | `71.02% <77.77%> (-3.47%)` | :arrow_down: |
| [api/internal/handler/label/label.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvbGFiZWwvbGFiZWwuZ28=) | `80.18% <100.00%> (-1.00%)` | :arrow_down: |
| [api/internal/route.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL3JvdXRlLmdv) | `85.71% <100.00%> (+0.42%)` | :arrow_up: |
| [api/internal/core/store/query.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvcXVlcnkuZ28=) | `0.00% <0.00%> (-88.10%)` | :arrow_down: |
| [api/internal/core/store/selector.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvc2VsZWN0b3IuZ28=) | `0.00% <0.00%> (-75.93%)` | :arrow_down: |
| [api/internal/handler/plugin/plugin.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvcGx1Z2luL3BsdWdpbi5nbw==) | `15.15% <0.00%> (-72.73%)` | :arrow_down: |
| [api/internal/utils/runtime/runtime.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL3V0aWxzL3J1bnRpbWUvcnVudGltZS5nbw==) | `0.00% <0.00%> (-64.29%)` | :arrow_down: |
| [api/internal/core/store/validate\_mock.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvdmFsaWRhdGVfbW9jay5nbw==) | `0.00% <0.00%> (-50.00%)` | :arrow_down: |
| ... and [22 more](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree-more) | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?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/1509?src=pr&el=footer). Last update [2dbd204...6a13c92](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?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 commented on pull request #1509: feat: support plugin config
Posted by GitBox <gi...@apache.org>.
codecov-io commented on pull request #1509:
URL: https://github.com/apache/apisix-dashboard/pull/1509#issuecomment-787705132
# [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?src=pr&el=h1) Report
> Merging [#1509](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?src=pr&el=desc) (55ba5f7) into [master](https://codecov.io/gh/apache/apisix-dashboard/commit/816ba9ec5e37327e151ca095a280ee2d087097f1?el=desc) (816ba9e) will **decrease** coverage by `17.69%`.
> The diff coverage is `28.04%`.
[![Impacted file tree graph](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/graphs/tree.svg?width=650&height=150&src=pr&token=Q1HERXN96P)](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #1509 +/- ##
===========================================
- Coverage 68.61% 50.92% -17.70%
===========================================
Files 48 49 +1
Lines 3056 3138 +82
===========================================
- Hits 2097 1598 -499
- Misses 718 1274 +556
- Partials 241 266 +25
```
| [Impacted Files](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [api/internal/core/entity/entity.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvZW50aXR5L2VudGl0eS5nbw==) | `81.25% <ø> (-18.75%)` | :arrow_down: |
| [...pi/internal/handler/plugin\_config/plugin\_config.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvcGx1Z2luX2NvbmZpZy9wbHVnaW5fY29uZmlnLmdv) | `26.38% <26.38%> (ø)` | |
| [api/internal/core/store/storehub.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvc3RvcmVodWIuZ28=) | `67.28% <33.33%> (-3.12%)` | :arrow_down: |
| [api/internal/route.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL3JvdXRlLmdv) | `85.71% <100.00%> (+0.42%)` | :arrow_up: |
| [api/internal/core/store/query.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvcXVlcnkuZ28=) | `0.00% <0.00%> (-88.10%)` | :arrow_down: |
| [api/internal/handler/tool/tool.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvdG9vbC90b29sLmdv) | `13.88% <0.00%> (-80.56%)` | :arrow_down: |
| [api/internal/core/store/selector.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvc2VsZWN0b3IuZ28=) | `0.00% <0.00%> (-75.93%)` | :arrow_down: |
| [api/internal/handler/plugin/plugin.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvcGx1Z2luL3BsdWdpbi5nbw==) | `15.15% <0.00%> (-72.73%)` | :arrow_down: |
| [...l/handler/route\_online\_debug/route\_online\_debug.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvcm91dGVfb25saW5lX2RlYnVnL3JvdXRlX29ubGluZV9kZWJ1Zy5nbw==) | `5.88% <0.00%> (-68.63%)` | :arrow_down: |
| [api/internal/utils/runtime/runtime.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL3V0aWxzL3J1bnRpbWUvcnVudGltZS5nbw==) | `0.00% <0.00%> (-64.29%)` | :arrow_down: |
| ... and [22 more](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree-more) | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?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/1509?src=pr&el=footer). Last update [816ba9e...55ba5f7](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?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 #1509: feat: support plugin config
Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #1509:
URL: https://github.com/apache/apisix-dashboard/pull/1509#issuecomment-787705132
# [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?src=pr&el=h1) Report
> Merging [#1509](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?src=pr&el=desc) (6a13c92) into [master](https://codecov.io/gh/apache/apisix-dashboard/commit/2dbd204d1f42fb9eb425b4cdc7f190adedfc667e?el=desc) (2dbd204) will **decrease** coverage by `31.84%`.
> The diff coverage is `58.26%`.
[![Impacted file tree graph](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/graphs/tree.svg?width=650&height=150&src=pr&token=Q1HERXN96P)](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #1509 +/- ##
===========================================
- Coverage 70.12% 38.27% -31.85%
===========================================
Files 129 49 -80
Lines 5231 3164 -2067
Branches 549 0 -549
===========================================
- Hits 3668 1211 -2457
- Misses 1323 1700 +377
- Partials 240 253 +13
```
| Flag | Coverage Δ | |
|---|---|---|
| backend-e2e-test | `?` | |
| backend-e2e-test-ginkgo | `38.27% <58.26%> (+4.69%)` | :arrow_up: |
| backend-unit-test | `?` | |
| frontend-e2e-test | `?` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.
| [Impacted Files](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [api/internal/core/entity/entity.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvZW50aXR5L2VudGl0eS5nbw==) | `75.00% <ø> (-25.00%)` | :arrow_down: |
| [api/internal/handler/label/label.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvbGFiZWwvbGFiZWwuZ28=) | `9.43% <54.54%> (-71.76%)` | :arrow_down: |
| [...pi/internal/handler/plugin\_config/plugin\_config.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvcGx1Z2luX2NvbmZpZy9wbHVnaW5fY29uZmlnLmdv) | `56.38% <56.38%> (ø)` | |
| [api/internal/core/store/storehub.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvc3RvcmVodWIuZ28=) | `59.81% <77.77%> (-14.68%)` | :arrow_down: |
| [api/internal/route.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL3JvdXRlLmdv) | `77.14% <100.00%> (-8.16%)` | :arrow_down: |
| [api/internal/core/store/query.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvcXVlcnkuZ28=) | `0.00% <0.00%> (-88.10%)` | :arrow_down: |
| [api/internal/core/store/selector.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvc2VsZWN0b3IuZ28=) | `0.00% <0.00%> (-75.93%)` | :arrow_down: |
| [api/internal/handler/plugin/plugin.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvcGx1Z2luL3BsdWdpbi5nbw==) | `15.15% <0.00%> (-72.73%)` | :arrow_down: |
| [api/internal/handler/service/service.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvc2VydmljZS9zZXJ2aWNlLmdv) | `21.27% <0.00%> (-70.22%)` | :arrow_down: |
| [api/internal/handler/data\_loader/route\_export.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvZGF0YV9sb2FkZXIvcm91dGVfZXhwb3J0Lmdv) | `3.38% <0.00%> (-65.79%)` | :arrow_down: |
| ... and [107 more](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree-more) | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?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/1509?src=pr&el=footer). Last update [2dbd204...6a13c92](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?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] starsz commented on a change in pull request #1509: feat: support plugin config
Posted by GitBox <gi...@apache.org>.
starsz commented on a change in pull request #1509:
URL: https://github.com/apache/apisix-dashboard/pull/1509#discussion_r584779722
##########
File path: api/test/e2enew/plugin_config/plugin_config_test.go
##########
@@ -0,0 +1,189 @@
+/*
+ * 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 plugin_config
+
+import (
+ "net/http"
+
+ "github.com/onsi/ginkgo"
+ "github.com/onsi/ginkgo/extensions/table"
+
+ "e2enew/base"
+)
+
+var _ = ginkgo.Describe("Plugin Config", func() {
+ table.DescribeTable("test plugin config",
+ func(tc base.HttpTestCase) {
+ base.RunTestCase(tc)
+ },
+ table.Entry("make sure the route doesn't exist", base.HttpTestCase{
+ Object: base.APISIXExpect(),
+ Method: http.MethodGet,
+ Path: "/hello",
+ ExpectStatus: http.StatusNotFound,
+ ExpectBody: `{"error_msg":"404 Route Not Found"}`,
+ }),
+ table.Entry("create plugin config", base.HttpTestCase{
+ Object: base.ManagerApiExpect(),
+ Path: "/apisix/admin/plugin_configs/1",
+ Method: http.MethodPut,
+ Body: `{
+ "plugins": {
+ "response-rewrite": {
+ "headers": {
+ "X-VERSION":"1.0"
+ }
+ },
+ "uri-blocker": {
+ "block_rules": ["select.+(from|limit)", "(?:(union(.*?)select))"]
+ }
+ }
+ }`,
+ Headers: map[string]string{"Authorization": base.GetToken()},
+ ExpectStatus: http.StatusOK,
+ }),
+ table.Entry("create route with the plugin config created before", base.HttpTestCase{
+ Object: base.ManagerApiExpect(),
+ Method: http.MethodPut,
+ Path: "/apisix/admin/routes/r1",
+ Body: `{
+ "uri": "/hello",
+ "plugin_config_id": "1",
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": [{
+ "host": "` + base.UpstreamIp + `",
+ "port": 1981,
+ "weight": 1
+ }]
+ }
+ }`,
+ Headers: map[string]string{"Authorization": base.GetToken()},
+ ExpectStatus: http.StatusOK,
+ }),
Review comment:
It seems missing `get plugin-config?
----------------------------------------------------------------
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] starsz commented on a change in pull request #1509: feat: support plugin config
Posted by GitBox <gi...@apache.org>.
starsz commented on a change in pull request #1509:
URL: https://github.com/apache/apisix-dashboard/pull/1509#discussion_r584769471
##########
File path: api/internal/handler/plugin_config/plugin_config.go
##########
@@ -0,0 +1,228 @@
+/*
+ * 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 plugin_config
+
+import (
+ "encoding/json"
+ "net/http"
+ "reflect"
+ "strings"
+
+ "github.com/gin-gonic/gin"
+ "github.com/shiningrush/droplet"
+ "github.com/shiningrush/droplet/data"
+ "github.com/shiningrush/droplet/wrapper"
+ wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+ "github.com/apisix/manager-api/internal/core/entity"
+ "github.com/apisix/manager-api/internal/core/store"
+ "github.com/apisix/manager-api/internal/handler"
+ "github.com/apisix/manager-api/internal/log"
+ "github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+ pluginConfigStore store.Interface
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+ return &Handler{
+ pluginConfigStore: store.GetStore(store.HubKeyPluginConfig),
+ }, nil
+}
+
+func (h *Handler) ApplyRoute(r *gin.Engine) {
+ r.GET("/apisix/admin/plugin_configs/:id", wgin.Wraps(h.Get,
+ wrapper.InputType(reflect.TypeOf(GetInput{}))))
+ r.GET("/apisix/admin/plugin_configs", wgin.Wraps(h.List,
+ wrapper.InputType(reflect.TypeOf(ListInput{}))))
+ r.POST("/apisix/admin/plugin_configs", wgin.Wraps(h.Create,
+ wrapper.InputType(reflect.TypeOf(entity.PluginConfig{}))))
+ r.PUT("/apisix/admin/plugin_configs", wgin.Wraps(h.Update,
+ wrapper.InputType(reflect.TypeOf(UpdateInput{}))))
+ r.PUT("/apisix/admin/plugin_configs/:id", wgin.Wraps(h.Update,
+ wrapper.InputType(reflect.TypeOf(UpdateInput{}))))
+ r.PATCH("/apisix/admin/plugin_configs/:id", wgin.Wraps(h.Patch,
+ wrapper.InputType(reflect.TypeOf(PatchInput{}))))
+ r.PATCH("/apisix/admin/plugin_configs/:id/*path", wgin.Wraps(h.Patch,
+ wrapper.InputType(reflect.TypeOf(PatchInput{}))))
+ r.DELETE("/apisix/admin/plugin_configs/:ids", wgin.Wraps(h.BatchDelete,
+ wrapper.InputType(reflect.TypeOf(BatchDelete{}))))
+}
+
+type GetInput struct {
+ ID string `auto_read:"id,path" validate:"required"`
+}
+
+func (h *Handler) Get(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*GetInput)
+
+ pluginConfig, err := h.pluginConfigStore.Get(c.Context(), input.ID)
+ if err != nil {
+ return handler.SpecCodeResponse(err), err
+ }
+
+ return pluginConfig, nil
+}
+
+type ListInput struct {
+ Search string `auto_read:"search,query"`
+ store.Pagination
+}
+
+// swagger:operation GET /apisix/admin/plugin_configs getPluginConfigList
+//
+// Return the plugin_config list according to the specified page number and page size, and support search.
+//
+// ---
+// produces:
+// - application/json
+// parameters:
+// - name: page
+// in: query
+// description: page number
+// required: false
+// type: integer
+// - name: page_size
+// in: query
+// description: page size
+// required: false
+// type: integer
+// - name: search
+// in: query
+// description: search keyword
+// required: false
+// type: string
+// responses:
+// '0':
+// description: list response
+// schema:
+// type: array
+// items:
+// "$ref": "#/definitions/pluginConfig"
+// default:
+// description: unexpected error
+// schema:
+// "$ref": "#/definitions/ApiError"
+func (h *Handler) List(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*ListInput)
+
+ ret, err := h.pluginConfigStore.List(c.Context(), store.ListInput{
+ Predicate: func(obj interface{}) bool {
+ if input.Search != "" {
+ return strings.Contains(obj.(*entity.PluginConfig).Desc, input.Search)
+ }
+ return true
+ },
+ PageSize: input.PageSize,
+ PageNumber: input.PageNumber,
+ })
+ if err != nil {
+ return nil, err
+ }
+
+ return ret, nil
+}
+
+func (h *Handler) Create(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*entity.PluginConfig)
+
+ ret, err := h.pluginConfigStore.Create(c.Context(), input)
+ if err != nil {
+ return handler.SpecCodeResponse(err), err
+ }
+
+ return ret, nil
+}
+
+type UpdateInput struct {
+ ID string `auto_read:"id,path"`
+ entity.PluginConfig
+}
+
+func (h *Handler) Update(c droplet.Context) (interface{}, error) {
+ input := c.Input().(*UpdateInput)
+
+ // check if ID in body is equal ID in path
+ if err := handler.IDCompare(input.ID, input.PluginConfig.ID); err != nil {
+ return &data.SpecCodeResponse{StatusCode: http.StatusBadRequest}, err
+ }
+
+ if input.ID != "" {
+ input.PluginConfig.ID = input.ID
+ }
+
+ ret, err := h.pluginConfigStore.Update(c.Context(), &input.PluginConfig, true)
Review comment:
OK.Got it.
----------------------------------------------------------------
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 merged pull request #1509: feat: support plugin config
Posted by GitBox <gi...@apache.org>.
nic-chen merged pull request #1509:
URL: https://github.com/apache/apisix-dashboard/pull/1509
----------------------------------------------------------------
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 #1509: feat: support plugin config
Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #1509:
URL: https://github.com/apache/apisix-dashboard/pull/1509#issuecomment-787705132
# [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?src=pr&el=h1) Report
> Merging [#1509](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?src=pr&el=desc) (6a13c92) into [master](https://codecov.io/gh/apache/apisix-dashboard/commit/2dbd204d1f42fb9eb425b4cdc7f190adedfc667e?el=desc) (2dbd204) will **decrease** coverage by `14.65%`.
> The diff coverage is `62.60%`.
[![Impacted file tree graph](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/graphs/tree.svg?width=650&height=150&src=pr&token=Q1HERXN96P)](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #1509 +/- ##
===========================================
- Coverage 70.12% 55.46% -14.66%
===========================================
Files 129 49 -80
Lines 5231 3164 -2067
Branches 549 0 -549
===========================================
- Hits 3668 1755 -1913
+ Misses 1323 1108 -215
- Partials 240 301 +61
```
| Flag | Coverage Δ | |
|---|---|---|
| backend-e2e-test | `55.46% <62.60%> (-0.15%)` | :arrow_down: |
| backend-e2e-test-ginkgo | `38.27% <58.26%> (+4.69%)` | :arrow_up: |
| backend-unit-test | `?` | |
| frontend-e2e-test | `?` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.
| [Impacted Files](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [api/internal/core/entity/entity.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvZW50aXR5L2VudGl0eS5nbw==) | `100.00% <ø> (ø)` | |
| [...pi/internal/handler/plugin\_config/plugin\_config.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvcGx1Z2luX2NvbmZpZy9wbHVnaW5fY29uZmlnLmdv) | `56.38% <56.38%> (ø)` | |
| [api/internal/core/store/storehub.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvc3RvcmVodWIuZ28=) | `71.02% <77.77%> (-3.47%)` | :arrow_down: |
| [api/internal/handler/label/label.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvbGFiZWwvbGFiZWwuZ28=) | `80.18% <100.00%> (-1.00%)` | :arrow_down: |
| [api/internal/route.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL3JvdXRlLmdv) | `85.71% <100.00%> (+0.42%)` | :arrow_up: |
| [api/internal/core/store/query.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvcXVlcnkuZ28=) | `0.00% <0.00%> (-88.10%)` | :arrow_down: |
| [api/internal/core/store/selector.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvc2VsZWN0b3IuZ28=) | `0.00% <0.00%> (-75.93%)` | :arrow_down: |
| [api/internal/handler/plugin/plugin.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvcGx1Z2luL3BsdWdpbi5nbw==) | `15.15% <0.00%> (-72.73%)` | :arrow_down: |
| [api/internal/utils/runtime/runtime.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL3V0aWxzL3J1bnRpbWUvcnVudGltZS5nbw==) | `0.00% <0.00%> (-64.29%)` | :arrow_down: |
| [api/internal/core/store/validate\_mock.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvdmFsaWRhdGVfbW9jay5nbw==) | `0.00% <0.00%> (-50.00%)` | :arrow_down: |
| ... and [103 more](https://codecov.io/gh/apache/apisix-dashboard/pull/1509/diff?src=pr&el=tree-more) | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?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/1509?src=pr&el=footer). Last update [2dbd204...6a13c92](https://codecov.io/gh/apache/apisix-dashboard/pull/1509?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