Skip to content

Commit

Permalink
Merge pull request #18 from eolinker/release/v2.1
Browse files Browse the repository at this point in the history
新增插件管理、插件模版模块
  • Loading branch information
Dot-Liu committed Mar 31, 2023
2 parents 1c67733 + 4fc6de3 commit e47cea1
Show file tree
Hide file tree
Showing 313 changed files with 14,745 additions and 5,746 deletions.
10 changes: 5 additions & 5 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ feishu-informer: # 飞书回调
frontend-builder: # 前端构建
stage: build
rules:
- if: $CI_COMMIT_TITLE =~ /^frontend/ && $CI_COMMIT_BRANCH == "V2.0" # 当前端提交后触发
- if: $CI_COMMIT_TITLE =~ /^frontend/ && ($CI_COMMIT_BRANCH == "V2.0" || $CI_COMMIT_BRANCH =~ /^release\/v/) # 当前端提交后触发
script:
- sed -i '/replace github.com\/eolinker\/eosc => */d' go.mod
- go mod tidy
Expand All @@ -42,15 +42,15 @@ frontend-builder: # 前端构建
golang-builder:
stage: build
rules:
- if: $CI_COMMIT_TITLE !~ /^frontend/ && $CI_COMMIT_BRANCH == "V2.0" # 当后端提交后触发
- if: $CI_COMMIT_TITLE !~ /^frontend/ && ($CI_COMMIT_BRANCH == "V2.0" || $CI_COMMIT_BRANCH =~ /^release\/v/) # 当后端提交后触发
script:
- sed -i '/replace github.com\/eolinker\/eosc => */d' go.mod
- go mod tidy
- ./scripts/build.sh $BUILD_DIR backend ${VERSION}
deployer:
stage: publish
rules:
- if: $CI_COMMIT_BRANCH=="V2.0"
- if: $CI_COMMIT_BRANCH=="V2.0" || $CI_COMMIT_BRANCH =~ /^release\/v/ || $CI_COMMIT_TITLE =~ /^frontend/
variables:
DEPLOY_DESC: "DEV 环境"
VIEW_ADDR: http://172.18.166.219:8080/
Expand All @@ -61,7 +61,7 @@ deployer:
success:
stage: webhook
rules:
- if: $CI_COMMIT_BRANCH=="V2.0"
- if: $CI_COMMIT_BRANCH=="V2.0" || $CI_COMMIT_BRANCH =~ /^release\/v/
variables:
DEPLOY_DESC: "DEV 环境"
VIEW_ADDR: http://172.18.166.219:8080/
Expand All @@ -74,7 +74,7 @@ success:
failure:
stage: webhook
rules:
- if: $CI_COMMIT_BRANCH=="V2.0"
- if: $CI_COMMIT_BRANCH=="V2.0" || $CI_COMMIT_BRANCH =~ /^release\/v/
variables:
DEPLOY_DESC: "DEV 环境"
script:
Expand Down
5 changes: 4 additions & 1 deletion access/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ const (
AuditLogView
ExtAPPView
ExtAPPEdit

PluginView
PluginEdit
PluginTemplateView
PluginTemplateEdit
lastId
unknown
)
Expand Down
6 changes: 5 additions & 1 deletion access/config/access.data
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ strategy_grey_view 查看
strategy_grey_edit 编辑
audit_log_view 查看
ext_app_view 查看
ext_app_edit 编辑
ext_app_edit 编辑
plugin_view 查看
plugin_edit 编辑
plugin_template_view 查看
plugin_template_edit 编辑
23 changes: 19 additions & 4 deletions access/config/access.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
modules:
- id: 4
title: API管理
module: router
access:
- api_view
- api_edit
children:
- id: 401
title: API列表
module: router/router
access:
- api_view
- api_edit
- id: 402
title: 插件模板
module: router/plugin
access:
- plugin_template_view
- plugin_template_edit
- id: 3
title: 应用管理
module: application
Expand Down Expand Up @@ -41,6 +50,12 @@ modules:
access:
- variable_view
- variable_edit
- id: 103
title: 插件管理
module: deploy/plugin
access:
- plugin_view
- plugin_edit
- id: 5
title: 服务治理
children:
Expand Down
5 changes: 4 additions & 1 deletion access/config/dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ authorization_edit:
- authorization_view
ext_app_edit:
- ext_app_view

