diff --git a/cmd/server/app/cmd/commands/server.go b/cmd/server/app/cmd/commands/server.go index f06f43568cf963fa527fc5960aee08bca8e5ff16..4f0b5e9f78828dd8355fad1a7d6446fe8322ef3d 100644 --- a/cmd/server/app/cmd/commands/server.go +++ b/cmd/server/app/cmd/commands/server.go @@ -109,7 +109,7 @@ func run(opts *options.ServerOptions, ctx context.Context, _ *cobra.Command) err } //start http server,and bind the plugin api、static file - err := network.HttpServerInit(config.HttpServer, ctx.Done()) + err := network.HttpGatewayServerInit(config.HttpServer, ctx.Done()) if err != nil { logger.Error("HttpServerInit socket server init failed, error:%v", err) return err diff --git a/cmd/server/app/network/httpserver.go b/cmd/server/app/network/httpserver.go index 0a87bcf8ea9cf1dddbece34758897fd9f0ad2575..63518ced833f0f137277254c42bf4b145b670e97 100644 --- a/cmd/server/app/network/httpserver.go +++ b/cmd/server/app/network/httpserver.go @@ -119,9 +119,6 @@ func SetupRouter() *gin.Engine { // 对插件提供的api接口 registerPluginApi(router) - // 绑定插件接口反向代理handler - registerPluginGateway(router) - // 绑定前端静态资源handler resource.StaticRouter(router) @@ -323,17 +320,11 @@ func registerAPIs(router *gin.Engine) { plugin := tokenApi.Group("") // 插件管理 { - plugin.GET("/plugins_paged", controller.GetPluginsPagedHandler) + plugin.GET("/plugins_paged", controller.GetPluginServicesPaged) p := plugin.Group("/plugins") { - // 添加插件 - p.PUT("", controller.AddPluginHandler) - // 启用/停用plugin - p.POST("/:uuid", controller.TogglePluginHandler) - // 删除插件 - p.DELETE("/:uuid", controller.UnloadPluginHandler) - // 获取插件列表 - p.GET("/", controller.GetPluginsHandler) + p.GET("/", controller.GetPluginServices) + p.POST("/toggle", controller.TogglePluginService) } } } @@ -371,12 +362,3 @@ func registerPluginApi(router *gin.Engine) { pluginAPI.POST("/has_permission", pluginapi.HasPermission) } } - -func registerPluginGateway(router *gin.Engine) { - gateway := router.Group("/plugin") - logger.Info("gateway process plugin request") - gateway.Any("/:plugin_name", controller.PluginGatewayHandler) - gateway.Any("/:plugin_name/*action", controller.PluginGatewayHandler) - - gateway.GET("/ws/:plugin_name", controller.PluginWebsocketGatewayHandler) -} diff --git a/cmd/server/app/network/jwt/jwtPlugin.go b/cmd/server/app/network/jwt/jwtPlugin.go new file mode 100644 index 0000000000000000000000000000000000000000..37e8cf58533434d772a0c6fc726528824aefa438 --- /dev/null +++ b/cmd/server/app/network/jwt/jwtPlugin.go @@ -0,0 +1,51 @@ +package jwt + +import ( + "errors" + "time" + + "gitee.com/openeuler/PilotGo/cmd/server/app/config" + "github.com/dgrijalva/jwt-go" + "github.com/gin-gonic/gin" +) + +type PluginServiceClaims struct { + jwt.StandardClaims + + ServiceName string +} + +func GeneratePluginServiceToken(serviceName string) (string, error) { + claims := &PluginServiceClaims{ + ServiceName: serviceName, + + StandardClaims: jwt.StandardClaims{ + IssuedAt: time.Now().Unix(), + Issuer: Issue, + Subject: "plugin token", + }, + } + token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) + tokenString, err := token.SignedString([]byte(config.OptionsConfig.JWT.SecretKey)) + if err != nil { + return "", err + } + return tokenString, nil +} + +func ParsePluginServiceClaims(c *gin.Context) (*PluginServiceClaims, error) { + cookie, err := c.Request.Cookie("PluginToken") + if err != nil { + return nil, err + } + + claims, err := parseClaims(cookie.Value, &PluginServiceClaims{}) + if err != nil { + return nil, err + } + m, ok := claims.(*PluginServiceClaims) + if !ok { + return nil, errors.New("invalid plugin claims") + } + return m, nil +} diff --git a/sdk/go-micro/gateway/caddy.go b/sdk/go-micro/gateway/caddy.go index c6492ad9adc37ccde8665c1dcc75cb9d1a5e74f1..f53c5a1c6df116bd9fc5d21bff91fe5c37c68a27 100644 --- a/sdk/go-micro/gateway/caddy.go +++ b/sdk/go-micro/gateway/caddy.go @@ -170,10 +170,13 @@ func (g *CaddyGateway) generateCaddyConfig() (*caddy.Config, error) { "set": map[string][]string{ "Host": {"{http.reverse_proxy.upstream.host}"}, "X-Forwarded-Prefix": {basePath}, + "Cookie": {"{http.request.header.Cookie}"}, }, }, "response": map[string]interface{}{ - "set": map[string][]string{}, + "set": map[string][]string{ + "Set-Cookie": {"{http.reverse_proxy.header.Set-Cookie}"}, + }, "deferred": true, }, } diff --git a/sdk/go-micro/gateway/service.go b/sdk/go-micro/gateway/service.go index 3b2054bf88fca29e0499c7b9252dc99e78b71f75..20cb856158cd2a801ab712bdf6a59aa033dfec4f 100644 --- a/sdk/go-micro/gateway/service.go +++ b/sdk/go-micro/gateway/service.go @@ -64,6 +64,8 @@ func (g *CaddyGateway) GetAllServices() []map[string]interface{} { "address": svc.Address, "port": svc.Port, "version": svc.Metadata["version"], + "menuName": svc.Metadata["menuName"], + "icon": svc.Metadata["icon"], "status": g.serviceStatus[serviceName], "extentions": svc.Metadata["extentions"], "permissions": svc.Metadata["permissions"], diff --git a/sdk/go-micro/registry/registry.go b/sdk/go-micro/registry/registry.go index c26a44e70e037818ea2279d347264eee13ac135f..480b928d43c1841b960139c6ee804933edc47724 100644 --- a/sdk/go-micro/registry/registry.go +++ b/sdk/go-micro/registry/registry.go @@ -25,12 +25,13 @@ type ServiceInfo struct { // Options represents the configuration options for service registry type Options struct { - Endpoints []string // etcd address - ServiceName string // 服务地址 - ServiceAddr string // 服务名称 - DialTimeout time.Duration // 超时时间 - + Endpoints []string // etcd address + ServiceName string // 服务地址 + ServiceAddr string // 服务名称 + DialTimeout time.Duration // 超时时间 Version string // 服务版本 + MenuName string // 菜单名称 + Icon string // 菜单图标 Extentions []common.Extention // 用于平台扩展点功能 Permissions []common.Permission //用于权限校验 } diff --git a/sdk/go-micro/registry/service.go b/sdk/go-micro/registry/service.go index 45b93407e63d17e91e5756cbb012c82d8d788c52..5c20a091a5f6cf348e1edb6f26dc29083f71fb27 100644 --- a/sdk/go-micro/registry/service.go +++ b/sdk/go-micro/registry/service.go @@ -39,6 +39,8 @@ func NewServiceRegistrar(opts *Options) (Registry, error) { Port: strings.Split(opts.ServiceAddr, ":")[1], Metadata: map[string]interface{}{ "version": opts.Version, + "menuName": opts.MenuName, + "icon": opts.Icon, "extentions": opts.Extentions, "permissions": opts.Permissions, },