From 95dde4dd5d6d711646265151913c32671694f25e Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Fri, 18 Oct 2024 12:10:27 +0800 Subject: [PATCH 1/5] finish ai router --- module/ai-api/dto/input.go | 5 +++-- module/ai-api/dto/output.go | 7 +++++++ module/ai-api/iml.go | 40 +++++++++++++++++++++++++------------ service/ai-api/model.go | 3 ++- 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/module/ai-api/dto/input.go b/module/ai-api/dto/input.go index f445f9cb..be94417e 100644 --- a/module/ai-api/dto/input.go +++ b/module/ai-api/dto/input.go @@ -24,8 +24,9 @@ type AiPromptVariable struct { } type AiModel struct { - Id string `json:"id"` - Config string `json:"config"` + Id string `json:"id"` + Config string `json:"config"` + Provider string `json:"provider"` } type EditAPI struct { diff --git a/module/ai-api/dto/output.go b/module/ai-api/dto/output.go index 1083f98f..912bb878 100644 --- a/module/ai-api/dto/output.go +++ b/module/ai-api/dto/output.go @@ -26,6 +26,7 @@ type APIItem struct { Updater auto.Label `json:"updater" aolabel:"user"` CreateTime auto.TimeLabel `json:"create_time"` UpdateTime auto.TimeLabel `json:"update_time"` + Provider ProviderItem `json:"provider"` Model ModelItem `json:"model"` } @@ -33,3 +34,9 @@ type ModelItem struct { Id string `json:"id"` Logo string `json:"logo"` } + +type ProviderItem struct { + Id string `json:"id"` + Name string `json:"name"` + Logo string `json:"logo"` +} diff --git a/module/ai-api/iml.go b/module/ai-api/iml.go index aadc019a..55a60fc2 100644 --- a/module/ai-api/iml.go +++ b/module/ai-api/iml.go @@ -9,6 +9,7 @@ import ( "strings" model_runtime "github.com/APIParkLab/APIPark/ai-provider/model-runtime" + ai_api_dto "github.com/APIParkLab/APIPark/module/ai-api/dto" ai_api "github.com/APIParkLab/APIPark/service/ai-api" "github.com/APIParkLab/APIPark/service/api" @@ -203,19 +204,8 @@ func (i *imlAPIModule) List(ctx context.Context, keyword string, serviceId strin if err != nil { return nil, err } - p, has := model_runtime.GetProvider(info.AdditionalConfig["provider"]) - if !has { - return nil, fmt.Errorf("provider not found") - } return utils.SliceToSlice(apis, func(t *ai_api.API) *ai_api_dto.APIItem { - modelItem := ai_api_dto.ModelItem{ - Id: t.Model, - } - model, has := p.DefaultModel(t.Model) - if has { - modelItem.Logo = model.Logo() - } - return &ai_api_dto.APIItem{ + item := &ai_api_dto.APIItem{ Id: t.ID, Name: t.Name, RequestPath: t.Path, @@ -225,8 +215,32 @@ func (i *imlAPIModule) List(ctx context.Context, keyword string, serviceId strin Updater: auto.UUID(t.Updater), CreateTime: auto.TimeLabel(t.CreateAt), UpdateTime: auto.TimeLabel(t.UpdateAt), - Model: modelItem, } + aiModel, err := ConvertStruct[ai_api_dto.AiModel](t.AdditionalConfig["ai_model"]) + if err != nil { + return item + } + p, has := model_runtime.GetProvider(aiModel.Provider) + if has { + item.Provider = ai_api_dto.ProviderItem{ + Id: p.ID(), + Name: p.Name(), + Logo: p.Logo(), + } + m, has := p.GetModel(t.Model) + if has { + item.Model = ai_api_dto.ModelItem{ + Id: m.ID(), + Logo: m.Logo(), + } + } + } else { + + item.Model = ai_api_dto.ModelItem{ + Id: aiModel.Id, + } + } + return item }), nil } diff --git a/service/ai-api/model.go b/service/ai-api/model.go index ed25fd12..bf9e7d41 100644 --- a/service/ai-api/model.go +++ b/service/ai-api/model.go @@ -2,8 +2,9 @@ package ai_api import ( "encoding/json" - "github.com/APIParkLab/APIPark/stores/api" "time" + + "github.com/APIParkLab/APIPark/stores/api" ) type API struct { From 86129c315842d96266dacd3a78338db1e5ef8cc8 Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Fri, 18 Oct 2024 15:38:39 +0800 Subject: [PATCH 2/5] Initialize deployment with built-in data optimization --- controller/service/iml.go | 26 +++++++++++- controller/system/iml.go | 79 ++++++++++++++++++++++++++++++++++++ controller/system/system.go | 7 ++++ module/cluster/impl.go | 26 +++++++----- module/team/iml.go | 16 -------- plugins/core/core.go | 1 + resources/access/access.yaml | 19 +-------- resources/access/role.yaml | 26 +++++++----- 8 files changed, 144 insertions(+), 56 deletions(-) diff --git a/controller/service/iml.go b/controller/service/iml.go index c782bad4..aac8c32b 100644 --- a/controller/service/iml.go +++ b/controller/service/iml.go @@ -6,6 +6,9 @@ import ( "net/http" "strings" + application_authorization "github.com/APIParkLab/APIPark/module/application-authorization" + application_authorization_dto "github.com/APIParkLab/APIPark/module/application-authorization/dto" + "github.com/APIParkLab/APIPark/model/plugin_model" "github.com/APIParkLab/APIPark/service/api" @@ -271,7 +274,8 @@ func (i *imlServiceController) SaveServiceDoc(ctx *gin.Context, id string, input } type imlAppController struct { - module service.IAppModule `autowired:""` + module service.IAppModule `autowired:""` + authModule application_authorization.IAuthorizationModule `autowired:""` } func (i *imlAppController) Search(ctx *gin.Context, teamId string, keyword string) ([]*service_dto.AppItem, error) { @@ -279,7 +283,25 @@ func (i *imlAppController) Search(ctx *gin.Context, teamId string, keyword strin } func (i *imlAppController) CreateApp(ctx *gin.Context, teamID string, input *service_dto.CreateApp) (*service_dto.App, error) { - return i.module.CreateApp(ctx, teamID, input) + app, err := i.module.CreateApp(ctx, teamID, input) + if err != nil { + return nil, err + } + _, err = i.authModule.AddAuthorization(ctx, app.Id, &application_authorization_dto.CreateAuthorization{ + Name: "Default API Key", + Driver: "apikey", + Position: "Header", + TokenName: "Authorization", + ExpireTime: 0, + Config: map[string]interface{}{ + "apikey": uuid.New().String(), + }, + }) + if err != nil { + i.module.DeleteApp(ctx, app.Id) + return nil, err + } + return app, nil } func (i *imlAppController) UpdateApp(ctx *gin.Context, appId string, input *service_dto.UpdateApp) (*service_dto.App, error) { return i.module.UpdateApp(ctx, appId, input) diff --git a/controller/system/iml.go b/controller/system/iml.go index 72e0de8f..a11b2e23 100644 --- a/controller/system/iml.go +++ b/controller/system/iml.go @@ -3,11 +3,23 @@ package system import ( "archive/zip" "bytes" + "context" "encoding/json" "fmt" "net/http" "time" + catalogue_dto "github.com/APIParkLab/APIPark/module/catalogue/dto" + + application_authorization_dto "github.com/APIParkLab/APIPark/module/application-authorization/dto" + service_dto "github.com/APIParkLab/APIPark/module/service/dto" + team_dto "github.com/APIParkLab/APIPark/module/team/dto" + "github.com/eolinker/eosc/log" + "github.com/eolinker/go-common/register" + "github.com/eolinker/go-common/server" + "github.com/eolinker/go-common/utils" + "github.com/google/uuid" + system_dto "github.com/APIParkLab/APIPark/module/system/dto" application_authorization "github.com/APIParkLab/APIPark/module/application-authorization" @@ -185,3 +197,70 @@ func (i *imlSettingController) Get(ctx *gin.Context) (*system_dto.Setting, error func (i *imlSettingController) Set(ctx *gin.Context, input *system_dto.InputSetting) error { return i.settingModule.Set(ctx, input) } + +type imlInitController struct { + teamModule team.ITeamModule `autowired:""` + appModule service.IAppModule `autowired:""` + applicationAuthorizationModule application_authorization.IAuthorizationModule `autowired:""` + catalogueModule catalogue.ICatalogueModule `autowired:""` +} + +func (i *imlInitController) OnInit() { + register.Handle(func(v server.Server) { + ctx := utils.SetUserId(context.Background(), "admin") + teams, err := i.teamModule.Search(ctx, "") + if err != nil { + log.Error("get teams error: %v", err) + return + } + if len(teams) == 0 { + info, err := i.teamModule.Create(ctx, &team_dto.CreateTeam{ + Name: "Default Team", + Description: "Auto created By APIPark", + }) + if err != nil { + log.Error("create default team error: %v", err) + return + } + app, err := i.appModule.CreateApp(ctx, info.Id, &service_dto.CreateApp{ + Name: "Demo Application", + Description: "Auto created By APIPark", + }) + if err != nil { + i.teamModule.Delete(ctx, info.Id) + log.Error("create default app error: %v", err) + return + } + _, err = i.applicationAuthorizationModule.AddAuthorization(ctx, app.Id, &application_authorization_dto.CreateAuthorization{ + Name: "Default API Key", + Driver: "apikey", + Position: "Header", + TokenName: "Authorization", + ExpireTime: 0, + Config: map[string]interface{}{ + "apikey": uuid.New().String(), + }, + }) + if err != nil { + i.teamModule.Delete(ctx, info.Id) + i.appModule.DeleteApp(ctx, app.Id) + log.Error("create default api key error: %v", err) + return + } + } + items, err := i.catalogueModule.Search(ctx, "") + if err != nil { + log.Error("get catalogue error: %v", err) + return + } + if len(items) == 0 { + err = i.catalogueModule.Create(ctx, &catalogue_dto.CreateCatalogue{ + Name: "Default Catalogue", + }) + if err != nil { + log.Error("create default catalogue error: %v", err) + return + } + } + }) +} diff --git a/controller/system/system.go b/controller/system/system.go index 008bf5d0..43a9a609 100644 --- a/controller/system/system.go +++ b/controller/system/system.go @@ -21,6 +21,9 @@ type ISettingController interface { Set(ctx *gin.Context, input *system_dto.InputSetting) error } +type IInitController interface { +} + func init() { autowire.Auto[IExportConfigController](func() reflect.Value { return reflect.ValueOf(new(imlExportConfigController)) @@ -33,4 +36,8 @@ func init() { autowire.Auto[ISettingController](func() reflect.Value { return reflect.ValueOf(new(imlSettingController)) }) + + autowire.Auto[IInitController](func() reflect.Value { + return reflect.ValueOf(new(imlInitController)) + }) } diff --git a/module/cluster/impl.go b/module/cluster/impl.go index 06d3b0af..db37f50e 100644 --- a/module/cluster/impl.go +++ b/module/cluster/impl.go @@ -2,16 +2,18 @@ package cluster import ( "context" - + + "github.com/APIParkLab/APIPark/service/setting" + cluster_dto "github.com/APIParkLab/APIPark/module/cluster/dto" - + "github.com/APIParkLab/APIPark/gateway/admin" "github.com/eolinker/eosc/log" - + "github.com/eolinker/go-common/store" - + "github.com/APIParkLab/APIPark/gateway" - + "github.com/APIParkLab/APIPark/service/cluster" "github.com/eolinker/ap-account/service/account" "github.com/eolinker/go-common/utils" @@ -23,6 +25,7 @@ var ( type imlClusterModule struct { clusterService cluster.IClusterService `autowired:""` + settingService setting.ISettingService `autowired:""` userNameService account.IAccountService `autowired:""` transaction store.ITransaction `autowired:""` } @@ -42,12 +45,12 @@ func (m *imlClusterModule) CheckCluster(ctx context.Context, address ...string) } }) nodeStatus(ctx, nodesOut) - + return nodesOut, nil } func (m *imlClusterModule) ResetCluster(ctx context.Context, clusterId string, address string) ([]*cluster_dto.Node, error) { - + nodes, err := m.clusterService.UpdateAddress(ctx, clusterId, address) if err != nil { return nil, err @@ -65,7 +68,10 @@ func (m *imlClusterModule) ResetCluster(ctx context.Context, clusterId string, a Gateways: i.Server, } }) - + v, has := m.settingService.Get(ctx, setting.KeyInvokeAddress) + if (!has || v == "") && len(nodesOut) > 0 && len(nodesOut[0].Gateways) > 0 { + m.settingService.Set(ctx, setting.KeyInvokeAddress, nodesOut[0].Gateways[0], utils.UserId(ctx)) + } nodeStatus(ctx, nodesOut) return nodesOut, nil } @@ -83,7 +89,7 @@ func (m *imlClusterModule) initGateway(ctx context.Context, clusterId string) er return gateway.InitGateway(ctx, clusterId, client) } func (m *imlClusterModule) ClusterNodes(ctx context.Context, clusterId string) ([]*cluster_dto.Node, error) { - + nodes, err := m.clusterService.Nodes(ctx) if err != nil { return nil, err @@ -98,7 +104,7 @@ func (m *imlClusterModule) ClusterNodes(ctx context.Context, clusterId string) ( } }) nodeStatus(ctx, nodesOut) - + return nodesOut, nil } diff --git a/module/team/iml.go b/module/team/iml.go index c02e5e00..a61f9854 100644 --- a/module/team/iml.go +++ b/module/team/iml.go @@ -161,19 +161,3 @@ func (m *imlTeamModule) Delete(ctx context.Context, id string) error { }) return err } - -func (m *imlTeamModule) OnInit() { - ctx := context.Background() - list, err := m.service.List(ctx) - if err != nil { - return - } - if len(list) == 0 { - teamId := uuid.New().String() - err = m.service.Create(ctx, &team.CreateTeam{ - Id: teamId, - Name: "Default Team", - Description: "Auto create default team", - }) - } -} diff --git a/plugins/core/core.go b/plugins/core/core.go index 2be3ebef..e194b191 100644 --- a/plugins/core/core.go +++ b/plugins/core/core.go @@ -83,6 +83,7 @@ type plugin struct { importConfigController system.IImportConfigController `autowired:""` aiProviderController ai.IProviderController `autowired:""` settingController system.ISettingController `autowired:""` + initController system.IInitController `autowired:""` apis []pm3.Api } diff --git a/resources/access/access.yaml b/resources/access/access.yaml index 9585978a..4ba49f1b 100644 --- a/resources/access/access.yaml +++ b/resources/access/access.yaml @@ -1,6 +1,8 @@ system: - name: organization cname: '组织管理' + i18n: + zh_CN: 组织管理 value: 'organization' children: - name: member @@ -190,23 +192,6 @@ system: - "PUT:/api/v1/dynamic/{name}/offline" dependents: - system.devops.log_configuration.view - - name: monitor - cname: 监控 - value: 'monitor' - children: - - name: view - cname: 查看 - value: 'view' - guest_allow: true - apis: - - "GET:/api/v1/monitor/config" - - name: manager - cname: 管理 - value: 'manager' - apis: - - "POST:/api/v1/monitor/config" - dependents: - - system.devops.monitor.view - name: ai_provider cname: AI 模型供应商 value: 'ai_provider' diff --git a/resources/access/role.yaml b/resources/access/role.yaml index 750f1650..8cc1f5b3 100644 --- a/resources/access/role.yaml +++ b/resources/access/role.yaml @@ -2,25 +2,27 @@ system: - name: supper_admin cname: 超级管理员 permits: - - system.api_market.service_classification.manager - - system.api_market.service_classification.view - system.dashboard.run_view.view - - system.devops.ai_provider.view - system.devops.ai_provider.manager + - system.devops.ai_provider.view - system.devops.cluster.manager - system.devops.cluster.view + - system.devops.data_source.manager + - system.devops.data_source.view - system.devops.log_configuration.manager - system.devops.log_configuration.view - system.devops.ssl_certificate.manager - system.devops.ssl_certificate.view - - system.devops.data_source.manager - - system.devops.data_source.view - system.organization.member.manager - system.organization.member.view - system.organization.role.view_system_role - system.organization.role.view_team_role - system.organization.team.manager - system.organization.team.view + - system.settings.general.manager + - system.settings.general.view + - system.settings.service_classification.manager + - system.settings.service_classification.view - system.workspace.api_market.view - system.workspace.application.view_all - system.workspace.service.view_all @@ -39,23 +41,25 @@ system: - name: devops_admin cname: 运维管理员 permits: - - system.api_market.service_classification.manager - - system.api_market.service_classification.view - system.dashboard.run_view.view - - system.devops.ai_provider.view - system.devops.ai_provider.manager + - system.devops.ai_provider.view - system.devops.cluster.manager - system.devops.cluster.view + - system.devops.data_source.manager + - system.devops.data_source.view - system.devops.log_configuration.manager - system.devops.log_configuration.view - system.devops.ssl_certificate.manager - system.devops.ssl_certificate.view - - system.devops.data_source.manager - - system.devops.data_source.view - system.workspace.api_market.view - system.workspace.application.view_all - system.workspace.service.view_all - system.workspace.team.view_all + - system.settings.general.manager + - system.settings.general.view + - system.settings.service_classification.manager + - system.settings.service_classification.view - name: member cname: 普通成员 permits: @@ -64,7 +68,7 @@ system: - name: guest cname: 只读成员 permits: - - system.api_market.service_classification.view + - system.settings.service_classification.view - system.devops.cluster.view - system.devops.log_configuration.view - system.devops.ssl_certificate.view From 6e9939f96ec9993794e10a5ee63ceed392d9312a Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Fri, 18 Oct 2024 19:50:20 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=96=B0=E5=A2=9Ei18n=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 7 +- go.sum | 8 +- resources/access/access.yaml | 150 +++++++++++++++---------------- resources/access/access_test.go | 55 ++++++++++++ resources/access/permit.yaml | 65 ++++++++------ resources/access/role.yaml | 40 ++++----- resources/locale/i18n/en-US.json | 44 +++++++++ resources/locale/i18n/ja-JP.json | 44 +++++++++ resources/locale/i18n/zh-CN.json | 44 +++++++++ resources/locale/i18n/zh-TW.json | 44 +++++++++ resources/locale/locale.go | 52 +++++++++++ 11 files changed, 418 insertions(+), 135 deletions(-) create mode 100644 resources/locale/i18n/en-US.json create mode 100644 resources/locale/i18n/ja-JP.json create mode 100644 resources/locale/i18n/zh-CN.json create mode 100644 resources/locale/i18n/zh-TW.json create mode 100644 resources/locale/locale.go diff --git a/go.mod b/go.mod index 4bc92d51..ba1f9dfa 100644 --- a/go.mod +++ b/go.mod @@ -7,13 +7,12 @@ go 1.21 require ( github.com/eolinker/ap-account v1.0.11 github.com/eolinker/eosc v0.17.3 - github.com/eolinker/go-common v1.0.4 + github.com/eolinker/go-common v1.1.0 github.com/gabriel-vasile/mimetype v1.4.4 github.com/getkin/kin-openapi v0.127.0 github.com/gin-gonic/gin v1.10.0 github.com/google/uuid v1.6.0 github.com/influxdata/influxdb-client-go/v2 v2.14.0 - github.com/mitchellh/mapstructure v1.5.0 github.com/urfave/cli/v2 v2.27.2 golang.org/x/crypto v0.24.0 gopkg.in/yaml.v3 v3.0.1 @@ -77,6 +76,4 @@ require ( gorm.io/driver/mysql v1.5.2 // indirect ) -//replace github.com/eolinker/ap-account => ../../eolinker/ap-account -// -//replace github.com/eolinker/go-common => ../../eolinker/go-common +replace github.com/eolinker/ap-account => ../../eolinker/ap-account diff --git a/go.sum b/go.sum index 01f76851..8ed516ee 100644 --- a/go.sum +++ b/go.sum @@ -27,12 +27,10 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= -github.com/eolinker/ap-account v1.0.11 h1:/TagC53BXu1mfdcIT16FoiSmbNJLL+YXaLpFgL/8AHw= -github.com/eolinker/ap-account v1.0.11/go.mod h1:5lsZwkQfnHO5YJ3Cu6X1PZwZ0gbmJBUcix0hxG8aEsY= github.com/eolinker/eosc v0.17.3 h1:sr2yT+v/AsqEdciRaaZZj0zL9pTufR5RvDW6+65hraQ= github.com/eolinker/eosc v0.17.3/go.mod h1:xgq816hpanlMXFtZw7Ztdctb1eEk9UPHchY4NfFO6Cw= -github.com/eolinker/go-common v1.0.4 h1:F0akjnzJfIFOVmK30fD0SsCLU7DAKPXuY21MeyMmQ7w= -github.com/eolinker/go-common v1.0.4/go.mod h1:Kb/jENMN1mApnodvRgV4YwO9FJby1Jkt2EUjrBjvSX4= +github.com/eolinker/go-common v1.1.0 h1:n/XXK7yVRen3jhNG/SfZGXJA+KNnaYf0XTDfMeviaBw= +github.com/eolinker/go-common v1.1.0/go.mod h1:Kb/jENMN1mApnodvRgV4YwO9FJby1Jkt2EUjrBjvSX4= github.com/gabriel-vasile/mimetype v1.4.4 h1:QjV6pZ7/XZ7ryI2KuyeEDE8wnh7fHP9YnQy+R0LnH8I= github.com/gabriel-vasile/mimetype v1.4.4/go.mod h1:JwLei5XPtWdGiMFB5Pjle1oEeoSeEuJfJE+TtfvdB/s= github.com/getkin/kin-openapi v0.127.0 h1:Mghqi3Dhryf3F8vR370nN67pAERW+3a95vomb3MAREY= @@ -99,8 +97,6 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0 github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= -github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= diff --git a/resources/access/access.yaml b/resources/access/access.yaml index 4ba49f1b..1ff6ba0b 100644 --- a/resources/access/access.yaml +++ b/resources/access/access.yaml @@ -1,23 +1,21 @@ system: - name: organization - cname: '组织管理' - i18n: - zh_CN: 组织管理 +# cname: '组织管理' value: 'organization' children: - name: member - cname: '成员' +# cname: '成员' value: 'member' children: - name: view - cname: '查看' +# cname: '查看' value: 'view' guest_allow: true apis: - "GET:/api/v1/user/accounts" - "GET:/api/v1/user/departments" - name: manager - cname: '管理' +# cname: '管理' value: 'manager' apis: - "POST:/api/v1/user/account" @@ -39,14 +37,14 @@ system: value: 'team' children: - name: view - cname: '查看' +# cname: '查看' value: 'view' guest_allow: true apis: - "GET:/api/v1/manager/teams" - "GET:/api/v1/manager/team" - name: manager - cname: '管理' +# cname: '管理' value: 'manager' apis: - "POST:/api/v1/manager/team" @@ -55,7 +53,7 @@ system: dependents: - system.organization.team.view - name: role - cname: '角色' +# cname: '角色' value: 'role' children: - name: view system role @@ -73,21 +71,21 @@ system: - "GET:/api/v1/team/roles" - "GET:/api/v1/team/role" - name: System Settings - cname: '系统设置' +# cname: '系统设置' value: 'settings' children: - name: service classification - cname: '服务分类' +# cname: '服务分类' value: 'service_classification' children: - name: view - cname: '查看' +# cname: '查看' value: 'view' guest_allow: true # apis: # - "GET:/api/v1/catalogues" - name: manager - cname: '管理' +# cname: '管理' value: 'manager' apis: - "POST:/api/v1/catalogue" @@ -97,24 +95,24 @@ system: dependents: - system.settings.service_classification.view - name: General - cname: 常规设置 +# cname: 常规设置 value: 'general' children: - name: view - cname: 查看 +# cname: 查看 value: 'view' guest_allow: true apis: # - "GET:/api/v1/setting" - name: manager - cname: 管理 +# cname: 管理 value: 'manager' apis: # - "PUT:/api/v1/setting" dependents: - system.settings.general.view - name: Devops - cname: 运维 +# cname: 运维 value: 'devops' children: - name: cluster @@ -128,7 +126,7 @@ system: apis: - "GET:/api/v1/cluster/nodes" - name: manager - cname: 管理 +# cname: 管理 value: 'manager' apis: - "PUT:/api/v1/cluster/reset" @@ -138,14 +136,14 @@ system: value: 'ssl_certificate' children: - name: view - cname: 查看 +# cname: 查看 value: 'view' guest_allow: true apis: - "GET:/api/v1/certificates" - "GET:/api/v1/certificate" - name: manager - cname: 管理 +# cname: 管理 value: 'manager' apis: - "POST:/api/v1/certificate" @@ -154,27 +152,27 @@ system: dependents: - system.devops.ssl_certificate.view - name: Data Source - cname: '数据源' +# cname: '数据源' value: 'data_source' children: - name: view - cname: '查看' +# cname: '查看' value: 'view' guest_allow: true apis: - "GET:/api/v1/monitor/config" - name: manager - cname: '管理' +# cname: '管理' value: 'manager' apis: - "POST:/api/v1/monitor/config" - "PUT:/api/v1/monitor/config" - name: log configuration - cname: 日志 +# cname: 日志 value: 'log_configuration' children: - name: view - cname: 查看 +# cname: 查看 value: 'view' guest_allow: true apis: @@ -182,7 +180,7 @@ system: - "GET:/api/v1/dynamic/{name}/list" - "GET:/api/v1/dynamic/{name}/render" - name: manager - cname: 管理 +# cname: 管理 value: 'manager' apis: - "POST:/api/v1/dynamic/{name}" @@ -192,19 +190,19 @@ system: - "PUT:/api/v1/dynamic/{name}/offline" dependents: - system.devops.log_configuration.view - - name: ai_provider - cname: AI 模型供应商 + - name: ai provider +# cname: AI 模型供应商 value: 'ai_provider' children: - name: view - cname: 查看 +# cname: 查看 value: 'view' guest_allow: true apis: - "GET:/api/v1/ai/providers" - "GET:/api/v1/ai/provider/config" - name: manager - cname: 管理 +# cname: 管理 value: 'manager' apis: - "PUT:/api/v1/ai/provider/config" @@ -213,15 +211,15 @@ system: - system.devops.ai_provider.view - name: dashboard - cname: 仪表盘 +# cname: 仪表盘 value: 'dashboard' children: - name: run view - cname: 运行视图 +# cname: 运行视图 value: 'run_view' children: - name: view - cname: 查看 +# cname: 查看 value: 'view' guest_allow: true apis: @@ -230,45 +228,45 @@ system: - "GET:/api/v1/monitor/overview/top10" - "GET:/api/v1/monitor/overview/summary" - name: workspace - cname: 工作空间 +# cname: 工作空间 value: 'workspace' children: - name: application - cname: 应用 +# cname: 应用 value: 'application' children: - - name: view all - cname: 查看所有应用 + - name: view all application +# cname: 查看所有应用 value: 'view_all' guest_allow: true apis: - "GET:/api/v1/apps" - name: service - cname: 服务 +# cname: 服务 value: 'service' children: - - name: view all - cname: 查看所有服务 + - name: view all service +# cname: 查看所有服务 value: 'view_all' guest_allow: true apis: - "GET:/api/v1/services" - name: team - cname: 团队 +# cname: 团队 value: 'team' children: - - name: view all - cname: 查看所有团队 + - name: view all team +# cname: 查看所有团队 value: 'view_all' guest_allow: true apis: - "GET:/api/v1/manager/teams" - name: api market - cname: API市场 +# cname: API市场 value: 'api_market' children: - name: view - cname: 查看 +# cname: 查看 value: 'view' guest_allow: true apis: @@ -276,15 +274,15 @@ system: - "GET:/api/v1/catalogue/service" team: - name: service - cname: 服务 +# cname: 服务 value: 'service' children: - name: router - cname: 路由 +# cname: 路由 value: 'router' children: - name: view - cname: 查看 +# cname: 查看 value: 'view' guest_allow: true apis: @@ -293,24 +291,24 @@ team: - "GET:/api/v1/service/router/detail/simple" - "GET:/api/v1/service/router/define" - name: manager - cname: 管理 +# cname: 管理 value: 'manager' apis: - "POST:/api/v1/service/router" - "PUT:/api/v1/service/router" - "DELETE:/api/v1/service/router" - - name: api_doc + - name: api doc cname: API文档 value: 'api_doc' children: - name: view - cname: 查看 +# cname: 查看 value: 'view' guest_allow: true apis: - "GET:/api/v1/service/api_doc" - name: manager - cname: 管理 +# cname: 管理 value: 'manager' apis: - "PUT:/api/v1/service/api_doc" @@ -320,22 +318,22 @@ team: value: 'upstream' children: - name: view - cname: 查看 +# cname: 查看 value: 'view' guest_allow: true apis: - "GET:/api/v1/service/upstream" - name: manager - cname: 管理 +# cname: 管理 value: 'manager' apis: - "PUT:/api/v1/service/upstream" - name: release - cname: 发布 +# cname: 发布 value: 'release' children: - name: view - cname: 查看 +# cname: 查看 value: 'view' guest_allow: true apis: @@ -346,18 +344,18 @@ team: - "GET:/api/v1/service/release/preview" - "GET:/api/v1/service/publish/status" - name: manager - cname: 管理 +# cname: 管理 value: 'manager' apis: - "POST:/api/v1/service/publish/release/do" # - "PUT:/api/v1/service/publish/execute" - "DELETE:/api/v1/service/release" - name: subscription management - cname: 订阅方管理 +# cname: 订阅方管理 value: 'subscription' children: - name: view - cname: 查看 +# cname: 查看 value: 'view' guest_allow: true apis: @@ -365,18 +363,18 @@ team: - "GET:/api/v1/service/approval/subscribe" - "GET:/api/v1/service/subscribers" - name: manager - cname: 管理 +# cname: 管理 value: 'manager' apis: - "POST:/api/v1/service/approval/subscribe" - "POST:/api/v1/service/subscriber" - "DELETE:/api/v1/service/subscriber" - name: service - cname: 服务管理 +# cname: 服务管理 value: 'service' children: - name: manager - cname: 管理 +# cname: 管理 value: 'manager' apis: - "PUT:/api/v1/service/info" @@ -391,24 +389,24 @@ team: value: 'subscription' children: - name: view - cname: 查看 +# cname: 查看 value: 'view' guest_allow: true apis: - "GET:/api/v1/application/subscriptions" - name: manager - cname: 管理 +# cname: 管理 value: 'manager' apis: - "POST:/api/v1/catalogue/service/subscribe" - "POST:/api/v1/application/subscription/cancel" - "POST:/api/v1/application/subscription/cancel_apply" - name: authorization - cname: 访问授权 +# cname: 访问授权 value: 'authorization' children: - name: view - cname: 查看 +# cname: 查看 value: 'view' guest_allow: true apis: @@ -416,58 +414,58 @@ team: - "GET:/api/v1/app/authorizations" - "GET:/api/v1/app/authorization/details" - name: manager - cname: 管理 +# cname: 管理 value: 'manager' apis: - "POST:/api/v1/app/authorization" - "PUT:/api/v1/app/authorization" - "DELETE:/api/v1/app/authorization" - name: application - cname: 应用 +# cname: 应用 value: 'application' children: - name: manager - cname: 管理 +# cname: 管理 value: 'manager' apis: - "PUT:/api/v1/app/info" - "POST:/api/v1/team/app" - "DELETE:/api/v1/app" - name: team - cname: 团队 +# cname: 团队 value: 'team' children: - name: member - cname: 成员 +# cname: 成员 value: 'member' children: - name: view - cname: 查看 +# cname: 查看 value: 'view' guest_allow: true apis: - "GET:/api/v1/team/members" - "GET:/api/v1/team/members/toadd" - name: manager - cname: 管理 +# cname: 管理 value: 'manager' apis: - "POST:/api/v1/team/member" - "DELETE:/api/v1/team/member" - "PUT:/api/v1/team/member/role" - name: team - cname: 团队管理 +# cname: 团队管理 value: 'team' children: - name: view - cname: '查看' +# cname: '查看' value: 'view' guest_allow: true apis: - "GET:/api/v1/manager/teams" - "GET:/api/v1/manager/team" - name: manager - cname: '管理' +# cname: '管理' value: 'manager' apis: - "POST:/api/v1/manager/team" diff --git a/resources/access/access_test.go b/resources/access/access_test.go index 95d216e7..afd896ca 100644 --- a/resources/access/access_test.go +++ b/resources/access/access_test.go @@ -1,12 +1,15 @@ package access import ( + "encoding/json" "fmt" "os" "sort" "strings" "testing" + yaml "gopkg.in/yaml.v3" + "github.com/eolinker/go-common/access" ) @@ -55,3 +58,55 @@ func printAccesses(group string, builder *strings.Builder) { } return } + +func TestPrintName(t *testing.T) { + result := make(map[string]string) + data, err := os.ReadFile("access.yaml") + if err != nil { + t.Fatal(err) + } + tmp := make(map[string]interface{}) + err = yaml.Unmarshal(data, &tmp) + if err != nil { + t.Fatal(err) + } + recursionReadKey("name", tmp, result) + data, err = os.ReadFile("role.yaml") + if err != nil { + t.Fatal(err) + } + tmp = make(map[string]interface{}) + err = yaml.Unmarshal(data, &tmp) + if err != nil { + t.Fatal(err) + } + recursionReadKey("name", tmp, result) + r, err := json.MarshalIndent(result, "", " ") + if err != nil { + t.Fatal(err) + } + + fmt.Println(string(r)) + +} + +// 递归读取文件中name字段 +func recursionReadKey(key string, data map[string]interface{}, result map[string]string) { + for k, v := range data { + switch t := v.(type) { + case string: + if k == key { + result[strings.ToLower(t)] = "" + } + case map[string]interface{}: + recursionReadKey(key, t, result) + case []interface{}: + for _, n := range t { + switch tt := n.(type) { + case map[string]interface{}: + recursionReadKey(key, tt, result) + } + } + } + } +} diff --git a/resources/access/permit.yaml b/resources/access/permit.yaml index 664c25bd..8a296c8f 100644 --- a/resources/access/permit.yaml +++ b/resources/access/permit.yaml @@ -1,23 +1,25 @@ system: - system.api_market.service_classification.manager: - - POST:/api/v1/catalogue - - PUT:/api/v1/catalogue - - DELETE:/api/v1/catalogue - - PUT:/api/v1/catalogue/sort - system.api_market.service_classification.view: - - GET:/api/v1/catalogues + system.dashboard.run_view.view: + - GET:/api/v1/monitor/overview/invoke + - GET:/api/v1/monitor/overview/message + - GET:/api/v1/monitor/overview/top10 + - GET:/api/v1/monitor/overview/summary + system.devops.ai_provider.manager: + - PUT:/api/v1/ai/provider/config + - PUT:/api/v1/ai/provider/default-llm system.devops.ai_provider.view: - GET:/api/v1/ai/providers - - GET:/api/v1/ai/provider - - POST:/api/v1/ai/provider - - PUT:/api/v1/ai/provider - system.devops.ai_provider.manager: - - DELETE:/api/v1/ai/provider + - GET:/api/v1/ai/provider/config system.devops.cluster.manager: - PUT:/api/v1/cluster/reset - POST:/api/v1/cluster/check system.devops.cluster.view: - GET:/api/v1/cluster/nodes + system.devops.data_source.manager: + - POST:/api/v1/monitor/config + - PUT:/api/v1/monitor/config + system.devops.data_source.view: + - GET:/api/v1/monitor/config system.devops.log_configuration.manager: - POST:/api/v1/dynamic/{name} - PUT:/api/v1/dynamic/{name}/config @@ -64,6 +66,14 @@ system: system.organization.team.view: - GET:/api/v1/manager/teams - GET:/api/v1/manager/team + system.settings.general.manager: + system.settings.general.view: + system.settings.service_classification.manager: + - POST:/api/v1/catalogue + - PUT:/api/v1/catalogue + - DELETE:/api/v1/catalogue + - PUT:/api/v1/catalogue/sort + system.settings.service_classification.view: system.workspace.api_market.view: - GET:/api/v1/catalogue/services - GET:/api/v1/catalogue/service @@ -72,10 +82,9 @@ system: system.workspace.service.view_all: - GET:/api/v1/services system.workspace.team.view_all: - - GET:/api/v1/teams + - GET:/api/v1/manager/teams team: team.application.application.manager: - - GET:/api/v1/app/info - PUT:/api/v1/app/info - POST:/api/v1/team/app - DELETE:/api/v1/app @@ -93,20 +102,13 @@ team: - POST:/api/v1/application/subscription/cancel_apply team.application.subscription.view: - GET:/api/v1/application/subscriptions - team.service.api.manager: - - POST:/api/v1/service/api - - PUT:/api/v1/service/api - - DELETE:/api/v1/service/api - - POST:/api/v1/service/api/copy - team.service.api.view: - - GET:/api/v1/service/apis - - GET:/api/v1/service/api/detail - - GET:/api/v1/service/api/detail/simple - - GET:/api/v1/service/api/define - - GET:/api/v1/service/apis/simple + team.service.api_doc.manager: + - PUT:/api/v1/service/api_doc + - POST:/api/v1/service/api_doc/upload + team.service.api_doc.view: + - GET:/api/v1/service/api_doc team.service.release.manager: - POST:/api/v1/service/publish/release/do - - PUT:/api/v1/service/publish/execute - DELETE:/api/v1/service/release team.service.release.view: - GET:/api/v1/service/releases @@ -115,8 +117,16 @@ team: - GET:/api/v1/service/publish/check - GET:/api/v1/service/release/preview - GET:/api/v1/service/publish/status + team.service.router.manager: + - POST:/api/v1/service/router + - PUT:/api/v1/service/router + - DELETE:/api/v1/service/router + team.service.router.view: + - GET:/api/v1/service/routers + - GET:/api/v1/service/router/detail + - GET:/api/v1/service/router/detail/simple + - GET:/api/v1/service/router/define team.service.service.manager: - - GET:/api/v1/service/info - PUT:/api/v1/service/info - POST:/api/v1/team/service - DELETE:/api/v1/team/service @@ -138,7 +148,6 @@ team: - PUT:/api/v1/team/member/role team.team.member.view: - GET:/api/v1/team/members - - GET:/api/v1/team/members/simple - GET:/api/v1/team/members/toadd team.team.team.manager: - POST:/api/v1/manager/team diff --git a/resources/access/role.yaml b/resources/access/role.yaml index 8cc1f5b3..30054bb5 100644 --- a/resources/access/role.yaml +++ b/resources/access/role.yaml @@ -1,6 +1,6 @@ system: - - name: supper_admin - cname: 超级管理员 + - name: supper admin + value: supper_admin permits: - system.dashboard.run_view.view - system.devops.ai_provider.manager @@ -28,8 +28,8 @@ system: - system.workspace.service.view_all - system.workspace.team.view_all supper: true - - name: team_admin - cname: 团队管理员 + - name: team admin + value: team_admin permits: - system.organization.role.view_team_role - system.organization.team.manager @@ -38,8 +38,8 @@ system: - system.workspace.application.view_all - system.workspace.service.view_all - system.workspace.team.view_all - - name: devops_admin - cname: 运维管理员 + - name: devops admin + value: devops_admin permits: - system.dashboard.run_view.view - system.devops.ai_provider.manager @@ -60,13 +60,13 @@ system: - system.settings.general.view - system.settings.service_classification.manager - system.settings.service_classification.view - - name: member - cname: 普通成员 + - name: general member + value: member permits: - system.workspace.api_market.view default: true - name: guest - cname: 只读成员 + value: guest permits: - system.settings.service_classification.view - system.devops.cluster.view @@ -83,8 +83,8 @@ system: - system.workspace.team.view_all - system.dashboard.run_view.view team: - - name: team_admin - cname: 团队管理员 + - name: team admin + value: team_admin permits: - team.application.application.manager - team.application.authorization.manager @@ -107,8 +107,8 @@ team: - team.team.team.manager - team.team.team.view supper: true - - name: service_admin - cname: 服务管理员 + - name: service admin + value: service_admin permits: - team.service.service.manager - team.service.upstream.manager @@ -122,8 +122,8 @@ team: - team.service.release.manager - team.service.release.view - team.team.member.view - - name: service_developer - cname: 服务开发者 + - name: service developer + value: service_developer permits: - team.service.upstream.manager - team.service.upstream.view @@ -134,8 +134,8 @@ team: - team.service.release.manager - team.service.release.view - team.team.member.view - - name: application_admin - cname: 应用管理员 + - name: application admin + value: application_admin permits: - team.application.application.manager - team.application.authorization.manager @@ -143,8 +143,8 @@ team: - team.application.subscription.manager - team.application.subscription.view - team.team.member.view - - name: application_developer - cname: 应用开发者 + - name: application developer + value: application_developer permits: - team.application.authorization.view - team.application.subscription.manager @@ -152,7 +152,7 @@ team: - team.team.member.view default: true - name: guest - cname: 只读成员 + value: guest permits: - team.application.authorization.view - team.application.subscription.view diff --git a/resources/locale/i18n/en-US.json b/resources/locale/i18n/en-US.json new file mode 100644 index 00000000..4d865e69 --- /dev/null +++ b/resources/locale/i18n/en-US.json @@ -0,0 +1,44 @@ +{ + "ai provider": "AI Provider", + "api market": "API Market", + "api doc": "API Documentation", + "application": "Application", + "application admin": "Application Administrator", + "application developer": "Application Developer", + "authorization": "Authorization", + "cluster": "Cluster", + "dashboard": "Dashboard", + "data source": "Data Source", + "devops": "DevOps", + "devops admin": "DevOps Administrator", + "general": "General Settings", + "general member": "General Member", + "guest": "Guest", + "log configuration": "Log Configuration", + "manager": "Manager", + "member": "Member", + "organization": "Organization Management", + "release": "Release", + "role": "Role", + "router": "Router", + "run view": "Run View", + "service": "Service", + "service admin": "Service Administrator", + "service classification": "Service Directory", + "service developer": "Service Developer", + "ssl certificate": "SSL Certificate", + "subscription management": "Subscription Management", + "subscription service": "Subscription Service", + "supper admin": "Super Administrator", + "system settings": "System Settings", + "team": "Team", + "team admin": "Team Administrator", + "upstream": "Upstream", + "view": "View", + "view all application": "View All Applications", + "view all service": "View All Services", + "view all team": "View All Teams", + "view system role": "View System Roles", + "view team role": "View Team Roles", + "workspace": "Workspace" +} diff --git a/resources/locale/i18n/ja-JP.json b/resources/locale/i18n/ja-JP.json new file mode 100644 index 00000000..894c899c --- /dev/null +++ b/resources/locale/i18n/ja-JP.json @@ -0,0 +1,44 @@ +{ + "ai provider": "AIプロバイダー", + "api market": "APIマーケット", + "api doc": "APIドキュメント", + "application": "アプリケーション", + "application admin": "アプリケーション管理者", + "application developer": "アプリケーション開発者", + "authorization": "認証", + "cluster": "クラスター", + "dashboard": "ダッシュボード", + "data source": "データソース", + "devops": "DevOps", + "devops admin": "DevOps管理者", + "general": "一般設定", + "general member": "一般メンバー", + "guest": "ゲスト", + "log configuration": "ログ設定", + "manager": "管理者", + "member": "メンバー", + "organization": "組織管理", + "release": "リリース", + "role": "役割", + "router": "ルーター", + "run view": "実行ビュー", + "service": "サービス", + "service admin": "サービス管理者", + "service classification": "サービスディレクトリ", + "service developer": "サービス開発者", + "ssl certificate": "SSL証明書", + "subscription management": "サブスクリプション管理", + "subscription service": "サブスクリプションサービス", + "supper admin": "スーパ管理者", + "system settings": "システム設定", + "team": "チーム", + "team admin": "チーム管理者", + "upstream": "アップストリーム", + "view": "表示", + "view all application": "すべてのアプリケーションを表示", + "view all service": "すべてのサービスを表示", + "view all team": "すべてのチームを表示", + "view system role": "システム役割を表示", + "view team role": "チーム役割を表示", + "workspace": "ワークスペース" +} diff --git a/resources/locale/i18n/zh-CN.json b/resources/locale/i18n/zh-CN.json new file mode 100644 index 00000000..ea248a81 --- /dev/null +++ b/resources/locale/i18n/zh-CN.json @@ -0,0 +1,44 @@ +{ + "ai provider": "AI供应商", + "api market": "API市场", + "api doc": "API文档", + "application": "应用", + "application admin": "应用管理员", + "application developer": "应用开发者", + "authorization": "鉴权", + "cluster": "集群", + "dashboard": "仪表盘", + "data source": "数据源", + "devops": "运维", + "devops admin": "运维管理员", + "general": "常规设置", + "general member": "普通成员", + "guest": "访客", + "log configuration": "日志配置", + "manager": "管理", + "member": "成员", + "organization": "组织管理", + "release": "发布", + "role": "角色", + "router": "路由", + "run view": "运行视图", + "service": "服务", + "service admin": "服务管理员", + "service classification": "服务目录", + "service developer": "服务开发者", + "ssl certificate": "SSL证书", + "subscription management": "订阅方管理", + "subscription service": "订阅服务", + "supper admin": "超级管理员", + "system settings": "系统设置", + "team": "团队", + "team admin": "团队管理员", + "upstream": "上游", + "view": "查看", + "view all application": "查看所有应用", + "view all service": "查看所有服务", + "view all team": "查看所有团队", + "view system role": "查看系统角色", + "view team role": "查看团队角色", + "workspace": "工作空间" +} \ No newline at end of file diff --git a/resources/locale/i18n/zh-TW.json b/resources/locale/i18n/zh-TW.json new file mode 100644 index 00000000..44c6075f --- /dev/null +++ b/resources/locale/i18n/zh-TW.json @@ -0,0 +1,44 @@ +{ + "ai provider": "AI供應商", + "api market": "API市場", + "api doc": "API文檔", + "application": "應用", + "application admin": "應用管理員", + "application developer": "應用開發者", + "authorization": "授權", + "cluster": "集群", + "dashboard": "儀表盤", + "data source": "數據源", + "devops": "運維", + "devops admin": "運維管理員", + "general": "常規設置", + "general member": "普通成員", + "guest": "訪客", + "log configuration": "日誌配置", + "manager": "管理", + "member": "成員", + "organization": "組織管理", + "release": "發布", + "role": "角色", + "router": "路由", + "run view": "運行視圖", + "service": "服務", + "service admin": "服務管理員", + "service classification": "服務目錄", + "service developer": "服務開發者", + "ssl certificate": "SSL證書", + "subscription management": "訂閱方管理", + "subscription service": "訂閱服務", + "supper admin": "超級管理員", + "system settings": "系統設置", + "team": "團隊", + "team admin": "團隊管理員", + "upstream": "上游", + "view": "查看", + "view all application": "查看所有應用", + "view all service": "查看所有服務", + "view all team": "查看所有團隊", + "view system role": "查看系統角色", + "view team role": "查看團隊角色", + "workspace": "工作空間" +} diff --git a/resources/locale/locale.go b/resources/locale/locale.go new file mode 100644 index 00000000..7b75955b --- /dev/null +++ b/resources/locale/locale.go @@ -0,0 +1,52 @@ +package locale + +import ( + "embed" + "encoding/json" + "strings" + + "github.com/eolinker/eosc" +) + +var ( + //go:embed i18n/* + i18nDirs embed.FS + i18nData eosc.Untyped[string, map[string]string] + defaultI18n = "zh-CN" +) + +func init() { + i18nData = eosc.BuildUntyped[string, map[string]string]() + files, err := i18nDirs.ReadDir("i18n") + if err != nil { + panic(err) + } + var data []byte + for _, f := range files { + data, err = i18nDirs.ReadFile("i18n/" + f.Name()) + if err != nil { + panic(err) + } + + tmp := make(map[string]string) + err = json.Unmarshal(data, &tmp) + if err != nil { + panic(err) + } + key := strings.TrimSuffix(f.Name(), ".json") + i18nData.Set(key, tmp) + } +} + +func Get(i18n string) map[string]string { + result, has := i18nData.Get(i18n) + if has { + return result + } + + result, has = i18nData.Get(defaultI18n) + if !has { + return make(map[string]string) + } + return result +} From 7101584d756ed41f2f8505f99ef04075208f8015 Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Fri, 18 Oct 2024 19:51:42 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=B3=A8=E9=87=8Aap-account=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 2 +- go.sum | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index ba1f9dfa..14c04ce1 100644 --- a/go.mod +++ b/go.mod @@ -76,4 +76,4 @@ require ( gorm.io/driver/mysql v1.5.2 // indirect ) -replace github.com/eolinker/ap-account => ../../eolinker/ap-account +//replace github.com/eolinker/ap-account => ../../eolinker/ap-account diff --git a/go.sum b/go.sum index 8ed516ee..ad8b4e19 100644 --- a/go.sum +++ b/go.sum @@ -27,6 +27,7 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= +github.com/eolinker/ap-account v1.0.11/go.mod h1:5lsZwkQfnHO5YJ3Cu6X1PZwZ0gbmJBUcix0hxG8aEsY= github.com/eolinker/eosc v0.17.3 h1:sr2yT+v/AsqEdciRaaZZj0zL9pTufR5RvDW6+65hraQ= github.com/eolinker/eosc v0.17.3/go.mod h1:xgq816hpanlMXFtZw7Ztdctb1eEk9UPHchY4NfFO6Cw= github.com/eolinker/go-common v1.1.0 h1:n/XXK7yVRen3jhNG/SfZGXJA+KNnaYf0XTDfMeviaBw= From 06b1cb3400c8e3870580a3face2bac517ed17227 Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Fri, 18 Oct 2024 22:15:55 +0800 Subject: [PATCH 5/5] Initial installation of initialization data for simplified use. --- controller/system/iml.go | 243 +++++++++++++++++++++++++---- module/ai/iml.go | 3 +- module/service/module.go | 1 + stores/universally/commit/wtype.go | 1 + 4 files changed, 218 insertions(+), 30 deletions(-) diff --git a/controller/system/iml.go b/controller/system/iml.go index a11b2e23..3739419e 100644 --- a/controller/system/iml.go +++ b/controller/system/iml.go @@ -7,14 +7,31 @@ import ( "encoding/json" "fmt" "net/http" + "strings" "time" + "github.com/eolinker/eosc/log" + + ai_dto "github.com/APIParkLab/APIPark/module/ai/dto" + + "github.com/APIParkLab/APIPark/model/plugin_model" + "github.com/APIParkLab/APIPark/service/api" + + ai_api "github.com/APIParkLab/APIPark/module/ai-api" + + model_runtime "github.com/APIParkLab/APIPark/ai-provider/model-runtime" + ai_api_dto "github.com/APIParkLab/APIPark/module/ai-api/dto" + router_dto "github.com/APIParkLab/APIPark/module/router/dto" + + "github.com/eolinker/go-common/store" + + "github.com/APIParkLab/APIPark/module/ai" + catalogue_dto "github.com/APIParkLab/APIPark/module/catalogue/dto" application_authorization_dto "github.com/APIParkLab/APIPark/module/application-authorization/dto" service_dto "github.com/APIParkLab/APIPark/module/service/dto" team_dto "github.com/APIParkLab/APIPark/module/team/dto" - "github.com/eolinker/eosc/log" "github.com/eolinker/go-common/register" "github.com/eolinker/go-common/server" "github.com/eolinker/go-common/utils" @@ -201,35 +218,84 @@ func (i *imlSettingController) Set(ctx *gin.Context, input *system_dto.InputSett type imlInitController struct { teamModule team.ITeamModule `autowired:""` appModule service.IAppModule `autowired:""` + serviceModule service.IServiceModule `autowired:""` applicationAuthorizationModule application_authorization.IAuthorizationModule `autowired:""` catalogueModule catalogue.ICatalogueModule `autowired:""` + providerModule ai.IProviderModule `autowired:""` + transaction store.ITransaction `autowired:""` + aiAPIModule ai_api.IAPIModule `autowired:""` + docModule service.IServiceDocModule `autowired:""` + routerModule router.IRouterModule `autowired:""` } func (i *imlInitController) OnInit() { register.Handle(func(v server.Server) { ctx := utils.SetUserId(context.Background(), "admin") - teams, err := i.teamModule.Search(ctx, "") - if err != nil { - log.Error("get teams error: %v", err) - return - } - if len(teams) == 0 { + + err := i.transaction.Transaction(ctx, func(ctx context.Context) error { + teams, err := i.teamModule.Search(ctx, "") + if err != nil { + return fmt.Errorf("get teams error: %v", err) + } + if len(teams) > 0 { + return nil + } + items, err := i.catalogueModule.Search(ctx, "") + if err != nil { + return fmt.Errorf("get catalogue error: %v", err) + } + catalogueId := uuid.New().String() + if len(items) == 0 { + err = i.catalogueModule.Create(ctx, &catalogue_dto.CreateCatalogue{ + Id: catalogueId, + Name: "Default Catalogue", + }) + if err != nil { + return fmt.Errorf("create default catalogue error: %v", err) + } + } else { + catalogueId = items[0].Id + } + info, err := i.teamModule.Create(ctx, &team_dto.CreateTeam{ Name: "Default Team", Description: "Auto created By APIPark", }) if err != nil { - log.Error("create default team error: %v", err) - return + return fmt.Errorf("create default team error: %v", err) + } + // 创建Rest服务 + _, err = i.serviceModule.Create(ctx, info.Id, &service_dto.CreateService{ + Name: "REST Demo Service", + Prefix: "/rest-demo", + Description: "Auto created By APIPark", + ServiceType: "public", + Catalogue: catalogueId, + ApprovalType: "auto", + Kind: "rest", + }) + if err != nil { + return fmt.Errorf("create default service error: %v", err) + } + // 创建AI服务 + err = i.createAIService(ctx, info.Id, &service_dto.CreateService{ + Name: "AI Demo Service", + Prefix: "/ai-demo", + Description: "Auto created By APIPark", + ServiceType: "public", + Catalogue: catalogueId, + ApprovalType: "auto", + Kind: "ai", + }) + if err != nil { + return err } app, err := i.appModule.CreateApp(ctx, info.Id, &service_dto.CreateApp{ Name: "Demo Application", Description: "Auto created By APIPark", }) if err != nil { - i.teamModule.Delete(ctx, info.Id) - log.Error("create default app error: %v", err) - return + return fmt.Errorf("create default app error: %v", err) } _, err = i.applicationAuthorizationModule.AddAuthorization(ctx, app.Id, &application_authorization_dto.CreateAuthorization{ Name: "Default API Key", @@ -242,25 +308,144 @@ func (i *imlInitController) OnInit() { }, }) if err != nil { - i.teamModule.Delete(ctx, info.Id) - i.appModule.DeleteApp(ctx, app.Id) - log.Error("create default api key error: %v", err) - return + return fmt.Errorf("create default api key error: %v", err) } - } - items, err := i.catalogueModule.Search(ctx, "") + return nil + }) if err != nil { - log.Error("get catalogue error: %v", err) - return - } - if len(items) == 0 { - err = i.catalogueModule.Create(ctx, &catalogue_dto.CreateCatalogue{ - Name: "Default Catalogue", - }) - if err != nil { - log.Error("create default catalogue error: %v", err) - return - } + log.Errorf("init iml error: %v", err) } }) } +func (i *imlInitController) createAIService(ctx context.Context, teamID string, input *service_dto.CreateService) error { + + providerId := "openai" + err := i.providerModule.UpdateProviderConfig(ctx, "openai", &ai_dto.UpdateConfig{ + Config: "{\n \"openai_api_base\": \"API Base\",\n \"openai_api_key\": \"API Key\",\n \"openai_organization\": \"Organization\"\n}", + }) + if err != nil { + return fmt.Errorf("update openai config error: %v", err) + } + input.Provider = &providerId + if input.Id == "" { + input.Id = uuid.New().String() + } + if input.Prefix == "" { + if len(input.Id) < 9 { + input.Prefix = input.Id + } else { + input.Prefix = input.Id[:8] + } + } + pv, err := i.providerModule.Provider(ctx, *input.Provider) + if err != nil { + return err + } + p, has := model_runtime.GetProvider(*input.Provider) + if !has { + return fmt.Errorf("provider not found") + } + m, has := p.GetModel(pv.DefaultLLM) + if !has { + return fmt.Errorf("model %s not found", pv.DefaultLLM) + } + + var info *service_dto.Service + err = i.transaction.Transaction(ctx, func(txCtx context.Context) error { + var err error + info, err = i.serviceModule.Create(ctx, teamID, input) + if err != nil { + return err + } + path := fmt.Sprintf("/%s/demo_translation_api", strings.Trim(input.Prefix, "/")) + timeout := 300000 + retry := 0 + aiPrompt := &ai_api_dto.AiPrompt{ + Variables: []*ai_api_dto.AiPromptVariable{ + { + Key: "source_lang", + Description: "", + Require: true, + }, + { + Key: "target_lang", + Description: "", + Require: true, + }, + { + Key: "text", + Description: "", + Require: true, + }, + }, + Prompt: "You need to translate {{source_lang}} into {{target_lang}}, and the following is the content that needs to be translated.\n---\n{{text}}", + } + aiModel := &ai_api_dto.AiModel{ + Id: m.ID(), + Config: m.DefaultConfig(), + } + name := "Demo Translation API" + description := "A demo that shows you how to use a prompt to create a Translation API." + apiId := uuid.New().String() + err = i.aiAPIModule.Create( + ctx, + info.Id, + &ai_api_dto.CreateAPI{ + Id: apiId, + Name: name, + Path: path, + Description: description, + Disable: false, + AiPrompt: aiPrompt, + AiModel: aiModel, + Timeout: timeout, + Retry: retry, + }, + ) + if err != nil { + return err + } + plugins := make(map[string]api.PluginSetting) + plugins["ai_prompt"] = api.PluginSetting{ + Config: plugin_model.ConfigType{ + "prompt": aiPrompt.Prompt, + "variables": aiPrompt.Variables, + }, + } + plugins["ai_formatter"] = api.PluginSetting{ + Config: plugin_model.ConfigType{ + "model": aiModel.Id, + "provider": fmt.Sprintf("%s@ai-provider", info.Provider.Id), + "config": aiModel.Config, + }, + } + _, err = i.routerModule.Create(ctx, info.Id, &router_dto.Create{ + Id: apiId, + Name: name, + Path: path, + Methods: []string{ + http.MethodPost, + }, + Description: description, + Protocols: []string{"http", "https"}, + MatchRules: nil, + Proxy: &router_dto.InputProxy{ + Path: path, + Timeout: timeout, + Retry: retry, + Plugins: plugins, + }, + Disable: false, + Upstream: info.Provider.Id, + }) + if err != nil { + return err + } + + return i.docModule.SaveServiceDoc(ctx, info.Id, &service_dto.SaveServiceDoc{ + Doc: "The Translation API allows developers to translate text from one language to another. It supports multiple languages and enables easy integration of high-quality translation features into applications. With simple API requests, you can quickly translate content into different target languages.", + }) + }) + + return err +} diff --git a/module/ai/iml.go b/module/ai/iml.go index 5f55f650..ba65e8e4 100644 --- a/module/ai/iml.go +++ b/module/ai/iml.go @@ -398,7 +398,8 @@ func (i *imlProviderModule) initGateway(ctx context.Context, clusterId string, c func (i *imlProviderModule) syncGateway(ctx context.Context, clusterId string, releases []*gateway.DynamicRelease, online bool) error { client, err := i.clusterService.GatewayClient(ctx, clusterId) if err != nil { - return err + log.Errorf("get apinto client error: %v", err) + return nil } defer func() { err := client.Close(ctx) diff --git a/module/service/module.go b/module/service/module.go index 900c5454..4ff83857 100644 --- a/module/service/module.go +++ b/module/service/module.go @@ -24,6 +24,7 @@ type IServiceModule interface { Edit(ctx context.Context, id string, input *service_dto.EditService) (*service_dto.Service, error) // Delete 删除项目 Delete(ctx context.Context, id string) error + // Simple 获取简易项目列表 //Simple(ctx context.Context, keyword string) ([]*service_dto.SimpleServiceItem, error) diff --git a/stores/universally/commit/wtype.go b/stores/universally/commit/wtype.go index ee9a967a..b7066349 100644 --- a/stores/universally/commit/wtype.go +++ b/stores/universally/commit/wtype.go @@ -24,6 +24,7 @@ func NewCommitWithKey[H any](name, key string) *StoreWidthType[H] { Store: Store[H]{ latestTableName: name + "_latest", commitTableName: name + "_commit", + name: name, }, key: key, }