plugin_edit:
- plugin_view
plugin_template_edit:
- plugin_template_view
6 changes: 5 additions & 1 deletion access/config/role.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@
- strategy_grey_edit
- audit_log_view
- ext_app_view
- ext_app_edit
- ext_app_edit
- plugin_view
- plugin_edit
- plugin_template_view
- plugin_template_edit
25 changes: 6 additions & 19 deletions app/apserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package main
import (
"context"
"fmt"
"github.com/eolinker/apinto-dashboard/modules/plugin/plugin_timer"
"os"

"github.com/eolinker/apinto-dashboard/app/apserver/version"
"github.com/eolinker/apinto-dashboard/db_migrator"
cluster_service "github.com/eolinker/apinto-dashboard/modules/cluster"
"github.com/eolinker/apinto-dashboard/store"
"github.com/eolinker/eosc/common/bean"
"github.com/eolinker/eosc/log"
Expand All @@ -30,7 +30,7 @@ func main() {
return nil
},
}
app.Run(os.Args)
_ = app.Run(os.Args)
}

func run() {
Expand All @@ -40,20 +40,17 @@ func run() {

registerRouter(engine)

//初始化数据库表 sql操作
initDB()

err := bean.Check()
if err != nil {
log.Fatal(err)
}

//初始化数据库表 sql操作
initDB()

//初始化超管账号 和清除超管缓存
go plugin_timer.ExtenderTimer()
// todo 不适合开源,后续通过插件接入

//初始化集群插件
initClustersPlugin()

if err = engine.Run(fmt.Sprintf(":%d", GetPort())); err != nil {
panic(err)
}
Expand All @@ -70,13 +67,3 @@ func initDB() {
db_migrator.InitSql(db)

}

func initClustersPlugin() {
var clientService cluster_service.IApintoClient
bean.Autowired(&clientService)

err := clientService.InitClustersGlobalPlugin(context.Background())
if err != nil {
panic(err)
}
}
5 changes: 5 additions & 0 deletions app/apserver/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/eolinker/apinto-dashboard/modules/group/group-controller"
"github.com/eolinker/apinto-dashboard/modules/openapi/open-api-controller"
"github.com/eolinker/apinto-dashboard/modules/openapp/open-app-controller"
plugin_controller "github.com/eolinker/apinto-dashboard/modules/plugin/plugin-controller"
plugin_template_controller "github.com/eolinker/apinto-dashboard/modules/plugin_template/plugin-template-controller"
strategy_controller2 "github.com/eolinker/apinto-dashboard/modules/strategy/strategy-controller"
user_controller "github.com/eolinker/apinto-dashboard/modules/user/user-controller"
variable_controller2 "github.com/eolinker/apinto-dashboard/modules/variable/variable-controller"
Expand Down Expand Up @@ -59,6 +61,9 @@ func registerRouter(engine *gin.Engine) {
strategy_controller2.RegisterStrategyGreyRouter(routes)
strategy_controller2.RegisterStrategyVisitRouter(routes)
strategy_controller2.RegisterStrategyFuseRouter(routes)
plugin_controller.RegisterPluginRouter(routes)
plugin_controller.RegisterPluginClusterRouter(routes)
plugin_template_controller.RegisterPluginTemplateRouter(routes)
audit_controller.RegisterAuditLogRouter(routes)
open_app_controller.RegisterExternalApplicationRouter(routes)

Expand Down
3 changes: 2 additions & 1 deletion app/apserver/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import (
_ "github.com/eolinker/apinto-dashboard/modules/notice/notice-service"
_ "github.com/eolinker/apinto-dashboard/modules/openapi/openapi-service"
_ "github.com/eolinker/apinto-dashboard/modules/openapp/openapp-service"
_ "github.com/eolinker/apinto-dashboard/modules/plugin/plugin-service"
_ "github.com/eolinker/apinto-dashboard/modules/plugin_template/plugin-template-service"
_ "github.com/eolinker/apinto-dashboard/modules/random/random-service"
_ "github.com/eolinker/apinto-dashboard/modules/strategy/strategy-service"
_ "github.com/eolinker/apinto-dashboard/modules/upstream/service"
_ "github.com/eolinker/apinto-dashboard/modules/user/user-service"
_ "github.com/eolinker/apinto-dashboard/modules/variable/variable-service"

//online-service必须放到最后导入
_ "github.com/eolinker/apinto-dashboard/modules/online/online-service"
)
48 changes: 48 additions & 0 deletions cache/redis_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
type IRedisCache[T any] interface {
Get(ctx context.Context, key string) (*T, error)
Set(ctx context.Context, key string, t *T, expiration time.Duration) error
SetAll(ctx context.Context, key string, t []*T, expiration time.Duration) error
GetAll(ctx context.Context, key string) ([]*T, error)
Delete(ctx context.Context, keys ...string) error
}

Expand Down Expand Up @@ -53,6 +55,30 @@ func (r *redisCache[T]) Delete(ctx context.Context, keys ...string) error {
return nil
}

func (r *redisCache[T]) GetAll(ctx context.Context, key string) ([]*T, error) {
key = r.keyPrefix + key

bytes, err := r.client.Get(ctx, key).Bytes()
if err != nil {
return nil, err
}

return r.toMyStructAll(bytes)

}

func (r *redisCache[T]) SetAll(ctx context.Context, key string, t []*T, expiration time.Duration) error {

key = r.keyPrefix + key

bytes, err := r.structToBytesAll(t)
if err != nil {
return err
}

return r.client.Set(ctx, key, bytes, expiration).Err()
}

func CreateRedisCache[T any](client *redis.ClusterClient) IRedisCache[T] {
return &redisCache[T]{
client: client,
Expand Down Expand Up @@ -81,3 +107,25 @@ func (r *redisCache[T]) toMyStruct(bytes []byte) (*T, error) {

return t, nil
}

func (r *redisCache[T]) structToBytesAll(t []*T) ([]byte, error) {

bytes, err := json.Marshal(t)
if err != nil {
return nil, err
}

return bytes, nil

}

func (r *redisCache[T]) toMyStructAll(bytes []byte) ([]*T, error) {

t := make([]*T, 0)
err := json.Unmarshal(bytes, &t)
if err != nil {
return nil, err
}

return t, nil
}
14 changes: 14 additions & 0 deletions client/v1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ type IClient interface {
ForInfluxV2Output() IProfession[InfluxV2Output, WorkerInfo]
ForApp() IProfession[ApplicationConfig, WorkerInfo]
ForGlobalPlugin() IPlugin[GlobalPlugin]
ForPluginTemplate() IProfession[PluginTemplateConfig, PluginTemplateInfo]
ForRouter() IProfession[RouterConfig, RouterInfo]
ForExtender() IExtender
ForCert() ICert
ForVariable() IVariable
ForStrategy() IStrategy
Expand All @@ -34,6 +36,7 @@ type IClient interface {
type Client struct {
adminAddrs []string
discovery IProfession[DiscoveryConfig, WorkerInfo]
pluginTemplate IProfession[PluginTemplateConfig, PluginTemplateInfo]
auth IProfession[AuthConfig, WorkerInfo]
output IProfession[any, WorkerInfo]
redisOutput IProfession[RedisOutput, WorkerInfo]
Expand All @@ -45,6 +48,7 @@ type Client struct {
plugin IPlugin[GlobalPlugin]
variable IVariable
strategy IStrategy
extender IExtender
}

func (c *Client) addrs() []string {
Expand Down Expand Up @@ -88,16 +92,26 @@ func (c *Client) init() {
c.influxV2Output = newIProfession[InfluxV2Output, WorkerInfo](c, "output")
c.service = newIProfession[ServiceConfig, WorkerInfo](c, "service")
c.router = newIProfession[RouterConfig, RouterInfo](c, "router")
c.pluginTemplate = newIProfession[PluginTemplateConfig, PluginTemplateInfo](c, "template")
c.cert = newCert(c)
c.app = newIProfession[ApplicationConfig, WorkerInfo](c, "app")
c.plugin = newIPlugin[GlobalPlugin](c)
c.strategy = newIStrategy(c)
c.variable = newIVariable(c, "variable")
c.extender = newIExtender(c)
}
func (c *Client) ForDiscovery() IProfession[DiscoveryConfig, WorkerInfo] {
return c.discovery
}

func (c *Client) ForPluginTemplate() IProfession[PluginTemplateConfig, PluginTemplateInfo] {
return c.pluginTemplate
}

func (c *Client) ForExtender() IExtender {
return c.extender
}

func (c *Client) ForApp() IProfession[ApplicationConfig, WorkerInfo] {
return c.app
}
Expand Down

0 comments on commit e47cea1

Please sign in to comment.