You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/09/19 01:16:44 UTC
[GitHub] [apisix-dashboard] nic-chen opened a new pull request #486: feat: add consumer CURD refactoring
nic-chen opened a new pull request #486:
URL: https://github.com/apache/apisix-dashboard/pull/486
Please answer these questions before submitting a pull request
- Why submit this pull request?
add consumer CURD refactoring
----------------------------------------------------------------
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 #486: feat: add consumer CURD refactoring
Posted by GitBox <gi...@apache.org>.
nic-chen commented on a change in pull request #486:
URL: https://github.com/apache/apisix-dashboard/pull/486#discussion_r491411145
##########
File path: api/internal/handler/consumer/consumer.go
##########
@@ -0,0 +1,135 @@
+package consumer
+
+import (
+ "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/utils"
+)
+
+type Handler struct {
+ consumerStore *store.GenericStore
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+ s, err := store.NewGenericStore(store.GenericStoreOption{
+ BasePath: "/apisix/consumers",
+ ObjType: reflect.TypeOf(entity.Consumer{}),
+ KeyFunc: func(obj interface{}) string {
+ r := obj.(*entity.Consumer)
+ return r.Username
Review comment:
@ShiningRush
username is used as key for consumer not ID.
see:
https://github.com/apache/apisix/blob/master/apisix/admin/consumers.lua#L77
----------------------------------------------------------------
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] ShiningRush commented on a change in pull request #486: feat: add consumer CURD refactoring
Posted by GitBox <gi...@apache.org>.
ShiningRush commented on a change in pull request #486:
URL: https://github.com/apache/apisix-dashboard/pull/486#discussion_r491256585
##########
File path: api/internal/handler/consumer/consumer.go
##########
@@ -0,0 +1,135 @@
+package consumer
+
+import (
+ "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"
Review comment:
this is a gin wrapper for the droplet
----------------------------------------------------------------
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 #486: feat: add consumer CURD refactoring
Posted by GitBox <gi...@apache.org>.
nic-chen commented on a change in pull request #486:
URL: https://github.com/apache/apisix-dashboard/pull/486#discussion_r491408586
##########
File path: api/route/base.go
##########
@@ -37,19 +38,20 @@ func SetUpRouter() *gin.Engine {
r := gin.New()
store := cookie.NewStore([]byte("secret"))
r.Use(sessions.Sessions("session", store))
- r.Use(filter.CORS(), filter.Authentication(), filter.RequestId(), filter.RecoverHandler())
+ r.Use(filter.CORS(), filter.Authentication(), filter.RequestId(), filter.RecoverHandler()) //
Review comment:
removed. @juzhiyuan
----------------------------------------------------------------
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] ShiningRush commented on a change in pull request #486: feat: add consumer CURD refactoring
Posted by GitBox <gi...@apache.org>.
ShiningRush commented on a change in pull request #486:
URL: https://github.com/apache/apisix-dashboard/pull/486#discussion_r491256497
##########
File path: api/internal/handler/consumer/consumer.go
##########
@@ -0,0 +1,135 @@
+package consumer
+
+import (
+ "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/utils"
+)
+
+type Handler struct {
+ consumerStore *store.GenericStore
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+ s, err := store.NewGenericStore(store.GenericStoreOption{
+ BasePath: "/apisix/consumers",
+ ObjType: reflect.TypeOf(entity.Consumer{}),
+ KeyFunc: func(obj interface{}) string {
+ r := obj.(*entity.Consumer)
+ return r.Username
+ },
+ })
+ if err != nil {
+ return nil, err
+ }
+ if err := s.Init(); err != nil {
+ return nil, err
+ }
+
+ utils.AppendToClosers(s.Close)
+ return &Handler{
+ consumerStore: s,
+ }, nil
+}
+
+func (h *Handler) ApplyRoute(r *gin.Engine) {
+ r.GET("/apisix/admin/consumers/:id", wgin.Wraps(h.Get,
+ wrapper.InputType(reflect.TypeOf(GetInput{}))))
+ r.GET("/apisix/admin/consumers", wgin.Wraps(h.List,
+ wrapper.InputType(reflect.TypeOf(ListInput{}))))
+ r.POST("/apisix/admin/consumers", wgin.Wraps(h.Create,
+ wrapper.InputType(reflect.TypeOf(entity.Consumer{}))))
+ r.PUT("/apisix/admin/consumers/:id", wgin.Wraps(h.Update,
+ wrapper.InputType(reflect.TypeOf(UpdateInput{}))))
+ r.DELETE("/apisix/admin/consumers", wgin.Wraps(h.BatchDelete,
Review comment:
Yes
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-dashboard] juzhiyuan merged pull request #486: feat: add consumer CURD refactoring
Posted by GitBox <gi...@apache.org>.
juzhiyuan merged pull request #486:
URL: https://github.com/apache/apisix-dashboard/pull/486
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-dashboard] juzhiyuan commented on a change in pull request #486: feat: add consumer CURD refactoring
Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on a change in pull request #486:
URL: https://github.com/apache/apisix-dashboard/pull/486#discussion_r491255664
##########
File path: api/internal/handler/consumer/consumer.go
##########
@@ -0,0 +1,135 @@
+package consumer
+
+import (
+ "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/utils"
+)
+
+type Handler struct {
+ consumerStore *store.GenericStore
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+ s, err := store.NewGenericStore(store.GenericStoreOption{
+ BasePath: "/apisix/consumers",
+ ObjType: reflect.TypeOf(entity.Consumer{}),
+ KeyFunc: func(obj interface{}) string {
+ r := obj.(*entity.Consumer)
+ return r.Username
+ },
+ })
+ if err != nil {
+ return nil, err
+ }
+ if err := s.Init(); err != nil {
+ return nil, err
+ }
+
+ utils.AppendToClosers(s.Close)
+ return &Handler{
+ consumerStore: s,
+ }, nil
+}
+
+func (h *Handler) ApplyRoute(r *gin.Engine) {
+ r.GET("/apisix/admin/consumers/:id", wgin.Wraps(h.Get,
+ wrapper.InputType(reflect.TypeOf(GetInput{}))))
+ r.GET("/apisix/admin/consumers", wgin.Wraps(h.List,
+ wrapper.InputType(reflect.TypeOf(ListInput{}))))
+ r.POST("/apisix/admin/consumers", wgin.Wraps(h.Create,
+ wrapper.InputType(reflect.TypeOf(entity.Consumer{}))))
+ r.PUT("/apisix/admin/consumers/:id", wgin.Wraps(h.Update,
+ wrapper.InputType(reflect.TypeOf(UpdateInput{}))))
+ r.DELETE("/apisix/admin/consumers", wgin.Wraps(h.BatchDelete,
Review comment:
BatchDelete means it will delete all consumers? when we want to delete only 1 item, we should pass only 1 id, right?
##########
File path: api/route/base.go
##########
@@ -37,19 +38,20 @@ func SetUpRouter() *gin.Engine {
r := gin.New()
store := cookie.NewStore([]byte("secret"))
r.Use(sessions.Sessions("session", store))
- r.Use(filter.CORS(), filter.Authentication(), filter.RequestId(), filter.RecoverHandler())
+ r.Use(filter.CORS(), filter.Authentication(), filter.RequestId(), filter.RecoverHandler()) //
Review comment:
`//`?
##########
File path: api/internal/handler/consumer/consumer.go
##########
@@ -0,0 +1,135 @@
+package consumer
+
+import (
+ "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"
Review comment:
wgin?
##########
File path: api/route/base.go
##########
@@ -37,19 +38,20 @@ func SetUpRouter() *gin.Engine {
r := gin.New()
store := cookie.NewStore([]byte("secret"))
r.Use(sessions.Sessions("session", store))
- r.Use(filter.CORS(), filter.Authentication(), filter.RequestId(), filter.RecoverHandler())
+ r.Use(filter.CORS(), filter.Authentication(), filter.RequestId(), filter.RecoverHandler()) //
AppendHealthCheck(r)
AppendAuthentication(r)
//AppendRoute(r)
AppendSsl(r)
AppendPlugin(r)
AppendUpstream(r)
- AppendConsumer(r)
+ //AppendConsumer(r)
Review comment:
just removed the extra comment line
----------------------------------------------------------------
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] ShiningRush commented on a change in pull request #486: feat: add consumer CURD refactoring
Posted by GitBox <gi...@apache.org>.
ShiningRush commented on a change in pull request #486:
URL: https://github.com/apache/apisix-dashboard/pull/486#discussion_r491257650
##########
File path: api/route/base.go
##########
@@ -37,19 +38,20 @@ func SetUpRouter() *gin.Engine {
r := gin.New()
store := cookie.NewStore([]byte("secret"))
r.Use(sessions.Sessions("session", store))
- r.Use(filter.CORS(), filter.Authentication(), filter.RequestId(), filter.RecoverHandler())
+ r.Use(filter.CORS(), filter.Authentication(), filter.RequestId(), filter.RecoverHandler()) //
AppendHealthCheck(r)
AppendAuthentication(r)
//AppendRoute(r)
AppendSsl(r)
AppendPlugin(r)
AppendUpstream(r)
- AppendConsumer(r)
+ //AppendConsumer(r)
Review comment:
No, just keep this until all API migrating completed.
This can help us compare the previous code
----------------------------------------------------------------
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] ShiningRush commented on a change in pull request #486: feat: add consumer CURD refactoring
Posted by GitBox <gi...@apache.org>.
ShiningRush commented on a change in pull request #486:
URL: https://github.com/apache/apisix-dashboard/pull/486#discussion_r491258262
##########
File path: api/internal/handler/consumer/consumer.go
##########
@@ -0,0 +1,135 @@
+package consumer
+
+import (
+ "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/utils"
+)
+
+type Handler struct {
+ consumerStore *store.GenericStore
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+ s, err := store.NewGenericStore(store.GenericStoreOption{
+ BasePath: "/apisix/consumers",
+ ObjType: reflect.TypeOf(entity.Consumer{}),
+ KeyFunc: func(obj interface{}) string {
+ r := obj.(*entity.Consumer)
+ return r.Username
Review comment:
I think we should use "ID" as key, keep same as admin api.I will add a unique check function for generic store,so you can use it to check username's unique.
----------------------------------------------------------------
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] ShiningRush commented on a change in pull request #486: feat: add consumer CURD refactoring
Posted by GitBox <gi...@apache.org>.
ShiningRush commented on a change in pull request #486:
URL: https://github.com/apache/apisix-dashboard/pull/486#discussion_r491258262
##########
File path: api/internal/handler/consumer/consumer.go
##########
@@ -0,0 +1,135 @@
+package consumer
+
+import (
+ "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/utils"
+)
+
+type Handler struct {
+ consumerStore *store.GenericStore
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+ s, err := store.NewGenericStore(store.GenericStoreOption{
+ BasePath: "/apisix/consumers",
+ ObjType: reflect.TypeOf(entity.Consumer{}),
+ KeyFunc: func(obj interface{}) string {
+ r := obj.(*entity.Consumer)
+ return r.Username
Review comment:
I think we should use "ID" as key, keep same as admin.I will add a unique check function for generic store,so you can use it to check username's unique.
----------------------------------------------------------------
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