api文档完成

This commit is contained in:
Liujian
2024-08-30 09:55:56 +08:00
parent f3a00814a5
commit f570c8b174
75 changed files with 2206 additions and 753 deletions
+17 -14
View File
@@ -1,43 +1,46 @@
package api
import (
api_doc_dto "github.com/APIParkLab/APIPark/module/api-doc/dto"
"reflect"
"github.com/gin-gonic/gin"
"github.com/eolinker/go-common/autowire"
api_dto "github.com/APIParkLab/APIPark/module/api/dto"
)
type IAPIController interface {
// Detail 获取API详情
Detail(ctx *gin.Context, serviceId string, apiId string) (*api_dto.ApiDetail, error)
// SimpleDetail 获取API简要详情
SimpleDetail(ctx *gin.Context, serviceId string, apiId string) (*api_dto.ApiSimpleDetail, error)
// Search 获取API列表
Search(ctx *gin.Context, keyword string, serviceId string) ([]*api_dto.ApiItem, error)
// SimpleSearch 获取API简要列表
SimpleSearch(ctx *gin.Context, keyword string, serviceId string) ([]*api_dto.ApiSimpleItem, error)
//SimpleList(ctx *gin.Context, serviceId string) ([]*api_dto.ApiSimpleItem, error)
// Create 创建API
Create(ctx *gin.Context, serviceId string, dto *api_dto.CreateApi) (*api_dto.ApiSimpleDetail, error)
// Edit 编辑API
Edit(ctx *gin.Context, serviceId string, apiId string, dto *api_dto.EditApi) (*api_dto.ApiSimpleDetail, error)
// Delete 删除API
Delete(ctx *gin.Context, serviceId string, apiId string) error
// Copy 复制API
Copy(ctx *gin.Context, serviceId string, apiId string, dto *api_dto.CreateApi) (*api_dto.ApiSimpleDetail, error)
// ApiDocDetail 获取API文档详情
ApiDocDetail(ctx *gin.Context, serviceId string, apiId string) (*api_dto.ApiDocDetail, error)
// ApiProxyDetail 获取API代理详情
ApiProxyDetail(ctx *gin.Context, serviceId string, apiId string) (*api_dto.ApiProxyDetail, error)
// Prefix 获取API前缀
Prefix(ctx *gin.Context, serviceId string) (string, bool, error)
}
type IAPIDocController interface {
// UpdateDoc 更新API文档
UpdateDoc(ctx *gin.Context, serviceId string, input *api_doc_dto.UpdateDoc) (*api_doc_dto.ApiDocDetail, error)
// GetDoc 获取API文档
GetDoc(ctx *gin.Context, serviceId string) (*api_doc_dto.ApiDocDetail, error)
UploadDoc(ctx *gin.Context, serviceId string) (*api_doc_dto.ApiDocDetail, error)
}
func init() {
autowire.Auto[IAPIController](func() reflect.Value {
return reflect.ValueOf(new(imlAPIController))
})
autowire.Auto[IAPIDocController](func() reflect.Value {
return reflect.ValueOf(new(imlAPIDocController))
})
}
+38 -24
View File
@@ -2,8 +2,11 @@ package api
import (
"github.com/APIParkLab/APIPark/module/api"
api_doc "github.com/APIParkLab/APIPark/module/api-doc"
api_doc_dto "github.com/APIParkLab/APIPark/module/api-doc/dto"
api_dto "github.com/APIParkLab/APIPark/module/api/dto"
"github.com/gin-gonic/gin"
"io"
)
var _ IAPIController = (*imlAPIController)(nil)
@@ -12,26 +15,14 @@ type imlAPIController struct {
module api.IApiModule `autowired:""`
}
//func (i *imlAPIController) SimpleList(ctx *gin.Context, serviceId string) ([]*api_dto.ApiSimpleItem, error) {
// return i.module.SimpleList(ctx, serviceId)
//}
func (i *imlAPIController) Detail(ctx *gin.Context, serviceId string, apiId string) (*api_dto.ApiDetail, error) {
return i.module.Detail(ctx, serviceId, apiId)
}
func (i *imlAPIController) SimpleDetail(ctx *gin.Context, serviceId string, apiId string) (*api_dto.ApiSimpleDetail, error) {
return i.module.SimpleDetail(ctx, serviceId, apiId)
}
func (i *imlAPIController) Search(ctx *gin.Context, keyword string, serviceId string) ([]*api_dto.ApiItem, error) {
return i.module.Search(ctx, keyword, serviceId)
}
func (i *imlAPIController) SimpleSearch(ctx *gin.Context, keyword string, serviceId string) ([]*api_dto.ApiSimpleItem, error) {
return i.module.SimpleSearch(ctx, keyword, serviceId)
}
func (i *imlAPIController) Create(ctx *gin.Context, serviceId string, dto *api_dto.CreateApi) (*api_dto.ApiSimpleDetail, error) {
return i.module.Create(ctx, serviceId, dto)
}
@@ -44,18 +35,6 @@ func (i *imlAPIController) Delete(ctx *gin.Context, serviceId string, apiId stri
return i.module.Delete(ctx, serviceId, apiId)
}
func (i *imlAPIController) Copy(ctx *gin.Context, serviceId string, apiId string, dto *api_dto.CreateApi) (*api_dto.ApiSimpleDetail, error) {
return i.module.Copy(ctx, serviceId, apiId, dto)
}
func (i *imlAPIController) ApiDocDetail(ctx *gin.Context, serviceId string, apiId string) (*api_dto.ApiDocDetail, error) {
return i.module.ApiDocDetail(ctx, serviceId, apiId)
}
func (i *imlAPIController) ApiProxyDetail(ctx *gin.Context, serviceId string, apiId string) (*api_dto.ApiProxyDetail, error) {
return i.module.ApiProxyDetail(ctx, serviceId, apiId)
}
func (i *imlAPIController) Prefix(ctx *gin.Context, serviceId string) (string, bool, error) {
prefix, err := i.module.Prefix(ctx, serviceId)
if err != nil {
@@ -63,3 +42,38 @@ func (i *imlAPIController) Prefix(ctx *gin.Context, serviceId string) (string, b
}
return prefix, true, nil
}
var _ IAPIDocController = (*imlAPIDocController)(nil)
type imlAPIDocController struct {
module api_doc.IAPIDocModule `autowired:""`
}
func (i *imlAPIDocController) UpdateDoc(ctx *gin.Context, serviceId string, input *api_doc_dto.UpdateDoc) (*api_doc_dto.ApiDocDetail, error) {
return i.module.UpdateDoc(ctx, serviceId, input)
}
func (i *imlAPIDocController) GetDoc(ctx *gin.Context, serviceId string) (*api_doc_dto.ApiDocDetail, error) {
return i.module.GetDoc(ctx, serviceId)
}
func (i *imlAPIDocController) UploadDoc(ctx *gin.Context, serviceId string) (*api_doc_dto.ApiDocDetail, error) {
// 获取文件内容
fileHeader, err := ctx.FormFile("doc")
if err != nil {
return nil, err
}
file, err := fileHeader.Open()
if err != nil {
return nil, err
}
content, err := io.ReadAll(file)
if err != nil {
return nil, err
}
return i.module.UpdateDoc(ctx, serviceId, &api_doc_dto.UpdateDoc{
Content: string(content),
})
}
File diff suppressed because one or more lines are too long
+1
View File
@@ -0,0 +1 @@
[{"id":"358caa9f-a079-44dd-8b28-c1d065777b6c","name":"Demo App","description":"Create the App to apply services","team":"eef18cfb-140b-4e78-b9eb-ad669d898110"}]
+1
View File
@@ -0,0 +1 @@
[{"service":"2d8beb9c-121f-4f6c-b860-50c02520e6f3","application":"358caa9f-a079-44dd-8b28-c1d065777b6c","reason":""}]
@@ -0,0 +1 @@
[{"application":"358caa9f-a079-44dd-8b28-c1d065777b6c","id":"9179f789-869b-40a5-8e45-d0c85c640f29","name":"Demo Auth Key","driver":"apikey","position":"Header","token_name":"Authorization","config":{"apikey":"da66c011-39ba-44eb-a318-3f1407644543","label":null},"expire_time":0,"hide_credential":false}]
+1
View File
@@ -0,0 +1 @@
[{"id":"16793ef0-cdb7-4c80-84eb-9a1a0c02113b","name":"AI","parent":"","sort":0},{"id":"542f3032-2b33-417a-88ee-44dbde7eec68","name":"Cloud Service","parent":"","sort":0},{"id":"6887358d-bcf5-4ebf-b945-6f882c2cde10","name":"Data Analysis","parent":"","sort":0},{"id":"706b75cf-855c-4940-9ce6-05055c95c581","name":"Development","parent":"","sort":0},{"id":"29417527-0245-4db4-8cd8-a9a02deeeda3","name":"IoT","parent":"","sort":0}]
File diff suppressed because one or more lines are too long
+1
View File
@@ -0,0 +1 @@
[{"id":"13a1d172-6e67-4581-a95b-61ea4c54ebbb","service":"2d8beb9c-121f-4f6c-b860-50c02520e6f3","subscriber":"358caa9f-a079-44dd-8b28-c1d065777b6c","team":"","applier":"","from":1}]
+1
View File
@@ -0,0 +1 @@
[{"id":"eef18cfb-140b-4e78-b9eb-ad669d898110","name":"Demo Team","description":""}]
+1
View File
@@ -0,0 +1 @@
[{"id":"2d8beb9c-121f-4f6c-b860-50c02520e6f3","name":"","service":"2d8beb9c-121f-4f6c-b860-50c02520e6f3","driver":"static","balance":"round-robin","timeout":3,"retry":3,"remark":"","limit_peer_second":10000,"proxy_headers":[],"scheme":"HTTPS","pass_host":"pass","upstream_host":"","nodes":[{"address":"demoapi.apipark.com","weight":999}],"discover":{"discover":"","service":""}}]
+167
View File
@@ -0,0 +1,167 @@
package system
import (
"archive/zip"
"bytes"
"encoding/json"
"fmt"
"github.com/APIParkLab/APIPark/module/api"
application_authorization "github.com/APIParkLab/APIPark/module/application-authorization"
"github.com/APIParkLab/APIPark/module/catalogue"
"github.com/APIParkLab/APIPark/module/service"
"github.com/APIParkLab/APIPark/module/subscribe"
"github.com/APIParkLab/APIPark/module/team"
"github.com/APIParkLab/APIPark/module/upstream"
"github.com/gin-gonic/gin"
"net/http"
"time"
)
var _ IExportConfigController = (*imlExportConfigController)(nil)
type imlExportConfigController struct {
teamModule team.ITeamExportModule `autowired:""`
serviceModule service.IExportServiceModule `autowired:""`
appModule service.IExportAppModule `autowired:""`
apiModule api.IExportApiModule `autowired:""`
upstreamModule upstream.IExportUpstreamModule `autowired:""`
applicationAuthorizationModule application_authorization.IExportAuthorizationModule `autowired:""`
catalogueModule catalogue.IExportCatalogueModule `autowired:""`
subscribeModule subscribe.IExportSubscribeModule `autowired:""`
applyModule subscribe.IExportSubscribeApprovalModule `autowired:""`
}
type ExportFile struct {
Driver string `json:"driver"`
Data interface{} `json:"data"`
}
func (e *ExportFile) Byte() []byte {
b, _ := json.Marshal(e.Data)
return b
}
func zipFile(files []*ExportFile) (*bytes.Buffer, error) {
// 创建一个缓冲区用于存储 ZIP 文件内容
buf := new(bytes.Buffer)
zipWriter := zip.NewWriter(buf)
now := time.Now()
// 将文件写入 ZIP
for _, file := range files {
header := &zip.FileHeader{
Name: fmt.Sprintf("%s.json", file.Driver),
Method: zip.Deflate,
Modified: now,
}
f, err := zipWriter.CreateHeader(header)
if err != nil {
return nil, fmt.Errorf("failed to create zip file: %v", err)
}
_, err = f.Write(file.Byte())
if err != nil {
return nil, fmt.Errorf("failed to write to zip file: %v", err)
}
}
// 关闭 ZIP writer,完成压缩过程
err := zipWriter.Close()
if err != nil {
return nil, fmt.Errorf("failed to close zip writer: %v", err)
}
return buf, nil
}
func (i *imlExportConfigController) ExportAll(ctx *gin.Context) error {
files, err := i.appendFiles(ctx)
if err != nil {
return err
}
buf, err := zipFile(files)
if err != nil {
}
ctx.DataFromReader(http.StatusOK, int64(buf.Len()), "application/zip", buf, map[string]string{
"Content-Disposition": "attachment; filename=\"export.zip\"",
})
return nil
}
func (i *imlExportConfigController) appendFiles(ctx *gin.Context) ([]*ExportFile, error) {
type exportConfig struct {
exportFunc func(ctx *gin.Context) (interface{}, error)
driver string
}
exports := []exportConfig{
{
exportFunc: func(ctx *gin.Context) (interface{}, error) {
return i.teamModule.ExportAll(ctx)
},
driver: "team",
},
{
exportFunc: func(ctx *gin.Context) (interface{}, error) {
return i.serviceModule.ExportAll(ctx)
},
driver: "service",
},
{
exportFunc: func(ctx *gin.Context) (interface{}, error) {
return i.appModule.ExportAll(ctx)
},
driver: "app",
},
{
exportFunc: func(ctx *gin.Context) (interface{}, error) {
return i.apiModule.ExportAll(ctx)
},
driver: "api",
},
{
exportFunc: func(ctx *gin.Context) (interface{}, error) {
return i.upstreamModule.ExportAll(ctx)
},
driver: "upstream",
},
{
exportFunc: func(ctx *gin.Context) (interface{}, error) {
return i.applicationAuthorizationModule.ExportAll(ctx)
},
driver: "authorization",
},
{
exportFunc: func(ctx *gin.Context) (interface{}, error) {
return i.catalogueModule.ExportAll(ctx)
},
driver: "catalogue",
},
{
exportFunc: func(ctx *gin.Context) (interface{}, error) {
return i.subscribeModule.ExportAll(ctx)
},
driver: "subscribe",
},
{
exportFunc: func(ctx *gin.Context) (interface{}, error) {
return i.applyModule.ExportAll(ctx)
},
driver: "apply",
},
}
files := make([]*ExportFile, 0, len(exports))
for _, config := range exports {
data, err := config.exportFunc(ctx)
if err != nil {
return nil, fmt.Errorf("[%s] failed to export data: %v", config.driver, err)
}
files = append(files, &ExportFile{
Driver: config.driver,
Data: data,
})
}
return files, nil
}
+458
View File
@@ -0,0 +1,458 @@
package system
import (
"context"
"embed"
"encoding/json"
"errors"
"fmt"
"github.com/APIParkLab/APIPark/module/api"
api_dto "github.com/APIParkLab/APIPark/module/api/dto"
application_authorization "github.com/APIParkLab/APIPark/module/application-authorization"
application_authorization_dto "github.com/APIParkLab/APIPark/module/application-authorization/dto"
"github.com/APIParkLab/APIPark/module/catalogue"
catalogue_dto "github.com/APIParkLab/APIPark/module/catalogue/dto"
"github.com/APIParkLab/APIPark/module/publish"
"github.com/APIParkLab/APIPark/module/publish/dto"
"github.com/APIParkLab/APIPark/module/release"
dto2 "github.com/APIParkLab/APIPark/module/release/dto"
"github.com/APIParkLab/APIPark/module/service"
service_dto "github.com/APIParkLab/APIPark/module/service/dto"
"github.com/APIParkLab/APIPark/module/subscribe"
subscribe_dto "github.com/APIParkLab/APIPark/module/subscribe/dto"
"github.com/APIParkLab/APIPark/module/team"
team_dto "github.com/APIParkLab/APIPark/module/team/dto"
"github.com/APIParkLab/APIPark/module/upstream"
upstream_dto "github.com/APIParkLab/APIPark/module/upstream/dto"
"github.com/eolinker/go-common/store"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
var (
//go:embed config/*.json
importConfigs embed.FS
)
func unmarshal[T any](name string) ([]*T, error) {
data, err := importConfigs.ReadFile(fmt.Sprintf("config/%s.json", name))
if err != nil {
return nil, fmt.Errorf("fail to read file(%s): %v", name, err)
}
t := make([]*T, 0)
err = json.Unmarshal(data, &t)
return t, err
}
var (
_ IImportConfigController = (*imlImportConfigController)(nil)
)
type imlImportConfigController struct {
teamModule team.ITeamModule `autowired:""`
serviceModule service.IServiceModule `autowired:""`
appModule service.IAppModule `autowired:""`
apiModule api.IApiModule `autowired:""`
upstreamModule upstream.IUpstreamModule `autowired:""`
applicationAuthorizationModule application_authorization.IAuthorizationModule `autowired:""`
catalogueModule catalogue.ICatalogueModule `autowired:""`
subscribeModule subscribe.ISubscribeModule `autowired:""`
applyModule subscribe.ISubscribeApprovalModule `autowired:""`
publishModule publish.IPublishModule `autowired:""`
releaseModule release.IReleaseModule `autowired:""`
transaction store.ITransaction `autowired:""`
}
func (i *imlImportConfigController) ImportAll(ctx *gin.Context) error {
return i.transaction.Transaction(ctx, func(transCtx context.Context) error {
err := i.importTeams(transCtx)
if err != nil {
return err
}
err = i.importCatalogues(transCtx)
if err != nil {
return err
}
err = i.importServices(transCtx)
if err != nil {
return err
}
err = i.importApplications(transCtx)
if err != nil {
return err
}
err = i.importApplicationAuth(transCtx)
if err != nil {
return err
}
err = i.importApis(transCtx)
if err != nil {
return err
}
err = i.importUpstreams(transCtx)
if err != nil {
return err
}
err = i.publish(transCtx)
if err != nil {
return err
}
err = i.importSubscribers(transCtx)
if err != nil {
return err
}
return nil
})
}
func (i *imlImportConfigController) importTeams(ctx context.Context) error {
data, err := unmarshal[team_dto.ExportTeam]("team")
if err != nil {
return err
}
for _, d := range data {
// 判断是否存在,如果存在,则更新
_, err = i.teamModule.GetTeam(ctx, d.Id)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
return err
}
_, err = i.teamModule.Create(ctx, &team_dto.CreateTeam{
Id: d.Id,
Name: d.Name,
Description: d.Description,
})
if err != nil {
return fmt.Errorf("create team(%s) error: %v", d.Id, err)
}
continue
}
_, err = i.teamModule.Edit(ctx, d.Id, &team_dto.EditTeam{
Name: &d.Name,
Description: &d.Description,
})
if err != nil {
return fmt.Errorf("update team(%s) error: %v", d.Id, err)
}
}
return nil
}
func (i *imlImportConfigController) importServices(ctx context.Context) error {
data, err := unmarshal[service_dto.ExportService]("service")
if err != nil {
return err
}
for _, d := range data {
// 判断是否存在,如果存在,则更新
_, err = i.serviceModule.Get(ctx, d.Id)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
return err
}
_, err = i.serviceModule.Create(ctx, d.Team, &service_dto.CreateService{
Id: d.Id,
Name: d.Name,
Prefix: d.Prefix,
Description: d.Description,
ServiceType: d.ServiceType,
Logo: d.Logo,
Tags: d.Tags,
Catalogue: d.Catalogue,
})
if err != nil {
return fmt.Errorf("create service(%s) error: %v", d.Id, err)
}
} else {
_, err = i.serviceModule.Edit(ctx, d.Id, &service_dto.EditService{
Name: &d.Name,
Description: &d.Description,
ServiceType: &d.ServiceType,
Catalogue: &d.Catalogue,
Logo: &d.Logo,
Tags: &d.Tags,
})
if err != nil {
return fmt.Errorf("update service(%s) error: %v", d.Id, err)
}
}
err = i.serviceModule.SaveServiceDoc(ctx, d.Id, &service_dto.SaveServiceDoc{Doc: d.Doc})
if err != nil {
return fmt.Errorf("save service(%s) doc error: %v", d.Id, err)
}
}
return nil
}
func (i *imlImportConfigController) importApplications(ctx context.Context) error {
data, err := unmarshal[service_dto.ExportApp]("app")
if err != nil {
return err
}
for _, d := range data {
// 判断是否存在,如果存在,则更新
_, err = i.appModule.GetApp(ctx, d.Id)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
return err
}
_, err = i.appModule.CreateApp(ctx, d.Team, &service_dto.CreateApp{
Id: d.Id,
Name: d.Name,
Description: d.Description,
})
if err != nil {
return fmt.Errorf("create app(%s) error: %v", d.Id, err)
}
continue
}
_, err = i.appModule.UpdateApp(ctx, d.Id, &service_dto.UpdateApp{
Name: &d.Name,
Description: &d.Description,
})
if err != nil {
return fmt.Errorf("update app(%s) error: %v", d.Id, err)
}
}
return nil
}
func (i *imlImportConfigController) importApis(ctx context.Context) error {
data, err := unmarshal[api_dto.ExportAPI]("api")
if err != nil {
return err
}
for _, d := range data {
var proxy *api_dto.InputProxy
if d.Proxy != nil {
proxy = &api_dto.InputProxy{
Path: d.Proxy.Path,
Timeout: d.Proxy.Timeout,
Retry: d.Proxy.Retry,
Headers: d.Proxy.Headers,
Extends: d.Proxy.Extends,
Plugins: d.Proxy.Plugins,
}
}
// 判断是否存在,如果存在,则更新
_, err = i.apiModule.Detail(ctx, d.Service, d.Id)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
return err
}
_, err = i.apiModule.Create(ctx, d.Service, &api_dto.CreateApi{
Id: d.Id,
Name: d.Name,
Path: d.Path,
Method: d.Method,
Description: d.Description,
MatchRules: d.MatchRules,
Proxy: proxy,
})
if err != nil {
return fmt.Errorf("create api(%s) error: %v", d.Id, err)
}
continue
}
info := &api_dto.EditApi{
Info: api_dto.EditInfo{
Name: &d.Name,
Description: &d.Description,
},
Proxy: proxy,
//Doc: &d.Doc,
}
_, err = i.apiModule.Edit(ctx, d.Service, d.Id, info)
if err != nil {
return fmt.Errorf("update api(%s) error: %v", d.Id, err)
}
}
return nil
}
func (i *imlImportConfigController) importCatalogues(ctx context.Context) error {
data, err := unmarshal[catalogue_dto.ExportCatalogue]("catalogue")
if err != nil {
return err
}
for _, d := range data {
_, err = i.catalogueModule.Get(ctx, d.Id)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
return err
}
err = i.catalogueModule.Create(ctx, &catalogue_dto.CreateCatalogue{
Id: d.Id,
Name: d.Name,
Parent: &d.Parent,
Sort: &d.Sort,
})
if err != nil {
return fmt.Errorf("create catalogue(%s) error: %v", d.Id, err)
}
continue
}
err = i.catalogueModule.Edit(ctx, d.Id, &catalogue_dto.EditCatalogue{
Name: &d.Name,
Parent: &d.Parent,
Sort: &d.Sort,
})
if err != nil {
return fmt.Errorf("update catalogue(%s) error: %v", d.Id, err)
}
}
return nil
}
func (i *imlImportConfigController) importUpstreams(ctx context.Context) error {
data, err := unmarshal[upstream_dto.ExportUpstream]("upstream")
if err != nil {
return err
}
for _, d := range data {
_, err = i.upstreamModule.Save(ctx, d.Service, d.Upstream)
if err != nil {
return fmt.Errorf("update upstream(%s) error: %v", d.Service, err)
}
}
return nil
}
func (i *imlImportConfigController) importApplicationAuth(ctx context.Context) error {
data, err := unmarshal[application_authorization_dto.ExportAuthorization]("authorization")
if err != nil {
return err
}
for _, d := range data {
_, err := i.applicationAuthorizationModule.Info(ctx, d.Application, d.UUID)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
return err
}
_, err = i.applicationAuthorizationModule.AddAuthorization(ctx, d.Application, &application_authorization_dto.CreateAuthorization{
UUID: d.UUID,
Name: d.Name,
Driver: d.Driver,
Position: d.Position,
TokenName: d.TokenName,
ExpireTime: d.ExpireTime,
Config: d.Config,
HideCredential: d.HideCredential,
})
if err != nil {
return fmt.Errorf("create authorization(%s) error: %v", d.UUID, err)
}
continue
}
_, err = i.applicationAuthorizationModule.EditAuthorization(ctx, d.Application, d.UUID, &application_authorization_dto.EditAuthorization{
Name: &d.Name,
Position: &d.Position,
TokenName: &d.TokenName,
ExpireTime: &d.ExpireTime,
Config: &d.Config,
HideCredential: &d.HideCredential,
})
if err != nil {
return fmt.Errorf("update authorization(%s) error: %v", d.UUID, err)
}
}
return nil
}
func (i *imlImportConfigController) publish(ctx context.Context) error {
data, err := unmarshal[service_dto.ExportService]("service")
if err != nil {
return err
}
for _, d := range data {
serviceId := d.Id
newReleaseId, err := i.releaseModule.Create(ctx, serviceId, &dto2.CreateInput{
Version: "v1",
Remark: "demo release",
})
if err != nil {
continue
}
apply, err := i.publishModule.Apply(ctx, serviceId, &dto.ApplyInput{
Release: newReleaseId,
Remark: "发布申请",
})
if err != nil {
return err
}
err = i.publishModule.Accept(ctx, serviceId, apply.Id, "")
if err != nil {
i.releaseModule.Delete(ctx, serviceId, newReleaseId)
return err
}
err = i.publishModule.Publish(ctx, serviceId, apply.Id)
if err != nil {
i.releaseModule.Delete(ctx, serviceId, newReleaseId)
return err
}
err = i.publishModule.Publish(ctx, serviceId, apply.Id)
if err != nil {
i.releaseModule.Delete(ctx, serviceId, newReleaseId)
return err
}
}
return nil
}
func (i *imlImportConfigController) importSubscribers(ctx context.Context) error {
applyData, err := unmarshal[subscribe_dto.ExportApproval]("apply")
if err != nil {
return err
}
for _, d := range applyData {
err = i.catalogueModule.Subscribe(ctx, &catalogue_dto.SubscribeService{
Service: d.Service,
Applications: []string{
d.Application,
},
Reason: d.Reason,
})
if err != nil {
return fmt.Errorf("application(%s) subscribe service(%s) error: %v", d.Application, d.Service, err)
}
}
data, err := unmarshal[subscribe_dto.ExportSubscriber]("subscribe")
if err != nil {
return err
}
for _, d := range data {
err = i.subscribeModule.ExistSubscriber(ctx, d.Service, d.Subscriber)
if err == nil {
continue
}
err = i.subscribeModule.AddSubscriber(ctx, d.Service, &subscribe_dto.AddSubscriber{
Application: d.Subscriber,
})
if err != nil {
return fmt.Errorf("update subscriber(%s) error: %v", d.Id, err)
}
}
return nil
}
+25
View File
@@ -0,0 +1,25 @@
package system
import (
"github.com/eolinker/go-common/autowire"
"github.com/gin-gonic/gin"
"reflect"
)
type IExportConfigController interface {
ExportAll(ctx *gin.Context) error
}
type IImportConfigController interface {
ImportAll(ctx *gin.Context) error
}
func init() {
autowire.Auto[IExportConfigController](func() reflect.Value {
return reflect.ValueOf(new(imlExportConfigController))
})
autowire.Auto[IImportConfigController](func() reflect.Value {
return reflect.ValueOf(new(imlImportConfigController))
})
}
-2
View File
@@ -49,9 +49,7 @@ func getFileSystem(dir string) http.FileSystem {
if err != nil {
panic(err)
}
return http.FS(fDir)
}
type Frontend struct {
+4 -1
View File
@@ -9,10 +9,13 @@ import (
"io"
"net/http"
"strings"
"time"
)
var (
httpClient = &http.Client{}
httpClient = &http.Client{
Timeout: 5 * time.Second,
}
ErrorInvalidAdminAddress = errors.New("invalid address")
)
+8 -2
View File
@@ -9,6 +9,7 @@ require (
github.com/eolinker/eosc v0.17.3
github.com/eolinker/go-common v1.0.4
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
@@ -31,6 +32,8 @@ require (
github.com/ghodss/yaml v1.0.0 // indirect
github.com/gin-contrib/gzip v1.0.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.20.0 // indirect
@@ -39,17 +42,21 @@ require (
github.com/google/go-cmp v0.6.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 // indirect
github.com/invopop/yaml v0.3.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/oapi-codegen/runtime v1.0.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/redis/go-redis/v9 v9.5.3 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
@@ -65,7 +72,6 @@ require (
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gorm.io/driver/mysql v1.5.2 // indirect
)
+26 -7
View File
@@ -35,6 +35,8 @@ github.com/eolinker/go-common v1.0.4 h1:F0akjnzJfIFOVmK30fD0SsCLU7DAKPXuY21MeyMm
github.com/eolinker/go-common v1.0.4/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=
github.com/getkin/kin-openapi v0.127.0/go.mod h1:OZrfXzUfGrNbsKj+xmFBx6E5c6yH3At/tAKSc2UszXM=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gin-contrib/gzip v1.0.1 h1:HQ8ENHODeLY7a4g1Au/46Z92bdGFl74OhxcZble9WJE=
@@ -43,6 +45,10 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
@@ -53,6 +59,8 @@ github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBEx
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
@@ -66,10 +74,14 @@ github.com/influxdata/influxdb-client-go/v2 v2.14.0 h1:AjbBfJuq+QoaXNcrova8smSjw
github.com/influxdata/influxdb-client-go/v2 v2.14.0/go.mod h1:Ahpm3QXKMJslpXl3IftVLVezreAUtBOTZssDrjZEFHI=
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 h1:W9WBk7wlPfJLvMCdtV4zPulc4uCPrlywQOmbFOhgQNU=
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo=
github.com/invopop/yaml v0.3.1 h1:f0+ZpmhfBSS4MhG+4HYseMdJhoeeopbSKbq5Rpeelso=
github.com/invopop/yaml v0.3.1/go.mod h1:PMOp3nn4/12yEZUFfmOuNHJsZToEEOwoWsT+D81KkeA=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE=
@@ -77,13 +89,14 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
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/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -91,16 +104,22 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/oapi-codegen/runtime v1.0.0 h1:P4rqFX5fMFWqRzY9M/3YF9+aPSPPB06IzP2P7oOxrWo=
github.com/oapi-codegen/runtime v1.0.0/go.mod h1:LmCUMQuPB4M/nLXilQXhHw+BLZdDb18B34OO356yJ/A=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/redis/go-redis/v9 v9.5.3 h1:fOAp1/uJG+ZtcITgZOfYFmTKPE7n4Vclj1wZFgRciUU=
github.com/redis/go-redis/v9 v9.5.3/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
@@ -150,8 +169,8 @@ golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+58
View File
@@ -0,0 +1,58 @@
package api_doc
import (
"context"
"errors"
api_doc_dto "github.com/APIParkLab/APIPark/module/api-doc/dto"
api_doc "github.com/APIParkLab/APIPark/service/api-doc"
"github.com/APIParkLab/APIPark/service/service"
"github.com/eolinker/go-common/auto"
"github.com/google/uuid"
"gorm.io/gorm"
)
var _ IAPIDocModule = (*imlAPIDocModule)(nil)
type imlAPIDocModule struct {
apiDocService api_doc.IAPIDocService `autowired:""`
serviceService service.IServiceService `autowired:""`
}
func (i *imlAPIDocModule) UpdateDoc(ctx context.Context, serviceId string, input *api_doc_dto.UpdateDoc) (*api_doc_dto.ApiDocDetail, error) {
_, err := i.serviceService.Get(ctx, serviceId)
if err != nil {
return nil, err
}
if input.Id == "" {
input.Id = uuid.New().String()
}
err = i.apiDocService.UpdateDoc(ctx, serviceId, &api_doc.UpdateDoc{
ID: input.Id,
Service: serviceId,
Content: input.Content,
})
if err != nil {
return nil, err
}
return i.GetDoc(ctx, serviceId)
}
func (i *imlAPIDocModule) GetDoc(ctx context.Context, serviceId string) (*api_doc_dto.ApiDocDetail, error) {
_, err := i.serviceService.Get(ctx, serviceId)
if err != nil {
return nil, err
}
info, err := i.apiDocService.GetDoc(ctx, serviceId)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
return nil, err
}
return nil, nil
}
return &api_doc_dto.ApiDocDetail{
Content: info.Content,
Updater: info.Updater,
UpdateTime: auto.TimeLabel(info.UpdateAt),
}, nil
}
+6
View File
@@ -0,0 +1,6 @@
package api_doc_dto
type UpdateDoc struct {
Id string `json:"id"`
Content string `json:"content"`
}
+9
View File
@@ -0,0 +1,9 @@
package api_doc_dto
import "github.com/eolinker/go-common/auto"
type ApiDocDetail struct {
Content string `json:"content"`
Updater string `json:"updater"`
UpdateTime auto.TimeLabel `json:"update_time"`
}
+20
View File
@@ -0,0 +1,20 @@
package api_doc
import (
"context"
api_doc_dto "github.com/APIParkLab/APIPark/module/api-doc/dto"
"github.com/eolinker/go-common/autowire"
"reflect"
)
type IAPIDocModule interface {
UpdateDoc(ctx context.Context, serviceId string, input *api_doc_dto.UpdateDoc) (*api_doc_dto.ApiDocDetail, error)
GetDoc(ctx context.Context, serviceId string) (*api_doc_dto.ApiDocDetail, error)
}
func init() {
apiDocModule := new(imlAPIDocModule)
autowire.Auto[IAPIDocModule](func() reflect.Value {
return reflect.ValueOf(apiDocModule)
})
}
+15 -7
View File
@@ -2,10 +2,11 @@ package api
import (
"context"
"github.com/APIParkLab/APIPark/module/system"
"reflect"
"github.com/eolinker/go-common/autowire"
api_dto "github.com/APIParkLab/APIPark/module/api/dto"
)
@@ -27,16 +28,23 @@ type IApiModule interface {
Delete(ctx context.Context, serviceId string, apiId string) error
// Copy 复制API
Copy(ctx context.Context, serviceId string, apiId string, dto *api_dto.CreateApi) (*api_dto.ApiSimpleDetail, error)
// ApiDocDetail 获取API文档详情
ApiDocDetail(ctx context.Context, serviceId string, apiId string) (*api_dto.ApiDocDetail, error)
// ApiProxyDetail 获取API代理详情
ApiProxyDetail(ctx context.Context, serviceId string, apiId string) (*api_dto.ApiProxyDetail, error)
// Prefix 获取API前缀
Prefix(ctx context.Context, serviceId string) (string, error)
//ExportAll(ctx context.Context) ([]*api_dto.ExportAPI, error)
}
type IExportApiModule interface {
system.IExportModule[api_dto.ExportAPI]
}
func init() {
apiModule := new(imlApiModule)
autowire.Auto[IApiModule](func() reflect.Value {
return reflect.ValueOf(new(imlApiModule))
return reflect.ValueOf(apiModule)
})
autowire.Auto[IExportApiModule](func() reflect.Value {
return reflect.ValueOf(apiModule)
})
}
+16 -11
View File
@@ -6,7 +6,7 @@ import (
"fmt"
"github.com/eolinker/go-common/utils"
"strings"
"github.com/APIParkLab/APIPark/service/api"
)
@@ -31,8 +31,7 @@ type CreateApi struct {
}
type InputProxy struct {
Path string `json:"path"`
//Upstream string `json:"upstream" aocheck:"upstream"`
Path string `json:"path"`
Timeout int `json:"timeout"`
Retry int `json:"retry"`
Headers []*Header `json:"headers"`
@@ -78,12 +77,14 @@ func (a *CreateApi) ToServiceRouter() *api.Router {
}
type EditApi struct {
Info struct {
Name *string `json:"name"`
Description *string `json:"description"`
} `json:"info"`
Proxy *InputProxy `json:"proxy"`
Doc *map[string]interface{} `json:"doc"`
Info EditInfo `json:"info"`
Proxy *InputProxy `json:"proxy"`
//Doc *map[string]interface{} `json:"doc"`
}
type EditInfo struct {
Name *string `json:"name"`
Description *string `json:"description"`
}
func ToServiceProxy(proxy *InputProxy) *api.Proxy {
@@ -97,7 +98,7 @@ func ToServiceProxy(proxy *InputProxy) *api.Proxy {
Opt: h.Opt,
}
})
return &api.Proxy{
Path: proxy.Path,
//Upstream: proxy.Upstream,
@@ -116,7 +117,7 @@ func ToServiceDocument(doc map[string]interface{}) *api.Document {
}
}
content, _ := json.Marshal(doc)
return &api.Document{
Content: string(content),
}
@@ -125,3 +126,7 @@ func ToServiceDocument(doc map[string]interface{}) *api.Document {
type ListInput struct {
Projects []string `json:"projects"`
}
type UpdateDoc struct {
Content string `json:"content"`
}
+24 -19
View File
@@ -2,9 +2,9 @@ package api_dto
import (
"encoding/json"
"github.com/eolinker/go-common/utils"
"github.com/APIParkLab/APIPark/service/api"
"github.com/eolinker/go-common/auto"
)
@@ -12,7 +12,8 @@ import (
type ApiItem struct {
Id string `json:"id"`
Name string `json:"name"`
Method string `json:"method"`
Methods []string `json:"methods"`
Protocols []string `json:"protocols"`
Path string `json:"request_path"`
Creator auto.Label `json:"creator" aolabel:"user"`
Updater auto.Label `json:"updater" aolabel:"user"`
@@ -30,8 +31,8 @@ type ApiSimpleItem struct {
type ApiDetail struct {
ApiSimpleDetail
Proxy *Proxy `json:"proxy"`
Doc map[string]interface{} `json:"doc"`
Proxy *Proxy `json:"proxy"`
//Doc map[string]interface{} `json:"doc"`
}
func GenApiSimpleDetail(api *api.Info) *ApiSimpleDetail {
@@ -40,12 +41,12 @@ func GenApiSimpleDetail(api *api.Info) *ApiSimpleDetail {
api.Match = "[]"
}
json.Unmarshal([]byte(api.Match), &match)
return &ApiSimpleDetail{
Id: api.UUID,
Name: api.Name,
Description: api.Description,
Method: api.Method,
Methods: api.Methods,
Path: api.Path,
MatchRules: match,
Creator: auto.UUID(api.Creator),
@@ -59,8 +60,9 @@ type ApiSimpleDetail struct {
Id string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Method string `json:"method"`
Methods []string `json:"methods"`
Path string `json:"path"`
Protocols []string `json:"protocols"`
MatchRules []Match `json:"match"`
Creator auto.Label `json:"creator" aolabel:"user"`
Updater auto.Label `json:"updater" aolabel:"user"`
@@ -68,21 +70,11 @@ type ApiSimpleDetail struct {
UpdateTime auto.TimeLabel `json:"update_time"`
}
type ApiDocDetail struct {
ApiSimpleDetail
Doc map[string]interface{} `json:"doc"`
}
type ApiProxyDetail struct {
ApiSimpleDetail
Proxy *Proxy `json:"proxy"`
}
func FromServiceProxy(proxy *api.Proxy) *Proxy {
if proxy == nil {
return nil
}
return &Proxy{
Path: proxy.Path,
Timeout: proxy.Timeout,
@@ -113,3 +105,16 @@ type Header struct {
Value string `json:"value"`
Opt string `json:"opt"`
}
type ExportAPI struct {
Id string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Method string `json:"method"`
Path string `json:"path"`
MatchRules []Match `json:"match"`
Service string `json:"service"`
Team string `json:"team"`
Proxy *Proxy `json:"proxy"`
Doc map[string]interface{} `json:"doc"`
}
+82 -157
View File
@@ -5,28 +5,32 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/APIParkLab/APIPark/service/universally/commit"
"strings"
"github.com/APIParkLab/APIPark/service/service"
"github.com/APIParkLab/APIPark/service/upstream"
"gorm.io/gorm"
"github.com/APIParkLab/APIPark/service/team"
"github.com/google/uuid"
"github.com/eolinker/go-common/auto"
"github.com/eolinker/go-common/utils"
"github.com/eolinker/go-common/store"
"github.com/APIParkLab/APIPark/service/api"
api_dto "github.com/APIParkLab/APIPark/module/api/dto"
)
var _ IApiModule = (*imlApiModule)(nil)
var (
_ IApiModule = (*imlApiModule)(nil)
_ IExportApiModule = (*imlApiModule)(nil)
)
var (
asServer = map[string]bool{
"as_server": true,
@@ -41,8 +45,48 @@ type imlApiModule struct {
transaction store.ITransaction `autowired:""`
}
func (i *imlApiModule) ExportAll(ctx context.Context) ([]*api_dto.ExportAPI, error) {
apiList, err := i.apiService.ListInfo(ctx)
if err != nil {
return nil, err
}
apiIds := utils.SliceToSlice(apiList, func(a *api.Info) string {
return a.UUID
})
proxyCommits, err := i.apiService.ListLatestCommitProxy(ctx, apiIds...)
if err != nil {
return nil, err
}
proxyCommitMap := utils.SliceToMap(proxyCommits, func(c *commit.Commit[api.Proxy]) string {
return c.Target
})
return utils.SliceToSlice(apiList, func(a *api.Info) *api_dto.ExportAPI {
match := make([]api_dto.Match, 0)
if a.Match == "" {
a.Match = "[]"
}
json.Unmarshal([]byte(a.Match), &match)
info := &api_dto.ExportAPI{
Id: a.UUID,
Name: a.Name,
Description: a.Description,
Path: a.Path,
MatchRules: match,
Service: a.Service,
Team: a.Team,
}
if v, ok := proxyCommitMap[a.UUID]; ok {
info.Proxy = api_dto.FromServiceProxy(v.Data)
}
return info
}), nil
}
func (i *imlApiModule) SimpleList(ctx context.Context, serviceId string) ([]*api_dto.ApiSimpleItem, error) {
list, err := i.apiService.ListForService(ctx, serviceId)
apiInfos, err := i.apiService.ListInfo(ctx, utils.SliceToSlice(list, func(s *api.API) string {
return s.UUID
@@ -50,13 +94,12 @@ func (i *imlApiModule) SimpleList(ctx context.Context, serviceId string) ([]*api
if err != nil {
return nil, err
}
out := utils.SliceToSlice(apiInfos, func(item *api.Info) *api_dto.ApiSimpleItem {
return &api_dto.ApiSimpleItem{
Id: item.UUID,
Name: item.Name,
Method: item.Method,
Path: item.Path,
Id: item.UUID,
Name: item.Name,
Path: item.Path,
}
})
return out, nil
@@ -67,12 +110,12 @@ func (i *imlApiModule) Detail(ctx context.Context, serviceId string, apiId strin
if err != nil {
return nil, err
}
detail, err := i.apiService.GetInfo(ctx, apiId)
if err != nil {
return nil, err
}
apiDetail := &api_dto.ApiDetail{
ApiSimpleDetail: *api_dto.GenApiSimpleDetail(detail),
}
@@ -83,25 +126,9 @@ func (i *imlApiModule) Detail(ctx context.Context, serviceId string, apiId strin
}
}
if proxy != nil {
apiDetail.Proxy = api_dto.FromServiceProxy(proxy.Data)
}
document, err := i.apiService.LatestDocument(ctx, apiId)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
return nil, err
}
}
if document != nil {
doc := make(map[string]interface{})
err = json.Unmarshal([]byte(document.Data.Content), &doc)
if err != nil {
return nil, err
}
apiDetail.Doc = doc
}
return apiDetail, nil
}
@@ -110,12 +137,12 @@ func (i *imlApiModule) SimpleDetail(ctx context.Context, serviceId string, apiId
if err != nil {
return nil, err
}
detail, err := i.apiService.GetInfo(ctx, apiId)
if err != nil {
return nil, err
}
return api_dto.GenApiSimpleDetail(detail), nil
}
@@ -124,7 +151,7 @@ func (i *imlApiModule) Search(ctx context.Context, keyword string, serviceId str
if err != nil {
return nil, err
}
list, err := i.apiService.Search(ctx, keyword, map[string]interface{}{
"service": serviceId,
})
@@ -144,7 +171,8 @@ func (i *imlApiModule) Search(ctx context.Context, keyword string, serviceId str
return &api_dto.ApiItem{
Id: item.UUID,
Name: item.Name,
Method: item.Method,
Methods: item.Methods,
Protocols: item.Protocols,
Path: item.Path,
Creator: auto.UUID(item.Creator),
Updater: auto.UUID(item.Updater),
@@ -153,7 +181,7 @@ func (i *imlApiModule) Search(ctx context.Context, keyword string, serviceId str
CanDelete: true,
}
})
return out, nil
}
@@ -162,7 +190,7 @@ func (i *imlApiModule) SimpleSearch(ctx context.Context, keyword string, service
if err != nil {
return nil, err
}
list, err := i.apiService.Search(ctx, keyword, map[string]interface{}{
"service": serviceId,
})
@@ -177,10 +205,10 @@ func (i *imlApiModule) SimpleSearch(ctx context.Context, keyword string, service
}
out := utils.SliceToSlice(apiInfos, func(item *api.Info) *api_dto.ApiSimpleItem {
return &api_dto.ApiSimpleItem{
Id: item.UUID,
Name: item.Name,
Method: item.Method,
Path: item.Path,
Id: item.UUID,
Name: item.Name,
//Methods: item.Methods,
Path: item.Path,
}
})
return out, nil
@@ -203,7 +231,7 @@ func (i *imlApiModule) Create(ctx context.Context, serviceId string, dto *api_dt
if err != nil {
return err
}
path := fmt.Sprintf("%s%s", prefix, dto.Path)
err = i.apiService.Exist(ctx, "", &api.ExistAPI{Path: dto.Path, Method: dto.Method})
if err != nil {
@@ -214,11 +242,7 @@ func (i *imlApiModule) Create(ctx context.Context, serviceId string, dto *api_dt
if err != nil {
return err
}
err = i.apiService.SaveDocument(ctx, dto.Id, api_dto.ToServiceDocument(nil))
if err != nil {
return err
}
match, _ := json.Marshal(dto.MatchRules)
return i.apiService.Create(ctx, &api.CreateAPI{
UUID: dto.Id,
@@ -229,7 +253,6 @@ func (i *imlApiModule) Create(ctx context.Context, serviceId string, dto *api_dt
Method: dto.Method,
Path: path,
Match: string(match),
//Upstream: proxy.Upstream,
})
})
if err != nil {
@@ -243,7 +266,7 @@ func (i *imlApiModule) Edit(ctx context.Context, serviceId string, apiId string,
if err != nil {
return nil, err
}
err = i.transaction.Transaction(ctx, func(ctx context.Context) error {
var up *string
if dto.Proxy != nil {
@@ -251,9 +274,6 @@ func (i *imlApiModule) Edit(ctx context.Context, serviceId string, apiId string,
if err != nil {
return err
}
//if dto.Proxy.Upstream != "" {
// up = &dto.Proxy.Upstream
//}
}
err = i.apiService.Save(ctx, apiId, &api.EditAPI{
Name: dto.Info.Name,
@@ -263,15 +283,9 @@ func (i *imlApiModule) Edit(ctx context.Context, serviceId string, apiId string,
if err != nil {
return err
}
if dto.Doc != nil {
err = i.apiService.SaveDocument(ctx, apiId, api_dto.ToServiceDocument(*dto.Doc))
if err != nil {
return err
}
}
return nil
})
if err != nil {
return nil, err
@@ -308,13 +322,13 @@ func (i *imlApiModule) Copy(ctx context.Context, serviceId string, apiId string,
if err != nil {
return err
}
path := fmt.Sprintf("%s/%s", strings.TrimSuffix(prefix, "/"), strings.TrimPrefix(dto.Path, "/"))
err = i.apiService.Exist(ctx, serviceId, &api.ExistAPI{Path: path, Method: dto.Method})
if err != nil {
return err
}
proxy, err := i.apiService.LatestProxy(ctx, oldApi.UUID)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
@@ -327,21 +341,8 @@ func (i *imlApiModule) Copy(ctx context.Context, serviceId string, apiId string,
if err != nil {
return err
}
//upstreamId = proxy.Data.Upstream
}
doc, err := i.apiService.LatestDocument(ctx, oldApi.UUID)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
return err
}
}
if doc != nil {
err = i.apiService.SaveDocument(ctx, dto.Id, doc.Data)
if err != nil {
return err
}
}
match, _ := json.Marshal(dto.MatchRules)
return i.apiService.Create(ctx, &api.CreateAPI{
UUID: dto.Id,
@@ -351,9 +352,8 @@ func (i *imlApiModule) Copy(ctx context.Context, serviceId string, apiId string,
Method: dto.Method,
Path: path,
Match: string(match),
//Upstream: upstreamId,
})
})
if err != nil {
return nil, err
@@ -361,87 +361,12 @@ func (i *imlApiModule) Copy(ctx context.Context, serviceId string, apiId string,
return i.SimpleDetail(ctx, serviceId, dto.Id)
}
func (i *imlApiModule) ApiDocDetail(ctx context.Context, serviceId string, apiId string) (*api_dto.ApiDocDetail, error) {
_, err := i.serviceService.Check(ctx, serviceId, asServer)
if err != nil {
return nil, err
}
apiBase, err := i.apiService.Get(ctx, apiId)
if err != nil {
return nil, err
}
if apiBase.IsDelete {
return nil, errors.New("api is delete")
}
detail, err := i.apiService.GetInfo(ctx, apiBase.UUID)
if err != nil {
return nil, err
}
document, err := i.apiService.LatestDocument(ctx, apiId)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
return nil, err
}
}
var doc map[string]interface{}
if document != nil {
doc = make(map[string]interface{})
err = json.Unmarshal([]byte(document.Data.Content), &doc)
if err != nil {
return nil, err
}
}
return &api_dto.ApiDocDetail{
ApiSimpleDetail: *api_dto.GenApiSimpleDetail(detail),
Doc: doc,
}, nil
}
func (i *imlApiModule) ApiProxyDetail(ctx context.Context, serviceId string, apiId string) (*api_dto.ApiProxyDetail, error) {
_, err := i.serviceService.Check(ctx, serviceId, asServer)
if err != nil {
return nil, err
}
apiBase, err := i.apiService.Get(ctx, apiId)
if err != nil {
return nil, err
}
if apiBase.IsDelete {
return nil, errors.New("api is delete")
}
if apiBase.Service != serviceId {
return nil, errors.New("api is not in project")
}
detail, err := i.apiService.GetInfo(ctx, apiId)
if err != nil {
return nil, err
}
apiDetail := &api_dto.ApiProxyDetail{
ApiSimpleDetail: *api_dto.GenApiSimpleDetail(detail),
}
proxy, err := i.apiService.LatestProxy(ctx, apiId)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
return nil, err
}
}
if proxy != nil {
apiDetail.Proxy = api_dto.FromServiceProxy(proxy.Data)
}
return apiDetail, nil
}
func (i *imlApiModule) Prefix(ctx context.Context, serviceId string) (string, error) {
pInfo, err := i.serviceService.Check(ctx, serviceId, asServer)
if err != nil {
return "", err
}
if pInfo.Prefix != "" {
if pInfo.Prefix[0] != '/' {
pInfo.Prefix = fmt.Sprintf("/%s", strings.TrimSuffix(pInfo.Prefix, "/"))
@@ -2,14 +2,15 @@ package application_authorization
import (
"context"
"github.com/APIParkLab/APIPark/module/system"
"reflect"
application_authorization_dto "github.com/APIParkLab/APIPark/module/application-authorization/dto"
"github.com/APIParkLab/APIPark/gateway"
"github.com/eolinker/go-common/autowire"
_ "github.com/APIParkLab/APIPark/module/application-authorization/auth-driver/aksk"
_ "github.com/APIParkLab/APIPark/module/application-authorization/auth-driver/apikey"
_ "github.com/APIParkLab/APIPark/module/application-authorization/auth-driver/basic"
@@ -30,12 +31,21 @@ type IAuthorizationModule interface {
Detail(ctx context.Context, appId string, aid string) ([]application_authorization_dto.DetailItem, error)
// Info 获取项目鉴权详情
Info(ctx context.Context, appId string, aid string) (*application_authorization_dto.Authorization, error)
//ExportAll(ctx context.Context) ([]*application_authorization_dto.ExportAuthorization, error)
}
type IExportAuthorizationModule interface {
system.IExportModule[application_authorization_dto.ExportAuthorization]
}
func init() {
authModule := new(imlAuthorizationModule)
autowire.Auto[IAuthorizationModule](func() reflect.Value {
m := new(imlAuthorizationModule)
gateway.RegisterInitHandleFunc(m.initGateway)
return reflect.ValueOf(m)
gateway.RegisterInitHandleFunc(authModule.initGateway)
return reflect.ValueOf(authModule)
})
autowire.Auto[IExportAuthorizationModule](func() reflect.Value {
return reflect.ValueOf(authModule)
})
}
@@ -31,3 +31,15 @@ type DetailItem struct {
Key string `json:"key"`
Value string `json:"value"`
}
type ExportAuthorization struct {
Application string `json:"application"`
UUID string `json:"id"`
Name string `json:"name"`
Driver string `json:"driver"`
Position string `json:"position"`
TokenName string `json:"token_name"`
Config map[string]interface{} `json:"config"`
ExpireTime int64 `json:"expire_time"`
HideCredential bool `json:"hide_credential"`
}
+54 -28
View File
@@ -6,30 +6,33 @@ import (
"errors"
"fmt"
"time"
application_authorization "github.com/APIParkLab/APIPark/service/application-authorization"
"github.com/eolinker/eosc/log"
authDriver "github.com/APIParkLab/APIPark/module/application-authorization/auth-driver"
"github.com/eolinker/go-common/utils"
"github.com/APIParkLab/APIPark/gateway"
"github.com/APIParkLab/APIPark/service/cluster"
"github.com/APIParkLab/APIPark/service/service"
"github.com/eolinker/go-common/auto"
"github.com/google/uuid"
"github.com/eolinker/go-common/store"
application_authorization_dto "github.com/APIParkLab/APIPark/module/application-authorization/dto"
)
var _ IAuthorizationModule = (*imlAuthorizationModule)(nil)
var (
_ IAuthorizationModule = (*imlAuthorizationModule)(nil)
_ IExportAuthorizationModule = (*imlAuthorizationModule)(nil)
)
type imlAuthorizationModule struct {
serviceService service.IServiceService `autowired:""`
@@ -38,6 +41,29 @@ type imlAuthorizationModule struct {
transaction store.ITransaction `autowired:""`
}
func (i *imlAuthorizationModule) ExportAll(ctx context.Context) ([]*application_authorization_dto.ExportAuthorization, error) {
list, err := i.authorizationService.List(ctx)
if err != nil {
return nil, err
}
return utils.SliceToSlice(list, func(a *application_authorization.Authorization) *application_authorization_dto.ExportAuthorization {
cfg := make(map[string]interface{})
json.Unmarshal([]byte(a.Config), &cfg)
return &application_authorization_dto.ExportAuthorization{
Application: a.Application,
UUID: a.UUID,
Name: a.Name,
Driver: a.Type,
Position: a.Position,
TokenName: a.TokenName,
Config: cfg,
ExpireTime: a.ExpireTime,
HideCredential: a.HideCredential,
}
}), nil
}
func (i *imlAuthorizationModule) getApplications(ctx context.Context, appIds []string, appMap map[string]*service.Service) ([]*gateway.ApplicationRelease, error) {
authorizations, err := i.authorizationService.ListByApp(ctx, appIds...)
if err != nil {
@@ -62,7 +88,7 @@ func (i *imlAuthorizationModule) getApplications(ctx context.Context, appIds []s
"service": id,
},
},
Authorizations: utils.SliceToSlice(auths, func(a *application_authorization.Authorization) *gateway.Authorization {
authCfg := make(map[string]interface{})
_ = json.Unmarshal([]byte(a.Config), &authCfg)
@@ -90,7 +116,7 @@ func (i *imlAuthorizationModule) initGateway(ctx context.Context, partitionId st
serviceIds = append(serviceIds, p.Id)
serviceMap[p.Id] = p
}
applications, err := i.getApplications(ctx, serviceIds, serviceMap)
if err != nil {
return err
@@ -99,7 +125,7 @@ func (i *imlAuthorizationModule) initGateway(ctx context.Context, partitionId st
}
func (i *imlAuthorizationModule) online(ctx context.Context, s *service.Service) error {
clusters, err := i.clusterService.List(ctx)
if err != nil {
return err
@@ -130,7 +156,7 @@ func (i *imlAuthorizationModule) online(ctx context.Context, s *service.Service)
}
}),
}
for _, c := range clusters {
err := i.doOnline(ctx, c.Uuid, app)
if err != nil {
@@ -148,7 +174,7 @@ func (i *imlAuthorizationModule) doOnline(ctx context.Context, clusterId string,
_ = client.Close(ctx)
}()
return client.Application().Online(ctx, app)
}
func (i *imlAuthorizationModule) AddAuthorization(ctx context.Context, appId string, info *application_authorization_dto.CreateAuthorization) (*application_authorization_dto.Authorization, error) {
authFactory, has := authDriver.GetAuthFactory(info.Driver)
@@ -163,16 +189,16 @@ func (i *imlAuthorizationModule) AddAuthorization(ctx context.Context, appId str
if err != nil {
return nil, err
}
s, err := i.serviceService.Get(ctx, appId)
if err != nil {
return nil, err
}
if info.UUID == "" {
info.UUID = uuid.New().String()
}
// 缺少配置查重操作
err = i.transaction.Transaction(ctx, func(ctx context.Context) error {
err = i.authorizationService.Create(ctx, &application_authorization.Create{
@@ -190,13 +216,13 @@ func (i *imlAuthorizationModule) AddAuthorization(ctx context.Context, appId str
if err != nil {
return err
}
return i.online(ctx, s)
})
if err != nil {
return nil, err
}
return i.Info(ctx, appId, info.UUID)
}
@@ -217,12 +243,12 @@ func (i *imlAuthorizationModule) EditAuthorization(ctx context.Context, appId st
if err != nil {
return nil, err
}
appInfo, err := i.serviceService.Get(ctx, appId)
if err != nil {
return nil, err
}
err = i.transaction.Transaction(ctx, func(ctx context.Context) error {
authId := auth.GenerateID(authInfo.Position, authInfo.TokenName)
cfgStr := string(cfg)
@@ -240,7 +266,7 @@ func (i *imlAuthorizationModule) EditAuthorization(ctx context.Context, appId st
}
return i.online(ctx, appInfo)
})
if err != nil {
return nil, err
}
@@ -252,7 +278,7 @@ func (i *imlAuthorizationModule) DeleteAuthorization(ctx context.Context, pid st
if err != nil {
return err
}
return i.transaction.Transaction(ctx, func(ctx context.Context) error {
err = i.authorizationService.Delete(ctx, aid)
if err != nil {
@@ -285,7 +311,7 @@ func (i *imlAuthorizationModule) doOffline(ctx context.Context, clusterId string
_ = client.Close(ctx)
}()
return client.Application().Offline(ctx, app)
}
func (i *imlAuthorizationModule) Authorizations(ctx context.Context, pid string) ([]*application_authorization_dto.AuthorizationItem, error) {
_, err := i.serviceService.Get(ctx, pid)
@@ -349,7 +375,7 @@ func (i *imlAuthorizationModule) Detail(ctx context.Context, pid string, aid str
hideAuthStr = "否"
}
details = append(details, application_authorization_dto.DetailItem{Key: "隐藏鉴权信息", Value: hideAuthStr})
return details, nil
}
@@ -366,7 +392,7 @@ func (i *imlAuthorizationModule) Info(ctx context.Context, pid string, aid strin
if auth.Config != "" {
_ = json.Unmarshal([]byte(auth.Config), &cfg)
}
return &application_authorization_dto.Authorization{
UUID: auth.UUID,
Name: auth.Name,
+16 -3
View File
@@ -2,10 +2,11 @@ package catalogue
import (
"context"
"github.com/APIParkLab/APIPark/module/system"
"reflect"
"github.com/eolinker/go-common/autowire"
catalogue_dto "github.com/APIParkLab/APIPark/module/catalogue/dto"
)
@@ -16,6 +17,8 @@ type ICatalogueModule interface {
Create(ctx context.Context, input *catalogue_dto.CreateCatalogue) error
// Edit 编辑目录
Edit(ctx context.Context, id string, input *catalogue_dto.EditCatalogue) error
Get(ctx context.Context, id string) (*catalogue_dto.Catalogue, error)
// Delete 删除目录
Delete(ctx context.Context, id string) error
// Services 关键字筛选服务列表
@@ -25,10 +28,20 @@ type ICatalogueModule interface {
// Subscribe 订阅服务
Subscribe(ctx context.Context, subscribeInfo *catalogue_dto.SubscribeService) error
Sort(ctx context.Context, sorts []*catalogue_dto.SortItem) error
//ExportAll(ctx context.Context) ([]*catalogue_dto.ExportCatalogue, error)
}
type IExportCatalogueModule interface {
system.IExportModule[catalogue_dto.ExportCatalogue]
}
func init() {
catalogueModule := new(imlCatalogueModule)
autowire.Auto[ICatalogueModule](func() reflect.Value {
return reflect.ValueOf(new(imlCatalogueModule))
return reflect.ValueOf(catalogueModule)
})
autowire.Auto[IExportCatalogueModule](func() reflect.Value {
return reflect.ValueOf(catalogueModule)
})
}
+2
View File
@@ -4,11 +4,13 @@ type CreateCatalogue struct {
Id string `json:"id"`
Name string `json:"name"`
Parent *string `json:"parent" aocheck:"catalogue"`
Sort *int `json:"sort"`
}
type EditCatalogue struct {
Name *string `json:"name"`
Parent *string `json:"parent" aocheck:"catalogue"`
Sort *int `json:"sort"`
}
type SubscribeService struct {
+14
View File
@@ -61,3 +61,17 @@ type Partition struct {
Name string `json:"name"`
Prefix string `json:"prefix"`
}
type Catalogue struct {
Id string `json:"id"`
Name string `json:"name"`
Parent string `json:"parent"`
Sort int `json:"sort"`
}
type ExportCatalogue struct {
Id string `json:"id"`
Name string `json:"name"`
Parent string `json:"parent"`
Sort int `json:"sort"`
}
+95 -61
View File
@@ -2,37 +2,36 @@ package catalogue
import (
"context"
"encoding/json"
"errors"
"fmt"
"math"
"sort"
service_doc "github.com/APIParkLab/APIPark/service/service-doc"
service_tag "github.com/APIParkLab/APIPark/service/service-tag"
"github.com/APIParkLab/APIPark/service/subscribe"
"github.com/eolinker/go-common/store"
"gorm.io/gorm"
"github.com/eolinker/go-common/utils"
"github.com/APIParkLab/APIPark/service/release"
"github.com/APIParkLab/APIPark/service/api"
"github.com/eolinker/go-common/auto"
"github.com/APIParkLab/APIPark/service/tag"
"github.com/APIParkLab/APIPark/service/service"
"github.com/google/uuid"
"github.com/APIParkLab/APIPark/service/catalogue"
catalogue_dto "github.com/APIParkLab/APIPark/module/catalogue/dto"
)
@@ -52,10 +51,39 @@ type imlCatalogueModule struct {
subscribeService subscribe.ISubscribeService `autowired:""`
subscribeApplyService subscribe.ISubscribeApplyService `autowired:""`
transaction store.ITransaction `autowired:""`
root *Root
}
func (i *imlCatalogueModule) Get(ctx context.Context, id string) (*catalogue_dto.Catalogue, error) {
info, err := i.catalogueService.Get(ctx, id)
if err != nil {
return nil, err
}
return &catalogue_dto.Catalogue{
Id: info.Id,
Name: info.Name,
Parent: info.Parent,
Sort: info.Sort,
}, nil
}
func (i *imlCatalogueModule) ExportAll(ctx context.Context) ([]*catalogue_dto.ExportCatalogue, error) {
list, err := i.catalogueService.List(ctx)
if err != nil {
return nil, err
}
return utils.SliceToSlice(list, func(c *catalogue.Catalogue) *catalogue_dto.ExportCatalogue {
return &catalogue_dto.ExportCatalogue{
Id: c.Id,
Name: c.Name,
Parent: c.Parent,
Sort: c.Sort,
}
}), nil
}
func (i *imlCatalogueModule) Subscribe(ctx context.Context, subscribeInfo *catalogue_dto.SubscribeService) error {
if len(subscribeInfo.Applications) == 0 {
return fmt.Errorf("applications is empty")
@@ -68,18 +96,18 @@ func (i *imlCatalogueModule) Subscribe(ctx context.Context, subscribeInfo *catal
if !s.AsServer {
return fmt.Errorf("service does not support subscribe")
}
userId := utils.UserId(ctx)
return i.transaction.Transaction(ctx, func(ctx context.Context) error {
apps := make([]string, 0, len(subscribeInfo.Applications))
for _, appId := range subscribeInfo.Applications {
if appId == s.Id {
// 不能订阅自己
continue
}
appInfo, err := i.serviceService.Get(ctx, appId)
if err != nil {
return err
@@ -103,7 +131,7 @@ func (i *imlCatalogueModule) Subscribe(ctx context.Context, subscribeInfo *catal
Status: subscribe.ApplyStatusReview,
Applier: userId,
})
//} else {
// status := subscribe.ApplyStatusReview
// err = i.subscribeApplyService.Save(ctx, info.Id, &subscribe.EditApply{
@@ -114,7 +142,7 @@ func (i *imlCatalogueModule) Subscribe(ctx context.Context, subscribeInfo *catal
if err != nil {
return err
}
// 修改订阅表状态
subscribers, err := i.subscribeService.ListByApplication(ctx, subscribeInfo.Service, appId)
if err != nil {
@@ -131,7 +159,7 @@ func (i *imlCatalogueModule) Subscribe(ctx context.Context, subscribeInfo *catal
if err != nil {
return err
}
} else {
subscriberMap := utils.SliceToMap(subscribers, func(t *subscribe.Subscribe) string {
return t.Application
@@ -154,9 +182,9 @@ func (i *imlCatalogueModule) Subscribe(ctx context.Context, subscribeInfo *catal
ApplyStatus: &status,
})
}
}
apps = append(apps, appId)
}
if len(apps) == 0 {
@@ -164,7 +192,7 @@ func (i *imlCatalogueModule) Subscribe(ctx context.Context, subscribeInfo *catal
}
return nil
})
}
func (i *imlCatalogueModule) ServiceDetail(ctx context.Context, sid string) (*catalogue_dto.ServiceDetail, error) {
@@ -182,7 +210,7 @@ func (i *imlCatalogueModule) ServiceDetail(ctx context.Context, sid string) (*ca
} else {
docStr = doc.Doc
}
r, err := i.releaseService.GetRunning(ctx, s.Id)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
@@ -196,7 +224,7 @@ func (i *imlCatalogueModule) ServiceDetail(ctx context.Context, sid string) (*ca
},
}, nil
}
return nil, fmt.Errorf("get running release failed: %w", err)
}
_, docCommits, _, err := i.releaseService.GetReleaseInfos(ctx, r.UUID)
@@ -213,39 +241,40 @@ func (i *imlCatalogueModule) ServiceDetail(ctx context.Context, sid string) (*ca
if err != nil {
return nil, err
}
apis := make([]*catalogue_dto.ServiceApi, 0, len(apiList))
// TODO:此处载入API文档
for _, info := range apiList {
basicApi := &catalogue_dto.ServiceApiBasic{
Id: info.UUID,
Name: info.Name,
Description: info.Description,
Method: info.Method,
Path: info.Path,
Creator: auto.UUID(info.Creator),
Updater: auto.UUID(info.Updater),
CreateTime: auto.TimeLabel(info.CreateAt),
UpdateTime: auto.TimeLabel(info.UpdateAt),
//Methods: info.Methods,
Path: info.Path,
Creator: auto.UUID(info.Creator),
Updater: auto.UUID(info.Updater),
CreateTime: auto.TimeLabel(info.CreateAt),
UpdateTime: auto.TimeLabel(info.UpdateAt),
}
v, ok := apiMap[info.UUID]
if !ok {
continue
}
commit, err := i.apiService.GetDocumentCommit(ctx, v.Commit)
if err != nil {
return nil, err
}
tmp := make(map[string]interface{})
if commit.Data != nil {
err = json.Unmarshal([]byte(commit.Data.Content), &tmp)
if err != nil {
return nil, err
}
}
//v, ok := apiMap[info.UUID]
//if !ok {
// continue
//}
//commit, err := i.apiService.GetDocumentCommit(ctx, v.Commit)
//if err != nil {
// return nil, err
//}
//tmp := make(map[string]interface{})
//if commit.Data != nil {
// err = json.Unmarshal([]byte(commit.Data.Content), &tmp)
// if err != nil {
// return nil, err
// }
//}
apis = append(apis, &catalogue_dto.ServiceApi{
ServiceApiBasic: basicApi,
Doc: tmp,
//Doc: tmp,
})
}
countMap, err := i.subscribeService.CountMapByService(ctx, subscribe.ApplyStatusSubscribe, sid)
@@ -280,7 +309,7 @@ func (i *imlCatalogueModule) ServiceDetail(ctx context.Context, sid string) (*ca
}
func (i *imlCatalogueModule) Services(ctx context.Context, keyword string) ([]*catalogue_dto.ServiceItem, error) {
serviceTags, err := i.serviceTagService.List(ctx, nil, nil)
if err != nil {
return nil, err
@@ -288,7 +317,7 @@ func (i *imlCatalogueModule) Services(ctx context.Context, keyword string) ([]*c
serviceTagMap := utils.SliceToMapArrayO(serviceTags, func(t *service_tag.Tag) (string, string) {
return t.Sid, t.Tid
})
items, err := i.serviceService.SearchPublicServices(ctx, keyword)
if err != nil {
return nil, err
@@ -303,25 +332,25 @@ func (i *imlCatalogueModule) Services(ctx context.Context, keyword string) ([]*c
if len(serviceIds) < 1 {
return nil, nil
}
// 获取服务API数量
apiCountMap, err := i.apiService.CountMapByService(ctx, serviceIds...)
if err != nil {
return nil, err
}
subscriberCountMap, err := i.subscribeService.CountMapByService(ctx, subscribe.ApplyStatusSubscribe, serviceIds...)
if err != nil {
return nil, err
}
result := make([]*catalogue_dto.ServiceItem, 0, len(items))
for _, v := range items {
apiNum, ok := apiCountMap[v.Id]
if !ok || apiNum < 1 {
continue
}
result = append(result, &catalogue_dto.ServiceItem{
Id: v.Id,
Name: v.Name,
@@ -376,7 +405,7 @@ func (i *imlCatalogueModule) Sort(ctx context.Context, sorts []*catalogue_dto.So
i.root = NewRoot(all)
return nil
})
}
func (i *imlCatalogueModule) Search(ctx context.Context, keyword string) ([]*catalogue_dto.Item, error) {
@@ -396,7 +425,7 @@ func (i *imlCatalogueModule) Search(ctx context.Context, keyword string) ([]*cat
}
return treeItems("", parentMap), nil
}
catalogues, err := i.catalogueService.Search(ctx, keyword, nil)
if err != nil {
return nil, err
@@ -406,7 +435,7 @@ func (i *imlCatalogueModule) Search(ctx context.Context, keyword string) ([]*cat
i.root = NewRoot(all)
}
items := make([]*catalogue_dto.Item, 0, len(catalogues))
return items, nil
}
@@ -418,11 +447,15 @@ func (i *imlCatalogueModule) Create(ctx context.Context, input *catalogue_dto.Cr
if input.Id == "" {
input.Id = uuid.New().String()
}
index := _sortMax
if input.Sort != nil {
index = *input.Sort
}
err := i.catalogueService.Create(ctx, &catalogue.CreateCatalogue{
Id: input.Id,
Name: input.Name,
Parent: parent,
Sort: _sortMax,
Sort: index,
})
if err != nil {
return err
@@ -440,6 +473,7 @@ func (i *imlCatalogueModule) Edit(ctx context.Context, id string, input *catalog
err := i.catalogueService.Save(ctx, id, &catalogue.EditCatalogue{
Name: input.Name,
Parent: input.Parent,
Sort: input.Sort,
})
if err != nil {
return err
+40 -40
View File
@@ -5,20 +5,20 @@ import (
"errors"
"fmt"
"time"
"github.com/eolinker/go-common/store"
"github.com/APIParkLab/APIPark/service/service"
"github.com/APIParkLab/APIPark/service/universally/commit"
"github.com/APIParkLab/APIPark/service/api"
"github.com/APIParkLab/APIPark/service/upstream"
"github.com/APIParkLab/APIPark/gateway"
"github.com/eolinker/eosc/log"
"github.com/APIParkLab/APIPark/module/publish/dto"
releaseModule "github.com/APIParkLab/APIPark/module/release"
serviceDiff "github.com/APIParkLab/APIPark/module/service-diff"
@@ -50,7 +50,7 @@ type imlPublishModule struct {
}
func (m *imlPublishModule) initGateway(ctx context.Context, partitionId string, clientDriver gateway.IClientDriver) error {
projects, err := m.serviceService.List(ctx)
if err != nil {
return err
@@ -66,7 +66,7 @@ func (m *imlPublishModule) initGateway(ctx context.Context, partitionId string,
if releaseInfo == nil {
continue
}
err = clientDriver.Project().Online(ctx, releaseInfo)
if err != nil {
return err
@@ -76,7 +76,7 @@ func (m *imlPublishModule) initGateway(ctx context.Context, partitionId string,
}
func (m *imlPublishModule) getProjectRelease(ctx context.Context, projectID string, partitionId string) (*gateway.ProjectRelease, error) {
releaseInfo, err := m.releaseService.GetRunning(ctx, projectID)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
@@ -100,12 +100,12 @@ func (m *imlPublishModule) getProjectRelease(ctx context.Context, projectID stri
upstreamCommitIds = append(upstreamCommitIds, c.Commit)
}
}
apiInfos, err := m.apiService.ListInfo(ctx, apiIds...)
if err != nil {
return nil, err
}
proxyCommits, err := m.apiService.ListProxyCommit(ctx, apiProxyCommitIds...)
if err != nil {
return nil, err
@@ -113,7 +113,7 @@ func (m *imlPublishModule) getProjectRelease(ctx context.Context, projectID stri
proxyCommitMap := utils.SliceToMapO(proxyCommits, func(c *commit.Commit[api.Proxy]) (string, *api.Proxy) {
return c.Target, c.Data
})
upstreamCommits, err := m.upstreamService.ListCommit(ctx, upstreamCommitIds...)
if err != nil {
return nil, err
@@ -128,8 +128,8 @@ func (m *imlPublishModule) getProjectRelease(ctx context.Context, projectID stri
Version: version,
},
Path: a.Path,
Method: []string{a.Method},
Service: a.Upstream,
Method: a.Methods,
Service: a.Service,
}
proxy, ok := proxyCommitMap[a.UUID]
if ok {
@@ -167,7 +167,7 @@ func (m *imlPublishModule) getProjectRelease(ctx context.Context, projectID stri
}),
}
}
return &gateway.ProjectRelease{
Id: projectID,
Version: version,
@@ -193,12 +193,12 @@ func (m *imlPublishModule) getReleaseInfo(ctx context.Context, projectID, releas
upstreamCommitIds = append(upstreamCommitIds, c.Commit)
}
}
apiInfos, err := m.apiService.ListInfo(ctx, apiIds...)
if err != nil {
return nil, err
}
proxyCommits, err := m.apiService.ListProxyCommit(ctx, apiProxyCommitIds...)
if err != nil {
return nil, err
@@ -206,7 +206,7 @@ func (m *imlPublishModule) getReleaseInfo(ctx context.Context, projectID, releas
proxyCommitMap := utils.SliceToMapO(proxyCommits, func(c *commit.Commit[api.Proxy]) (string, *api.Proxy) {
return c.Target, c.Data
})
upstreamCommits, err := m.upstreamService.ListCommit(ctx, upstreamCommitIds...)
if err != nil {
return nil, err
@@ -220,8 +220,8 @@ func (m *imlPublishModule) getReleaseInfo(ctx context.Context, projectID, releas
Version: version,
},
Path: a.Path,
Method: []string{a.Method},
Service: a.Upstream,
Method: a.Methods,
Service: a.Service,
}
proxy, ok := proxyCommitMap[a.UUID]
if ok {
@@ -246,7 +246,7 @@ func (m *imlPublishModule) getReleaseInfo(ctx context.Context, projectID, releas
}
projectReleaseMap := make(map[string]*gateway.ProjectRelease)
upstreamReleaseMap := make(map[string]*gateway.UpstreamRelease)
for _, c := range upstreamCommits {
for _, partitionId := range clusterIds {
upstreamRelease := &gateway.UpstreamRelease{
@@ -265,11 +265,11 @@ func (m *imlPublishModule) getReleaseInfo(ctx context.Context, projectID, releas
return fmt.Sprintf("%s weight=%d", n.Address, n.Weight)
}),
}
upstreamReleaseMap[partitionId] = upstreamRelease
}
}
for _, clusterId := range clusterIds {
projectReleaseMap[clusterId] = &gateway.ProjectRelease{
Id: projectID,
@@ -309,7 +309,7 @@ func (m *imlPublishModule) PublishStatuses(ctx context.Context, serviceId string
Status: status.String(),
Error: errMsg,
}
}), nil
}
@@ -326,23 +326,23 @@ func (m *imlPublishModule) Apply(ctx context.Context, serviceId string, input *d
if err != nil {
return nil, err
}
previous := ""
running, err := m.releaseService.GetRunning(ctx, serviceId)
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return nil, err
}
if running != nil {
previous = running.UUID
}
releaseToPublish, err := m.releaseService.GetRelease(ctx, input.Release)
if err != nil {
// 目标版本不存在
return nil, err
}
newPublishId := uuid.NewString()
diff, ok, err := m.projectDiffModule.DiffForLatest(ctx, serviceId, previous)
if err != nil {
@@ -371,7 +371,7 @@ func (m *imlPublishModule) CheckPublish(ctx context.Context, serviceId string, r
if err != nil {
return nil, err
}
running, err := m.releaseService.GetRunning(ctx, serviceId)
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return nil, err
@@ -395,7 +395,7 @@ func (m *imlPublishModule) CheckPublish(ctx context.Context, serviceId string, r
}
return m.projectDiffModule.Out(ctx, diff)
}
}
func (m *imlPublishModule) checkPublish(ctx context.Context, serviceId string, releaseId string) error {
flows, err := m.publishService.ListForStatus(ctx, serviceId, publish.StatusApply, publish.StatusAccept)
@@ -409,7 +409,7 @@ func (m *imlPublishModule) checkPublish(ctx context.Context, serviceId string, r
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return err
}
if running == nil {
return nil
}
@@ -423,7 +423,7 @@ func (m *imlPublishModule) Close(ctx context.Context, serviceId, id string) erro
if err != nil {
return err
}
return nil
}
@@ -439,7 +439,7 @@ func (m *imlPublishModule) Stop(ctx context.Context, serviceId string, id string
if flow.Service != serviceId {
return errors.New("项目不一致")
}
if flow.Status != publish.StatusApply && flow.Status != publish.StatusAccept {
return errors.New("只有发布中状态才能停止")
}
@@ -467,7 +467,7 @@ func (m *imlPublishModule) Accept(ctx context.Context, serviceId string, id stri
}
func (m *imlPublishModule) publish(ctx context.Context, id string, clusterId string, projectRelease *gateway.ProjectRelease) error {
publishStatus := &publish.Status{
Publish: id,
Status: publish.StatusPublishing,
@@ -483,7 +483,7 @@ func (m *imlPublishModule) publish(ctx context.Context, id string, clusterId str
log.Errorf("set publishing publishStatus error: %v", err)
}
}()
client, err := m.clusterService.GatewayClient(ctx, clusterId)
if err != nil {
publishStatus.Status = publish.StatusPublishError
@@ -538,13 +538,13 @@ func (m *imlPublishModule) Publish(ctx context.Context, serviceId string, id str
clusterIds := utils.SliceToSlice(clusters, func(i *cluster.Cluster) string {
return i.Uuid
})
projectReleaseMap, err := m.getReleaseInfo(ctx, serviceId, flow.Release, flow.Release, clusterIds)
if err != nil {
return err
}
hasError := false
for _, c := range clusters {
err = m.publish(ctx, flow.Id, c.Uuid, projectReleaseMap[c.Uuid])
if err != nil {
@@ -573,7 +573,7 @@ func (m *imlPublishModule) List(ctx context.Context, serviceId string, page, pag
if err != nil {
return nil, 0, err
}
return utils.SliceToSlice(list, func(s *publish.Publish) *dto.Publish {
return dto.FromModel(s, "")
}), total, nil
@@ -612,5 +612,5 @@ func (m *imlPublishModule) Detail(ctx context.Context, serviceId string, id stri
Diffs: out,
PublishStatuses: publishStatuses,
}, nil
}
+30 -30
View File
@@ -4,11 +4,11 @@ import (
"context"
"errors"
"fmt"
"github.com/APIParkLab/APIPark/service/cluster"
"github.com/APIParkLab/APIPark/service/service"
"github.com/APIParkLab/APIPark/service/service_diff"
"github.com/APIParkLab/APIPark/module/release/dto"
serviceDiff "github.com/APIParkLab/APIPark/module/service-diff"
"github.com/APIParkLab/APIPark/service/api"
@@ -41,7 +41,7 @@ type imlReleaseModule struct {
}
func (m *imlReleaseModule) Create(ctx context.Context, serviceId string, input *dto.CreateInput) (string, error) {
proInfo, err := m.projectService.Check(ctx, serviceId, projectRuleMustServer)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
@@ -53,7 +53,7 @@ func (m *imlReleaseModule) Create(ctx context.Context, serviceId string, input *
if err != nil || len(clusters) == 0 {
return "", fmt.Errorf("cluster not set:%w", err)
}
apis, err := m.apiService.ListForService(ctx, proInfo.Id)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
@@ -77,16 +77,16 @@ func (m *imlReleaseModule) Create(ctx context.Context, serviceId string, input *
if len(apis) != len(apiProxy) {
return "", errors.New("api or document not found")
}
apiDocs, err := m.apiService.ListLatestCommitDocument(ctx, apiUUIDS...)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return "", errors.New("api config or document not found")
}
return "", err
}
if len(apis) != len(apiDocs) {
return "", errors.New("api or document not found")
}
//apiDocs, err := m.apiService.ListLatestCommitDocument(ctx, apiUUIDS...)
//if err != nil {
// if errors.Is(err, gorm.ErrRecordNotFound) {
// return "", errors.New("api config or document not found")
// }
// return "", err
//}
//if len(apis) != len(apiDocs) {
// return "", errors.New("api or document not found")
//}
upstreams, err := m.upstreamService.ListLatestCommit(ctx, serviceId)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
@@ -94,13 +94,13 @@ func (m *imlReleaseModule) Create(ctx context.Context, serviceId string, input *
}
return "", err
}
apiProxyCommits := utils.SliceToMapO(apiProxy, func(c *commit.Commit[api.Proxy]) (string, string) {
return c.Target, c.UUID
})
apiDocumentCommits := utils.SliceToMapO(apiDocs, func(c *commit.Commit[api.Document]) (string, string) {
return c.Target, c.UUID
})
//apiDocumentCommits := utils.SliceToMapO(apiDocs, func(c *commit.Commit[api.Document]) (string, string) {
// return c.Target, c.UUID
//})
upstreamCommits := utils.SliceToMapArray(upstreams, func(c *commit.Commit[upstream.Config]) string {
return c.Target
})
@@ -111,10 +111,10 @@ func (m *imlReleaseModule) Create(ctx context.Context, serviceId string, input *
})
if !m.releaseService.Completeness(utils.SliceToSlice(clusters, func(s *cluster.Cluster) string {
return s.Uuid
}), apiUUIDS, apiProxy, apiDocs, upstreams) {
}), apiUUIDS, apiProxy, nil, upstreams) {
return "", errors.New("completeness check failed")
}
newRelease, err := m.releaseService.CreateRelease(ctx, serviceId, input.Version, input.Remark, apiProxyCommits, apiDocumentCommits, upstreamCommitsForUKC)
newRelease, err := m.releaseService.CreateRelease(ctx, serviceId, input.Version, input.Remark, apiProxyCommits, nil, upstreamCommitsForUKC)
if err != nil {
return "", err
}
@@ -169,7 +169,7 @@ func (m *imlReleaseModule) List(ctx context.Context, project string) ([]*dto.Rel
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return nil, err
}
releaseIds := utils.SliceToSlice(list, func(s *release.Release) string {
return s.UUID
})
@@ -180,9 +180,9 @@ func (m *imlReleaseModule) List(ctx context.Context, project string) ([]*dto.Rel
flowMap := utils.SliceToMap(flows, func(s *publish.Publish) string {
return s.Release
})
return utils.SliceToSlice(list, func(s *release.Release) *dto.Release {
r := &dto.Release{
Id: s.UUID,
Service: auto.UUID(s.Service),
@@ -194,7 +194,7 @@ func (m *imlReleaseModule) List(ctx context.Context, project string) ([]*dto.Rel
Creator: auto.UUID(s.Creator),
CreateTime: auto.TimeLabel(s.CreateAt),
}
if running != nil && running.UUID == s.UUID {
r.Status = dto.StatusRunning
r.CanRollback = true
@@ -203,12 +203,12 @@ func (m *imlReleaseModule) List(ctx context.Context, project string) ([]*dto.Rel
flow, has := flowMap[s.UUID]
if has {
r.FlowId = flow.Id
if flow.Status == publish.StatusApply {
r.Status = dto.StatusApply
r.CanDelete = false
} else if flow.Status == publish.StatusAccept {
r.Status = dto.StatusAccept
r.CanDelete = false
} else if flow.Status == publish.StatusPublishError {
@@ -254,7 +254,7 @@ func (m *imlReleaseModule) Delete(ctx context.Context, project string, id string
}
return m.releaseService.DeleteRelease(ctx, id)
})
}
func (m *imlReleaseModule) Preview(ctx context.Context, project string) (*dto.Release, *service_diff.Diff, bool, error) {
@@ -266,11 +266,11 @@ func (m *imlReleaseModule) Preview(ctx context.Context, project string) (*dto.Re
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil, false, err
}
if running == nil {
running = new(release.Release)
}
diff, completeness, err := m.projectDiffModule.DiffForLatest(ctx, project, running.UUID)
if err != nil {
return nil, nil, false, err
@@ -286,5 +286,5 @@ func (m *imlReleaseModule) Preview(ctx context.Context, project string) (*dto.Re
CanDelete: false,
CanRollback: false,
}, diff, completeness, nil
}
+26 -26
View File
@@ -93,10 +93,10 @@ func (m *imlServiceDiff) DiffForLatest(ctx context.Context, serviceId string, ba
if err != nil {
return nil, false, fmt.Errorf("diff for api commit %v", err)
}
documents, err := m.apiService.ListLatestCommitDocument(ctx, apiIds...)
if err != nil {
return nil, false, err
}
//documents, err := m.apiService.ListLatestCommitDocument(ctx, apiIds...)
//if err != nil {
// return nil, false, err
//}
upstreamCommits, err := m.upstreamService.ListLatestCommit(ctx, serviceId)
if err != nil {
@@ -108,10 +108,10 @@ func (m *imlServiceDiff) DiffForLatest(ctx context.Context, serviceId string, ba
return nil, false, err
}
target := &projectInfo{
id: serviceId,
apis: apiInfos,
apiCommits: proxy,
apiDocs: documents,
id: serviceId,
apis: apiInfos,
apiCommits: proxy,
//apiDocs: documents,
upstreamCommits: upstreamCommits,
}
clusters, err := m.clusterService.List(ctx)
@@ -143,11 +143,11 @@ func (m *imlServiceDiff) getReleaseInfo(ctx context.Context, releaseId string) (
}, func(c *release.ProjectCommits) bool {
return c.Type == release.CommitApiProxy
})
apiDocumentCommitIds := utils.SliceToSlice(commits, func(i *release.ProjectCommits) string {
return i.Commit
}, func(c *release.ProjectCommits) bool {
return c.Type == release.CommitApiDocument
})
//apiDocumentCommitIds := utils.SliceToSlice(commits, func(i *release.ProjectCommits) string {
// return i.Commit
//}, func(c *release.ProjectCommits) bool {
// return c.Type == release.CommitApiDocument
//})
upstreamCommitIds := utils.SliceToSlice(commits, func(i *release.ProjectCommits) string {
return i.Commit
}, func(c *release.ProjectCommits) bool {
@@ -157,18 +157,18 @@ func (m *imlServiceDiff) getReleaseInfo(ctx context.Context, releaseId string) (
if err != nil {
return nil, err
}
documentCommits, err := m.apiService.ListDocumentCommit(ctx, apiDocumentCommitIds...)
if err != nil {
return nil, err
}
//documentCommits, err := m.apiService.ListDocumentCommit(ctx, apiDocumentCommitIds...)
//if err != nil {
// return nil, err
//}
upstreamCommits, err := m.upstreamService.ListCommit(ctx, upstreamCommitIds...)
if err != nil {
return nil, err
}
return &projectInfo{
apis: apiInfos,
apiCommits: proxyCommits,
apiDocs: documentCommits,
apis: apiInfos,
apiCommits: proxyCommits,
//apiDocs: documentCommits,
upstreamCommits: upstreamCommits,
}, nil
}
@@ -198,9 +198,9 @@ func (m *imlServiceDiff) diff(partitions []string, base, target *projectInfo) *s
for _, apiInfo := range target.apis {
apiId := apiInfo.UUID
a := &service_diff.ApiDiff{
APi: apiInfo.UUID,
Name: apiInfo.Name,
Method: apiInfo.Method,
APi: apiInfo.UUID,
Name: apiInfo.Name,
//Methods: apiInfo.Methods,
Path: apiInfo.Path,
Status: service_diff.Status{},
}
@@ -240,9 +240,9 @@ func (m *imlServiceDiff) diff(partitions []string, base, target *projectInfo) *s
for _, apiInfo := range base.apis {
if baseApis.Has(apiInfo.UUID) {
out.Apis = append(out.Apis, &service_diff.ApiDiff{
APi: apiInfo.UUID,
Name: apiInfo.Name,
Method: apiInfo.Method,
APi: apiInfo.UUID,
Name: apiInfo.Name,
//Methods: apiInfo.Methods,
Path: apiInfo.Path,
Status: service_diff.Status{},
Change: service_diff.ChangeTypeDelete,
+1 -1
View File
@@ -38,7 +38,7 @@ type UpstreamDiffOut struct {
// Apis: utils.SliceToSlice(d.Apis, func(s *project_diff.ApiDiff) *ApiDiffOut {
// return &ApiDiffOut{
// Name: s.Name,
// Method: s.Method,
// Methods: s.Methods,
// Path: s.Path,
// Upstream: s.Upstream,
// Change: s.Change,
+20
View File
@@ -113,3 +113,23 @@ type ServiceDoc struct {
Updater auto.Label `json:"updater" aolabel:"user"`
UpdateTime auto.TimeLabel `json:"update_time"`
}
type ExportService struct {
Id string `json:"id"`
Name string `json:"name"`
Prefix string `json:"prefix,omitempty"`
Description string `json:"description"`
Team string `json:"team"`
ServiceType string `json:"service_type"`
Catalogue string `json:"catalogue"`
Tags []string `json:"tags"`
Logo string `json:"logo"`
Doc string `json:"doc"`
}
type ExportApp struct {
Id string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Team string `json:"team"`
}
+127 -57
View File
@@ -6,39 +6,40 @@ import (
"fmt"
"sort"
"strings"
service_tag "github.com/APIParkLab/APIPark/service/service-tag"
service_doc "github.com/APIParkLab/APIPark/service/service-doc"
serviceDto "github.com/APIParkLab/APIPark/module/service/dto"
"github.com/APIParkLab/APIPark/service/tag"
"github.com/APIParkLab/APIPark/service/service"
"github.com/APIParkLab/APIPark/service/subscribe"
"gorm.io/gorm"
"github.com/APIParkLab/APIPark/service/api"
"github.com/eolinker/go-common/auto"
team_member "github.com/APIParkLab/APIPark/service/team-member"
"github.com/eolinker/go-common/store"
"github.com/google/uuid"
"github.com/eolinker/go-common/utils"
"github.com/APIParkLab/APIPark/service/team"
service_dto "github.com/APIParkLab/APIPark/module/service/dto"
)
var (
_ IServiceModule = (*imlServiceModule)(nil)
_ IServiceModule = (*imlServiceModule)(nil)
_ IExportServiceModule = (*imlServiceModule)(nil)
)
type imlServiceModule struct {
@@ -52,8 +53,64 @@ type imlServiceModule struct {
transaction store.ITransaction `autowired:""`
}
func (i *imlServiceModule) ExportAll(ctx context.Context) ([]*service_dto.ExportService, error) {
services, err := i.serviceService.ServiceList(ctx)
if err != nil {
return nil, err
}
serviceIds := utils.SliceToSlice(services, func(s *service.Service) string {
return s.Id
})
serviceTags, err := i.serviceTagService.List(ctx, serviceIds, nil)
if err != nil {
return nil, err
}
tagMap, err := i.tagService.Map(ctx)
if err != nil {
return nil, err
}
serviceTagMap := make(map[string][]string)
for _, st := range serviceTags {
if _, ok := tagMap[st.Tid]; !ok {
continue
}
if _, ok := serviceTagMap[st.Sid]; !ok {
serviceTagMap[st.Sid] = make([]string, 0)
}
serviceTagMap[st.Sid] = append(serviceTagMap[st.Sid], tagMap[st.Tid].Name)
}
docMap, err := i.serviceDocService.Map(ctx, serviceIds...)
if err != nil {
return nil, err
}
items := make([]*service_dto.ExportService, 0, len(services))
for _, s := range services {
info := &service_dto.ExportService{
Id: s.Id,
Name: s.Name,
Prefix: s.Prefix,
Description: s.Description,
Team: s.Team,
ServiceType: s.ServiceType.String(),
Catalogue: s.Catalogue,
Logo: s.Logo,
}
if v, ok := docMap[s.Id]; ok {
info.Doc = v.Doc
}
if tags, ok := serviceTagMap[s.Id]; ok {
info.Tags = tags
}
items = append(items, info)
}
return items, nil
}
func (i *imlServiceModule) searchMyServices(ctx context.Context, teamId string, keyword string) ([]*service.Service, error) {
userID := utils.UserId(ctx)
condition := make(map[string]interface{})
condition["as_server"] = true
@@ -73,7 +130,7 @@ func (i *imlServiceModule) searchMyServices(ctx context.Context, teamId string,
condition["team"] = teamIds
return i.serviceService.Search(ctx, keyword, condition, "update_at desc")
}
}
func (i *imlServiceModule) SearchMyServices(ctx context.Context, teamId string, keyword string) ([]*service_dto.ServiceItem, error) {
@@ -88,7 +145,7 @@ func (i *imlServiceModule) SearchMyServices(ctx context.Context, teamId string,
if err != nil {
return nil, err
}
items := make([]*service_dto.ServiceItem, 0, len(services))
for _, model := range services {
if teamId != "" && model.Team != teamId {
@@ -121,7 +178,7 @@ func (i *imlServiceModule) SimpleAPPS(ctx context.Context, keyword string) ([]*s
Id: p.Id,
Name: p.Name,
Description: p.Description,
Team: auto.UUID(p.Team),
}
}), nil
@@ -130,15 +187,15 @@ func (i *imlServiceModule) SimpleAPPS(ctx context.Context, keyword string) ([]*s
func (i *imlServiceModule) Simple(ctx context.Context, keyword string) ([]*service_dto.SimpleServiceItem, error) {
w := make(map[string]interface{})
w["as_server"] = true
services, err := i.serviceService.Search(ctx, keyword, w)
if err != nil {
return nil, err
}
items := make([]*service_dto.SimpleServiceItem, 0, len(services))
for _, p := range services {
items = append(items, &service_dto.SimpleServiceItem{
Id: p.Id,
Name: p.Name,
@@ -151,14 +208,14 @@ func (i *imlServiceModule) Simple(ctx context.Context, keyword string) ([]*servi
func (i *imlServiceModule) MySimple(ctx context.Context, keyword string) ([]*service_dto.SimpleServiceItem, error) {
services, err := i.searchMyServices(ctx, "", keyword)
if err != nil {
return nil, err
}
items := make([]*service_dto.SimpleServiceItem, 0, len(services))
for _, p := range services {
items = append(items, &service_dto.SimpleServiceItem{
Id: p.Id,
Name: p.Name,
@@ -178,7 +235,7 @@ func (i *imlServiceModule) Get(ctx context.Context, id string) (*service_dto.Ser
if err != nil {
return nil, err
}
s := service_dto.ToService(serviceInfo)
s.Tags = auto.List(utils.SliceToSlice(tags, func(p *service_tag.Tag) string {
return p.Tid
@@ -201,24 +258,19 @@ func (i *imlServiceModule) Search(ctx context.Context, teamID string, keyword st
if err != nil {
return nil, err
}
serviceIds := utils.SliceToSlice(list, func(s *service.Service) string {
return s.Id
})
apiCountMap, err := i.apiService.CountByGroup(ctx, "", map[string]interface{}{"service": serviceIds}, "service")
if err != nil {
return nil, err
}
//serviceCountMap, err := i.serviceService.CountByGroup(ctx, "", map[string]interface{}{"uuid": serviceIds}, "service")
//if err != nil {
// return nil, err
//}
items := make([]*service_dto.ServiceItem, 0, len(list))
for _, model := range list {
apiCount := apiCountMap[model.Id]
//serviceCount := serviceCountMap[model.Id]
items = append(items, &service_dto.ServiceItem{
Id: model.Id,
Name: model.Name,
@@ -234,7 +286,7 @@ func (i *imlServiceModule) Search(ctx context.Context, teamID string, keyword st
}
func (i *imlServiceModule) Create(ctx context.Context, teamID string, input *service_dto.CreateService) (*service_dto.Service, error) {
if input.Id == "" {
input.Id = uuid.New().String()
}
@@ -300,7 +352,7 @@ func (i *imlServiceModule) Edit(ctx context.Context, id string, input *service_d
return fmt.Errorf("catalogue can not be empty")
}
}
err = i.serviceService.Save(ctx, id, &service.Edit{
Name: input.Name,
Description: input.Description,
@@ -329,7 +381,7 @@ func (i *imlServiceModule) Edit(ctx context.Context, id string, input *service_d
}
return nil
})
if err != nil {
return nil, err
}
@@ -337,7 +389,7 @@ func (i *imlServiceModule) Edit(ctx context.Context, id string, input *service_d
}
func (i *imlServiceModule) Delete(ctx context.Context, id string) error {
err := i.transaction.Transaction(ctx, func(ctx context.Context) error {
count, err := i.apiService.CountByService(ctx, id)
if err != nil {
@@ -346,7 +398,7 @@ func (i *imlServiceModule) Delete(ctx context.Context, id string) error {
if count > 0 {
return fmt.Errorf("service has apis, can not delete")
}
return i.serviceService.Delete(ctx, id)
})
return err
@@ -389,7 +441,7 @@ func (i *imlServiceModule) getTagUuids(ctx context.Context, tags []string) ([]st
func (i *imlServiceModule) ServiceDoc(ctx context.Context, pid string) (*serviceDto.ServiceDoc, error) {
_, err := i.serviceService.Check(ctx, pid, map[string]bool{"as_server": true})
if err != nil {
return nil, err
}
@@ -421,7 +473,7 @@ func (i *imlServiceModule) ServiceDoc(ctx context.Context, pid string) (*service
func (i *imlServiceModule) SaveServiceDoc(ctx context.Context, pid string, input *serviceDto.SaveServiceDoc) error {
_, err := i.serviceService.Check(ctx, pid, map[string]bool{"as_server": true})
if err != nil {
return err
}
@@ -431,7 +483,10 @@ func (i *imlServiceModule) SaveServiceDoc(ctx context.Context, pid string, input
})
}
var _ IAppModule = &imlAppModule{}
var (
_ IAppModule = &imlAppModule{}
_ IExportAppModule = &imlAppModule{}
)
type imlAppModule struct {
teamService team.ITeamService `autowired:""`
@@ -441,6 +496,21 @@ type imlAppModule struct {
transaction store.ITransaction `autowired:""`
}
func (i *imlAppModule) ExportAll(ctx context.Context) ([]*service_dto.ExportApp, error) {
apps, err := i.serviceService.AppList(ctx)
if err != nil {
return nil, err
}
return utils.SliceToSlice(apps, func(p *service.Service) *service_dto.ExportApp {
return &service_dto.ExportApp{
Id: p.Id,
Name: p.Name,
Description: p.Description,
Team: p.Team,
}
}), nil
}
func (i *imlAppModule) Search(ctx context.Context, teamId string, keyword string) ([]*service_dto.AppItem, error) {
var services []*service.Service
var err error
@@ -456,16 +526,16 @@ func (i *imlAppModule) Search(ctx context.Context, teamId string, keyword string
if err != nil {
return nil, err
}
serviceIds := utils.SliceToSlice(services, func(p *service.Service) string {
return p.Id
})
subscribers, err := i.subscribeService.SubscriptionsByApplication(ctx, serviceIds...)
if err != nil {
return nil, err
}
subscribeCount := map[string]int64{}
subscribeVerifyCount := map[string]int64{}
verifyTmp := map[string]struct{}{}
@@ -484,7 +554,7 @@ func (i *imlAppModule) Search(ctx context.Context, teamId string, keyword string
subscribeVerifyCount[s.Application]++
}
default:
}
}
items := make([]*service_dto.AppItem, 0, len(services))
@@ -516,7 +586,7 @@ func (i *imlAppModule) Search(ctx context.Context, teamId string, keyword string
}
func (i *imlAppModule) CreateApp(ctx context.Context, teamID string, input *service_dto.CreateApp) (*service_dto.App, error) {
if input.Id == "" {
input.Id = uuid.New().String()
}
@@ -536,11 +606,11 @@ func (i *imlAppModule) CreateApp(ctx context.Context, teamID string, input *serv
if len(members) == 0 {
return nil, fmt.Errorf("master is not in team")
}
err = i.transaction.Transaction(ctx, func(ctx context.Context) error {
return i.serviceService.Create(ctx, mo)
})
if err != nil {
return nil, err
@@ -560,7 +630,7 @@ func (i *imlAppModule) UpdateApp(ctx context.Context, appId string, input *servi
//if info.Master != userId {
// return nil, fmt.Errorf("user is not app master, can not update")
//}
err = i.serviceService.Save(ctx, appId, &service.Edit{
Name: input.Name,
Description: input.Description,
@@ -589,7 +659,7 @@ func (i *imlAppModule) searchMyApps(ctx context.Context, teamId string, keyword
}
teamIds := membersForUser[userID]
condition["team"] = teamIds
return i.serviceService.Search(ctx, keyword, condition, "update_at desc")
}
}
@@ -602,12 +672,12 @@ func (i *imlAppModule) SearchMyApps(ctx context.Context, teamId string, keyword
serviceIds := utils.SliceToSlice(services, func(p *service.Service) string {
return p.Id
})
subscribers, err := i.subscribeService.SubscriptionsByApplication(ctx, serviceIds...)
if err != nil {
return nil, err
}
subscribeCount := map[string]int64{}
subscribeVerifyCount := map[string]int64{}
verifyTmp := map[string]struct{}{}
@@ -626,7 +696,7 @@ func (i *imlAppModule) SearchMyApps(ctx context.Context, teamId string, keyword
subscribeVerifyCount[s.Application]++
}
default:
}
}
items := make([]*service_dto.AppItem, 0, len(services))
@@ -681,7 +751,7 @@ func (i *imlAppModule) MySimpleApps(ctx context.Context, keyword string) ([]*ser
}
items := make([]*service_dto.SimpleAppItem, 0, len(services))
for _, p := range services {
items = append(items, &service_dto.SimpleAppItem{
Id: p.Id,
Name: p.Name,
@@ -722,6 +792,6 @@ func (i *imlAppModule) DeleteApp(ctx context.Context, appId string) error {
if !info.AsApp {
return errors.New("not app, can not delete")
}
return i.serviceService.Delete(ctx, appId)
}
+32 -13
View File
@@ -2,10 +2,11 @@ package service
import (
"context"
"github.com/APIParkLab/APIPark/module/system"
"reflect"
service_dto "github.com/APIParkLab/APIPark/module/service/dto"
"github.com/eolinker/go-common/autowire"
)
@@ -24,15 +25,19 @@ type IServiceModule interface {
Delete(ctx context.Context, id string) error
// Simple 获取简易项目列表
Simple(ctx context.Context, keyword string) ([]*service_dto.SimpleServiceItem, error)
// MySimple 获取我的简易项目列表
MySimple(ctx context.Context, keyword string) ([]*service_dto.SimpleServiceItem, error)
ServiceDoc(ctx context.Context, pid string) (*service_dto.ServiceDoc, error)
// SaveServiceDoc 保存服务文档
SaveServiceDoc(ctx context.Context, pid string, input *service_dto.SaveServiceDoc) error
}
type IExportServiceModule interface {
system.IExportModule[service_dto.ExportService]
}
type IAppModule interface {
CreateApp(ctx context.Context, teamID string, input *service_dto.CreateApp) (*service_dto.App, error)
UpdateApp(ctx context.Context, appId string, input *service_dto.UpdateApp) (*service_dto.App, error)
@@ -45,13 +50,27 @@ type IAppModule interface {
DeleteApp(ctx context.Context, appId string) error
}
func init() {
autowire.Auto[IServiceModule](func() reflect.Value {
m := new(imlServiceModule)
return reflect.ValueOf(m)
})
autowire.Auto[IAppModule](func() reflect.Value {
return reflect.ValueOf(new(imlAppModule))
})
type IExportAppModule interface {
system.IExportModule[service_dto.ExportApp]
}
func init() {
serviceModule := new(imlServiceModule)
autowire.Auto[IServiceModule](func() reflect.Value {
return reflect.ValueOf(serviceModule)
})
autowire.Auto[IExportServiceModule](func() reflect.Value {
return reflect.ValueOf(serviceModule)
})
appModule := new(imlAppModule)
autowire.Auto[IAppModule](func() reflect.Value {
return reflect.ValueOf(appModule)
})
autowire.Auto[IExportAppModule](func() reflect.Value {
return reflect.ValueOf(appModule)
})
}
+17 -12
View File
@@ -3,16 +3,13 @@ package subscribe_dto
import "github.com/eolinker/go-common/auto"
type Subscriber struct {
Id string `json:"id"`
Service auto.Label `json:"service" aolabel:"service"`
//Cluster []auto.Label `json:"partition" aolabel:"partition"`
Id string `json:"id"`
Service auto.Label `json:"service" aolabel:"service"`
Subscriber auto.Label `json:"subscriber" aolabel:"service"`
Team auto.Label `json:"team" aolabel:"team"`
ApplyTime auto.TimeLabel `json:"apply_time"`
Applier auto.Label `json:"applier" aolabel:"user"`
//Approver auto.Label `json:"approver" aolabel:"user"`
From int `json:"from"`
From int `json:"from"`
}
type SubscriptionItem struct {
@@ -54,9 +51,17 @@ type ApprovalItem struct {
Status int `json:"status"`
}
//
//type PartitionServiceItem struct {
// Id string `json:"id"`
// Name string `json:"name"`
// ServiceNum int64 `json:"service_num"`
//}
type ExportApproval struct {
Service string `json:"service"`
Application string `json:"application"`
Reason string `json:"reason"`
}
type ExportSubscriber struct {
Id string `json:"id"`
Service string `json:"service"`
Subscriber string `json:"subscriber"`
Team string `json:"team"`
Applier string `json:"applier"`
From int `json:"from"`
}
+46 -2
View File
@@ -26,7 +26,8 @@ import (
)
var (
_ ISubscribeModule = (*imlSubscribeModule)(nil)
_ ISubscribeModule = (*imlSubscribeModule)(nil)
_ IExportSubscribeModule = (*imlSubscribeModule)(nil)
)
type imlSubscribeModule struct {
@@ -37,6 +38,31 @@ type imlSubscribeModule struct {
transaction store.ITransaction `autowired:""`
}
func (i *imlSubscribeModule) ExistSubscriber(ctx context.Context, serviceId string, app string) error {
_, err := i.subscribeService.GetByServiceAndApplication(ctx, serviceId, app)
if err == nil {
return nil
}
return err
}
func (i *imlSubscribeModule) ExportAll(ctx context.Context) ([]*subscribe_dto.ExportSubscriber, error) {
list, err := i.subscribeService.List(ctx)
if err != nil {
return nil, err
}
return utils.SliceToSlice(list, func(s *subscribe.Subscribe) *subscribe_dto.ExportSubscriber {
return &subscribe_dto.ExportSubscriber{
Id: s.Id,
Service: s.Service,
Subscriber: s.Application,
Applier: s.Applier,
From: s.From,
}
}), nil
}
func (i *imlSubscribeModule) getSubscribers(ctx context.Context, serviceIds []string) ([]*gateway.SubscribeRelease, error) {
subscribers, err := i.subscribeService.SubscribersByProject(ctx, serviceIds...)
if err != nil {
@@ -343,7 +369,10 @@ func (i *imlSubscribeModule) SearchSubscribers(ctx context.Context, serviceId st
return items, nil
}
var _ ISubscribeApprovalModule = (*imlSubscribeApprovalModule)(nil)
var (
_ ISubscribeApprovalModule = (*imlSubscribeApprovalModule)(nil)
_ ISubscribeApprovalModule = (*imlSubscribeApprovalModule)(nil)
)
type imlSubscribeApprovalModule struct {
subscribeService subscribe.ISubscribeService `autowired:""`
@@ -353,6 +382,21 @@ type imlSubscribeApprovalModule struct {
transaction store.ITransaction `autowired:""`
}
func (i *imlSubscribeApprovalModule) ExportAll(ctx context.Context) ([]*subscribe_dto.ExportApproval, error) {
list, err := i.subscribeApplyService.List(ctx)
if err != nil {
return nil, err
}
return utils.SliceToSlice(list, func(s *subscribe.Apply) *subscribe_dto.ExportApproval {
return &subscribe_dto.ExportApproval{
Service: s.Service,
Application: s.Application,
Reason: s.Reason,
}
}), nil
}
func (i *imlSubscribeApprovalModule) Pass(ctx context.Context, pid string, id string, approveInfo *subscribe_dto.Approve) error {
applyInfo, err := i.subscribeApplyService.Get(ctx, id)
if err != nil {
+29 -6
View File
@@ -2,16 +2,18 @@ package subscribe
import (
"context"
"github.com/APIParkLab/APIPark/module/system"
"reflect"
"github.com/eolinker/go-common/autowire"
subscribe_dto "github.com/APIParkLab/APIPark/module/subscribe/dto"
)
type ISubscribeModule interface {
// AddSubscriber 新增订阅方
AddSubscriber(ctx context.Context, pid string, input *subscribe_dto.AddSubscriber) error
ExistSubscriber(ctx context.Context, serviceId string, app string) error
// DeleteSubscriber 删除订阅方
DeleteSubscriber(ctx context.Context, project string, serviceId string, applicationId string) error
// SearchSubscribers 关键字获取订阅方列表
@@ -24,7 +26,12 @@ type ISubscribeModule interface {
DeleteSubscription(ctx context.Context, pid string, uuid string) error
// RevokeApply 取消申请
RevokeApply(ctx context.Context, app string, uuid string) error
//PartitionServices(ctx context.Context, app string) ([]*subscribe_dto.PartitionServiceItem, error)
//ExportAll(ctx context.Context) ([]*subscribe_dto.ExportSubscriber, error)
}
type IExportSubscribeModule interface {
system.IExportModule[subscribe_dto.ExportSubscriber]
}
type ISubscribeApprovalModule interface {
@@ -36,14 +43,30 @@ type ISubscribeApprovalModule interface {
Pass(ctx context.Context, pid string, id string, approveInfo *subscribe_dto.Approve) error
// Reject 驳回审批
Reject(ctx context.Context, pid string, id string, approveInfo *subscribe_dto.Approve) error
ExportAll(ctx context.Context) ([]*subscribe_dto.ExportApproval, error)
}
type IExportSubscribeApprovalModule interface {
system.IExportModule[subscribe_dto.ExportApproval]
}
func init() {
subscribeModule := new(imlSubscribeModule)
autowire.Auto[ISubscribeModule](func() reflect.Value {
return reflect.ValueOf(new(imlSubscribeModule))
return reflect.ValueOf(subscribeModule)
})
autowire.Auto[IExportSubscribeModule](func() reflect.Value {
return reflect.ValueOf(subscribeModule)
})
applyModule := new(imlSubscribeApprovalModule)
autowire.Auto[ISubscribeApprovalModule](func() reflect.Value {
return reflect.ValueOf(new(imlSubscribeApprovalModule))
return reflect.ValueOf(applyModule)
})
autowire.Auto[IExportSubscribeApprovalModule](func() reflect.Value {
return reflect.ValueOf(applyModule)
})
}
+7
View File
@@ -0,0 +1,7 @@
package system
import "context"
type IExportModule[T any] interface {
ExportAll(ctx context.Context) ([]*T, error)
}
+6
View File
@@ -52,3 +52,9 @@ func ToTeam(model *team.Team, serviceNum int64, appNum int64) *Team {
CanDelete: serviceNum == 0 && appNum == 0,
}
}
type ExportTeam struct {
Id string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
}
+29 -15
View File
@@ -3,26 +3,26 @@ package team
import (
"context"
"fmt"
"github.com/eolinker/go-common/utils"
"github.com/eolinker/ap-account/service/role"
"github.com/eolinker/go-common/store"
"github.com/eolinker/ap-account/service/user"
"github.com/APIParkLab/APIPark/service/service"
team_member "github.com/APIParkLab/APIPark/service/team-member"
"github.com/google/uuid"
team_dto "github.com/APIParkLab/APIPark/module/team/dto"
"github.com/APIParkLab/APIPark/service/team"
)
var (
_ ITeamModule = (*imlTeamModule)(nil)
_ ITeamModule = (*imlTeamModule)(nil)
_ ITeamExportModule = (*imlTeamModule)(nil)
)
type imlTeamModule struct {
@@ -35,6 +35,20 @@ type imlTeamModule struct {
transaction store.ITransaction `autowired:""`
}
func (m *imlTeamModule) ExportAll(ctx context.Context) ([]*team_dto.ExportTeam, error) {
teams, err := m.service.List(ctx)
if err != nil {
return nil, err
}
return utils.SliceToSlice(teams, func(t *team.Team) *team_dto.ExportTeam {
return &team_dto.ExportTeam{
Id: t.Id,
Name: t.Name,
Description: t.Description,
}
}), nil
}
func (m *imlTeamModule) GetTeam(ctx context.Context, id string) (*team_dto.Team, error) {
tv, err := m.service.Get(ctx, id)
if err != nil {
@@ -48,9 +62,9 @@ func (m *imlTeamModule) GetTeam(ctx context.Context, id string) (*team_dto.Team,
if err != nil {
return nil, err
}
return team_dto.ToTeam(tv, serviceCountMap[id], appCountMap[id]), nil
}
func (m *imlTeamModule) Search(ctx context.Context, keyword string) ([]*team_dto.Item, error) {
@@ -58,7 +72,7 @@ func (m *imlTeamModule) Search(ctx context.Context, keyword string) ([]*team_dto
if err != nil {
return nil, err
}
serviceCountMap, err := m.serviceService.ServiceCountByTeam(ctx)
if err != nil {
return nil, err
@@ -78,7 +92,7 @@ func (m *imlTeamModule) Create(ctx context.Context, input *team_dto.CreateTeam)
if input.Id == "" {
input.Id = uuid.New().String()
}
err := m.transaction.Transaction(ctx, func(ctx context.Context) error {
if input.Master == "" {
input.Master = utils.UserId(ctx)
@@ -91,7 +105,7 @@ func (m *imlTeamModule) Create(ctx context.Context, input *team_dto.CreateTeam)
if err != nil {
return err
}
err = m.memberService.AddMemberTo(ctx, input.Id, input.Master)
if err != nil {
return err
@@ -100,7 +114,7 @@ func (m *imlTeamModule) Create(ctx context.Context, input *team_dto.CreateTeam)
if err != nil {
return err
}
return m.roleMemberService.Add(ctx, &role.AddMember{
Role: supperRole.Id,
User: input.Master,
@@ -120,7 +134,7 @@ func (m *imlTeamModule) Edit(ctx context.Context, id string, input *team_dto.Edi
Description: input.Description,
})
})
if err != nil {
return nil, err
}
+14 -3
View File
@@ -2,8 +2,9 @@ package team
import (
"context"
"github.com/APIParkLab/APIPark/module/system"
"reflect"
team_dto "github.com/APIParkLab/APIPark/module/team/dto"
"github.com/eolinker/go-common/autowire"
)
@@ -13,17 +14,27 @@ type ITeamModule interface {
GetTeam(ctx context.Context, id string) (*team_dto.Team, error)
// Search 搜索团队
Search(ctx context.Context, keyword string) ([]*team_dto.Item, error)
// Create 创建团队
Create(ctx context.Context, input *team_dto.CreateTeam) (*team_dto.Team, error)
// Edit 编辑团队
Edit(ctx context.Context, id string, input *team_dto.EditTeam) (*team_dto.Team, error)
// Delete 删除团队
Delete(ctx context.Context, id string) error
//ExportAll(ctx context.Context) ([]*team_dto.ExportTeam, error)
}
type ITeamExportModule interface {
system.IExportModule[team_dto.ExportTeam]
}
func init() {
teamModule := new(imlTeamModule)
autowire.Auto[ITeamModule](func() reflect.Value {
return reflect.ValueOf(new(imlTeamModule))
return reflect.ValueOf(teamModule)
})
autowire.Auto[ITeamExportModule](func() reflect.Value {
return reflect.ValueOf(teamModule)
})
}
+8
View File
@@ -2,6 +2,14 @@ package upstream_dto
type UpstreamConfig *Upstream
type ExportUpstream struct {
ID string `json:"id"`
Name string `json:"name"`
Service string `json:"service"`
*Upstream
}
type Upstream struct {
Type string `json:"driver"`
Balance string `json:"balance"`
+47 -15
View File
@@ -4,34 +4,66 @@ import (
"context"
"errors"
"fmt"
"github.com/APIParkLab/APIPark/service/universally/commit"
"github.com/eolinker/go-common/utils"
"github.com/APIParkLab/APIPark/service/cluster"
"github.com/APIParkLab/APIPark/service/service"
"gorm.io/gorm"
"github.com/APIParkLab/APIPark/service/upstream"
"github.com/eolinker/go-common/store"
upstream_dto "github.com/APIParkLab/APIPark/module/upstream/dto"
)
var (
_ IUpstreamModule = (*imlUpstreamModule)(nil)
asServer = map[string]bool{
_ IUpstreamModule = (*imlUpstreamModule)(nil)
_ IExportUpstreamModule = (*imlUpstreamModule)(nil)
asServer = map[string]bool{
"as_server": true,
}
)
type imlUpstreamModule struct {
projectService service.IServiceService `autowired:""`
serviceService service.IServiceService `autowired:""`
upstreamService upstream.IUpstreamService `autowired:""`
transaction store.ITransaction `autowired:""`
}
func (i *imlUpstreamModule) ExportAll(ctx context.Context) ([]*upstream_dto.ExportUpstream, error) {
latestCommits, err := i.upstreamService.ListLatestCommit(ctx)
if err != nil {
return nil, err
}
commitMap := utils.SliceToMap(latestCommits, func(c *commit.Commit[upstream.Config]) string {
return c.Target
})
list, err := i.upstreamService.List(ctx)
if err != nil {
return nil, err
}
items := make([]*upstream_dto.ExportUpstream, 0, len(list))
for _, u := range list {
c, ok := commitMap[u.UUID]
if !ok {
continue
}
items = append(items, &upstream_dto.ExportUpstream{
ID: u.UUID,
Name: u.Name,
Service: u.Service,
Upstream: upstream_dto.FromClusterConfig(c.Data),
})
}
return items, nil
}
func (i *imlUpstreamModule) Get(ctx context.Context, pid string) (upstream_dto.UpstreamConfig, error) {
_, err := i.projectService.Check(ctx, pid, asServer)
_, err := i.serviceService.Check(ctx, pid, asServer)
if err != nil {
return nil, err
}
@@ -49,29 +81,29 @@ func (i *imlUpstreamModule) Get(ctx context.Context, pid string) (upstream_dto.U
}
return nil, nil
}
return upstream_dto.FromClusterConfig(commit.Data), nil
}
func (i *imlUpstreamModule) Save(ctx context.Context, pid string, upstreamConfig upstream_dto.UpstreamConfig) (upstream_dto.UpstreamConfig, error) {
pInfo, err := i.projectService.Check(ctx, pid, asServer)
pInfo, err := i.serviceService.Check(ctx, pid, asServer)
if err != nil {
return nil, err
}
err = i.transaction.Transaction(ctx, func(ctx context.Context) error {
err = i.upstreamService.SaveCommit(ctx, pid, cluster.DefaultClusterID, upstream_dto.ConvertUpstream(upstreamConfig))
if err != nil {
return err
}
return i.upstreamService.Save(ctx, &upstream.SaveUpstream{
UUID: pid,
Name: fmt.Sprintf("upstream-%s", pid),
Project: pid,
Service: pid,
Team: pInfo.Team,
})
})
if err != nil {
return nil, err
+14 -3
View File
@@ -2,20 +2,31 @@ package upstream
import (
"context"
"github.com/APIParkLab/APIPark/module/system"
"reflect"
"github.com/eolinker/go-common/autowire"
upstream_dto "github.com/APIParkLab/APIPark/module/upstream/dto"
)
type IUpstreamModule interface {
Get(ctx context.Context, pid string) (upstream_dto.UpstreamConfig, error)
Save(ctx context.Context, pid string, upstream upstream_dto.UpstreamConfig) (upstream_dto.UpstreamConfig, error)
//ExportAll(ctx context.Context) ([]*upstream_dto.ExportUpstream, error)
}
type IExportUpstreamModule interface {
system.IExportModule[upstream_dto.ExportUpstream]
}
func init() {
upstreamModule := new(imlUpstreamModule)
autowire.Auto[IUpstreamModule](func() reflect.Value {
return reflect.ValueOf(new(imlUpstreamModule))
return reflect.ValueOf(upstreamModule)
})
autowire.Auto[IExportUpstreamModule](func() reflect.Value {
return reflect.ValueOf(upstreamModule)
})
}
+5 -6
View File
@@ -9,16 +9,15 @@ import (
func (p *plugin) apiApis() []pm3.Api {
return []pm3.Api{
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/service/apis", []string{"context", "query:keyword", "query:service"}, []string{"apis"}, p.apiController.Search),
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/service/apis/simple", []string{"context", "query:keyword", "query:service"}, []string{"apis"}, p.apiController.SimpleSearch),
//pm3.CreateApiWidthDoc(http.MethodPost, "/api/v1/simple/service/apis", []string{"context", "query:service"}, []string{"apis"}, p.apiController.SimpleList),
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/service/api/detail", []string{"context", "query:service", "query:api"}, []string{"api"}, p.apiController.Detail),
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/service/api/detail/simple", []string{"context", "query:service", "query:api"}, []string{"api"}, p.apiController.SimpleDetail),
pm3.CreateApiWidthDoc(http.MethodPost, "/api/v1/service/api", []string{"context", "query:service", "body"}, []string{"api"}, p.apiController.Create),
pm3.CreateApiWidthDoc(http.MethodPut, "/api/v1/service/api", []string{"context", "query:service", "query:api", "body"}, []string{"api"}, p.apiController.Edit),
pm3.CreateApiWidthDoc(http.MethodDelete, "/api/v1/service/api", []string{"context", "query:service", "query:api"}, nil, p.apiController.Delete),
pm3.CreateApiWidthDoc(http.MethodPost, "/api/v1/service/api/copy", []string{"context", "query:service", "query:api", "body"}, []string{"api"}, p.apiController.Copy),
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/service/api/doc", []string{"context", "query:service", "query:api"}, []string{"api"}, p.apiController.ApiDocDetail),
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/service/api/proxy", []string{"context", "query:service", "query:api"}, []string{"api"}, p.apiController.ApiProxyDetail),
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/service/api/define", []string{"context", "query:service"}, []string{"prefix", "force"}, p.apiController.Prefix),
pm3.CreateApiWidthDoc(http.MethodPut, "/api/v1/service/api_doc", []string{"context", "query:service", "body"}, []string{"doc"}, p.apiDocController.UpdateDoc),
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/service/api_doc", []string{"context", "query:service"}, []string{"doc"}, p.apiDocController.GetDoc),
pm3.CreateApiWidthDoc(http.MethodPost, "/api/v1/service/api_doc/upload", []string{"context", "query:service"}, []string{"doc"}, p.apiDocController.UploadDoc),
}
}
+5
View File
@@ -2,6 +2,7 @@ package core
import (
"github.com/APIParkLab/APIPark/controller/monitor"
"github.com/APIParkLab/APIPark/controller/system"
"net/http"
plugin_cluster "github.com/APIParkLab/APIPark/controller/plugin-cluster"
@@ -66,6 +67,7 @@ type plugin struct {
catalogueController catalogue.ICatalogueController `autowired:""`
upstreamController upstream.IUpstreamController `autowired:""`
apiController api.IAPIController `autowired:""`
apiDocController api.IAPIDocController `autowired:""`
subscribeController subscribe.ISubscribeController `autowired:""`
appAuthorizationController application_authorization.IAuthorizationController `autowired:""`
releaseController release.IReleaseController `autowired:""`
@@ -74,6 +76,8 @@ type plugin struct {
dynamicModuleController dynamic_module.IDynamicModuleController `autowired:""`
pluginClusterController plugin_cluster.IPluginClusterController `autowired:""`
commonController common.ICommonController `autowired:""`
exportConfigController system.IExportConfigController `autowired:""`
importConfigController system.IImportConfigController `autowired:""`
apis []pm3.Api
}
@@ -93,6 +97,7 @@ func (p *plugin) OnComplete() {
p.apis = append(p.apis, p.monitorStatisticApis()...)
p.apis = append(p.apis, p.PartitionPluginApi()...)
p.apis = append(p.apis, p.commonApis()...)
p.apis = append(p.apis, p.systemApis()...)
}
func (p *plugin) Name() string {
+13
View File
@@ -0,0 +1,13 @@
package core
import (
"github.com/eolinker/go-common/pm3"
"net/http"
)
func (p *plugin) systemApis() []pm3.Api {
return []pm3.Api{
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/system/_export", []string{"context"}, nil, p.exportConfigController.ExportAll),
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/system/_import", []string{"context"}, nil, p.importConfigController.ImportAll),
}
}
+32 -1
View File
@@ -132,7 +132,6 @@ system:
- "POST:/api/v1/certificate"
- "PUT:/api/v1/certificate"
- "DELETE:/api/v1/certificate"
- name: log configuration
cname: 日志
value: 'log_configuration'
@@ -154,6 +153,38 @@ system:
- "DELETE:/api/v1/dynamic/{name}/batch"
- "PUT:/api/v1/dynamic/{name}/online"
- "PUT:/api/v1/dynamic/{name}/offline"
- 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"
- name: dashboard
cname: 仪表盘
value: 'dashboard'
children:
- name: run view
cname: 运行视图
value: 'run_view'
children:
- name: view
cname: 查看
value: 'view'
guest_allow: true
apis:
- "GET:/api/v1/monitor/overview/invoke"
- "GET:/api/v1/monitor/overview/message"
- "GET:/api/v1/monitor/overview/top10"
- "GET:/api/v1/monitor/overview/summary"
- name: workspace
cname: 工作空间
value: 'workspace'
+8
View File
@@ -4,12 +4,15 @@ system:
permits:
- system.api_market.service_classification.manager
- system.api_market.service_classification.view
- system.dashboard.run_view.view
- system.devops.cluster.manager
- system.devops.cluster.view
- system.devops.log_configuration.manager
- system.devops.log_configuration.view
- system.devops.ssl_certificate.manager
- system.devops.ssl_certificate.view
- system.devops.monitor.manager
- system.devops.monitor.view
- system.organization.member.manager
- system.organization.member.view
- system.organization.role.view_system_role
@@ -36,12 +39,15 @@ system:
permits:
- system.api_market.service_classification.manager
- system.api_market.service_classification.view
- system.dashboard.run_view.view
- system.devops.cluster.manager
- system.devops.cluster.view
- system.devops.log_configuration.manager
- system.devops.log_configuration.view
- system.devops.ssl_certificate.manager
- system.devops.ssl_certificate.view
- system.devops.monitor.manager
- system.devops.monitor.view
- system.workspace.api_market.view
- system.workspace.application.view_all
- system.workspace.service.view_all
@@ -58,6 +64,7 @@ system:
- system.devops.cluster.view
- system.devops.log_configuration.view
- system.devops.ssl_certificate.view
- system.devops.monitor.view
- system.organization.member.view
- system.organization.role.view_system_role
- system.organization.role.view_team_role
@@ -66,6 +73,7 @@ system:
- system.workspace.application.view_all
- system.workspace.service.view_all
- system.workspace.team.view_all
- system.dashboard.run_view.view
team:
- name: team_admin
cname: 团队管理员
+70
View File
@@ -0,0 +1,70 @@
package api_doc
import (
"context"
"errors"
"github.com/APIParkLab/APIPark/service/universally/commit"
"github.com/APIParkLab/APIPark/stores/api"
"github.com/eolinker/go-common/utils"
"gorm.io/gorm"
"time"
)
var (
_ IAPIDocService = (*imlAPIDocService)(nil)
)
type imlAPIDocService struct {
store api.IAPIDocStore `autowired:""`
commitService commit.ICommitWithKeyService[DocCommit] `autowired:""`
}
func (i *imlAPIDocService) UpdateDoc(ctx context.Context, serviceId string, input *UpdateDoc) error {
// 校验内容格式是否正确
if err := ValidDoc(input.Content); err != nil {
return err
}
info, err := i.store.First(ctx, map[string]interface{}{
"service": serviceId,
})
operator := utils.UserId(ctx)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
return err
}
return i.store.Insert(ctx, &api.Doc{
UUID: input.ID,
Service: serviceId,
Content: input.Content,
Updater: operator,
UpdateAt: time.Now(),
})
}
info.Updater = operator
info.UpdateAt = time.Now()
return i.store.Save(ctx, info)
}
func (i *imlAPIDocService) GetDoc(ctx context.Context, serviceId string) (*Doc, error) {
info, err := i.store.First(ctx, map[string]interface{}{
"service": serviceId,
})
if err != nil {
return nil, err
}
return &Doc{
Id: info.UUID,
Service: info.Service,
Content: info.Content,
Updater: info.Updater,
UpdateAt: info.UpdateAt,
}, nil
}
func (i *imlAPIDocService) LatestDocCommit(ctx context.Context, serviceId string) (*commit.Commit[DocCommit], error) {
return i.commitService.Latest(ctx, serviceId)
}
func (i *imlAPIDocService) CommitDoc(ctx context.Context, serviceId string, data *DocCommit) error {
return i.commitService.Save(ctx, serviceId, data)
}
+21
View File
@@ -0,0 +1,21 @@
package api_doc
import "time"
type UpdateDoc struct {
ID string
Service string
Content string
}
type Doc struct {
Id string
Service string
Content string
Updater string
UpdateAt time.Time
}
type DocCommit struct {
Content string `json:"content"`
}
+82
View File
@@ -0,0 +1,82 @@
package api_doc
import (
"context"
"fmt"
"github.com/APIParkLab/APIPark/service/universally/commit"
"github.com/eolinker/go-common/autowire"
"github.com/getkin/kin-openapi/openapi3"
"reflect"
)
type IAPIDocService interface {
// UpdateDoc 更新文档
UpdateDoc(ctx context.Context, serviceId string, input *UpdateDoc) error
// GetDoc 获取文档
GetDoc(ctx context.Context, serviceId string) (*Doc, error)
// LatestDocCommit 获取最新文档
LatestDocCommit(ctx context.Context, serviceId string) (*commit.Commit[DocCommit], error)
CommitDoc(ctx context.Context, serviceId string, data *DocCommit) error
}
func init() {
autowire.Auto[IAPIDocService](func() reflect.Value {
return reflect.ValueOf(new(imlAPIDocService))
})
commit.InitCommitWithKeyService[DocCommit]("service", "api_doc")
}
var (
loader = openapi3.NewLoader()
)
func ValidDoc(content string) error {
doc, err := loader.LoadFromData([]byte(content))
if err != nil {
return fmt.Errorf("failed to load OpenAPI document: %v", err)
}
err = doc.Validate(loader.Context)
if err != nil {
return fmt.Errorf("OpenAPI document is not valid: %v", err)
}
return nil
}
func DocAPICount(content string) (int64, error) {
doc, err := loader.LoadFromData([]byte(content))
if err != nil {
return 0, err
}
if doc.Paths == nil {
return 0, nil
}
var count int64
for _, item := range doc.Paths.Map() {
if item.Get != nil {
count++
}
if item.Post != nil {
count++
}
if item.Put != nil {
count++
}
if item.Patch != nil {
count++
}
if item.Delete != nil {
count++
}
if item.Head != nil {
count++
}
if item.Options != nil {
count++
}
if item.Trace != nil {
count++
}
}
return count, nil
}
+29 -97
View File
@@ -5,18 +5,18 @@ import (
"errors"
"fmt"
"time"
"github.com/google/uuid"
"gorm.io/gorm"
"github.com/APIParkLab/APIPark/service/universally/commit"
"github.com/APIParkLab/APIPark/stores/api"
"github.com/eolinker/go-common/utils"
"github.com/eolinker/go-common/auto"
"github.com/APIParkLab/APIPark/service/universally"
)
@@ -27,15 +27,13 @@ var (
type HistoryType string
const (
HistoryDocument HistoryType = "doc"
HistoryProxy HistoryType = "proxy"
HistoryProxy HistoryType = "proxy"
)
type imlAPIService struct {
store api.IApiBaseStore `autowired:""`
apiInfoStore api.IAPIInfoStore `autowired:""`
proxyCommitService commit.ICommitWithKeyService[Proxy] `autowired:""`
documentCommitService commit.ICommitWithKeyService[Document] `autowired:""`
store api.IApiBaseStore `autowired:""`
apiInfoStore api.IAPIInfoStore `autowired:""`
proxyCommitService commit.ICommitWithKeyService[Proxy] `autowired:""`
universally.IServiceGet[API]
universally.IServiceDelete
}
@@ -62,69 +60,28 @@ func (i *imlAPIService) ListInfoForService(ctx context.Context, serviceId string
if err != nil {
return nil, err
}
return utils.SliceToSlice(list, func(info *api.Info) *Info {
return &Info{
UUID: info.UUID,
Name: info.Name,
Description: info.Description,
CreateAt: info.CreateAt,
UpdateAt: info.UpdateAt,
Service: info.Service,
Team: info.Team,
Creator: info.Creator,
Updater: info.Updater,
Method: info.Method,
Path: info.Path,
Match: info.Match,
}
}), nil
return utils.SliceToSlice(list, FromEntityInfo), nil
}
func (i *imlAPIService) ListInfo(ctx context.Context, aids ...string) ([]*Info, error) {
list, err := i.apiInfoStore.List(ctx, map[string]interface{}{
"uuid": aids,
})
w := map[string]interface{}{}
if len(aids) > 0 {
w["uuid"] = aids
}
list, err := i.apiInfoStore.List(ctx, w)
if err != nil {
return nil, err
}
return utils.SliceToSlice(list, func(info *api.Info) *Info {
return &Info{
UUID: info.UUID,
Name: info.Name,
Description: info.Description,
CreateAt: info.CreateAt,
UpdateAt: info.UpdateAt,
Service: info.Service,
Team: info.Team,
Creator: info.Creator,
Updater: info.Updater,
Method: info.Method,
Path: info.Path,
Match: info.Match,
}
}), nil
return utils.SliceToSlice(list, FromEntityInfo), nil
}
func (i *imlAPIService) GetInfo(ctx context.Context, aid string) (*Info, error) {
info, err := i.apiInfoStore.GetByUUID(ctx, aid)
if err != nil {
return nil, err
}
return &Info{
UUID: info.UUID,
Name: info.Name,
Description: info.Description,
CreateAt: info.CreateAt,
UpdateAt: info.UpdateAt,
Service: info.Service,
Team: info.Team,
Creator: info.Creator,
Updater: info.Updater,
Method: info.Method,
Path: info.Path,
Match: info.Match,
}, nil
return FromEntityInfo(info), nil
}
func (i *imlAPIService) Save(ctx context.Context, id string, model *EditAPI) error {
@@ -139,9 +96,6 @@ func (i *imlAPIService) Save(ctx context.Context, id string, model *EditAPI) err
if model.Name != nil {
ev.Name = *model.Name
}
//if model.Upstream != nil {
// ev.Upstream = *model.Upstream
//}
if model.Description != nil {
ev.Description = *model.Description
}
@@ -150,7 +104,7 @@ func (i *imlAPIService) Save(ctx context.Context, id string, model *EditAPI) err
return e
}
return i.store.SetLabels(ctx, ev.Id, getLabels(ev)...)
})
}
func getLabels(input *api.Info, appends ...string) []string {
@@ -171,7 +125,7 @@ func (i *imlAPIService) Create(ctx context.Context, input *CreateAPI) (err error
return err
}
}
if t != nil {
return fmt.Errorf("method(%s),path(%s) is exist", input.Method, input.Path)
}
@@ -183,11 +137,11 @@ func (i *imlAPIService) Create(ctx context.Context, input *CreateAPI) (err error
if a != nil {
return fmt.Errorf("api(%s) is exist", input.UUID)
}
} else {
input.UUID = uuid.NewString()
}
ne := api.Api{
Id: 0,
UUID: input.UUID,
@@ -235,10 +189,6 @@ func (i *imlAPIService) ListProxyCommit(ctx context.Context, commitId ...string)
return i.proxyCommitService.List(ctx, commitId...)
}
func (i *imlAPIService) ListDocumentCommit(ctx context.Context, commitId ...string) ([]*commit.Commit[Document], error) {
return i.documentCommitService.List(ctx, commitId...)
}
func (i *imlAPIService) CountByService(ctx context.Context, service string) (int64, error) {
return i.store.CountWhere(ctx, map[string]interface{}{
"service": service,
@@ -273,41 +223,23 @@ func (i *imlAPIService) listForService(ctx context.Context, serviceId string, is
return i.store.ListQuery(ctx, "service=? and is_delete=?", []interface{}{serviceId, isDelete}, "id")
}
func (i *imlAPIService) ListLatestCommitProxy(ctx context.Context, apiUUID ...string) ([]*commit.Commit[Proxy], error) {
return i.proxyCommitService.ListLatest(ctx, apiUUID...)
}
func (i *imlAPIService) ListLatestCommitDocument(ctx context.Context, apiUUID ...string) ([]*commit.Commit[Document], error) {
return i.documentCommitService.ListLatest(ctx, apiUUID...)
}
func (i *imlAPIService) LatestProxy(ctx context.Context, aid string) (*commit.Commit[Proxy], error) {
return i.proxyCommitService.Latest(ctx, aid)
}
func (i *imlAPIService) LatestDocument(ctx context.Context, aid string) (*commit.Commit[Document], error) {
return i.documentCommitService.Latest(ctx, aid)
return i.proxyCommitService.Latest(ctx, aid)
}
func (i *imlAPIService) GetProxyCommit(ctx context.Context, commitId string) (*commit.Commit[Proxy], error) {
return i.proxyCommitService.Get(ctx, commitId)
}
func (i *imlAPIService) GetDocumentCommit(ctx context.Context, commitId string) (*commit.Commit[Document], error) {
return i.documentCommitService.Get(ctx, commitId)
}
func (i *imlAPIService) SaveProxy(ctx context.Context, aid string, data *Proxy) error {
return i.proxyCommitService.Save(ctx, aid, data)
}
func (i *imlAPIService) SaveDocument(ctx context.Context, aid string, data *Document) error {
return i.documentCommitService.Save(ctx, aid, data)
return i.proxyCommitService.Save(ctx, aid, data)
}
func (i *imlAPIService) GetLabels(ctx context.Context, ids ...string) map[string]string {
@@ -325,8 +257,8 @@ func (i *imlAPIService) GetLabels(ctx context.Context, ids ...string) map[string
func (i *imlAPIService) OnComplete() {
i.IServiceGet = universally.NewGetSoftDelete[API, api.Api](i.store, FromEntity)
i.IServiceDelete = universally.NewSoftDelete[api.Api](i.store)
auto.RegisterService("api", i)
}
+65 -20
View File
@@ -1,22 +1,26 @@
package api
import (
"encoding/json"
"net/http"
"strings"
"time"
"github.com/APIParkLab/APIPark/model/plugin_model"
"github.com/APIParkLab/APIPark/stores/api"
)
type API struct {
UUID string
Service string
Team string
Creator string
Method string
Path string
CreateAt time.Time
IsDelete bool
UUID string
Service string
Team string
Creator string
Method []string
Path string
Protocols []string
CreateAt time.Time
IsDelete bool
}
type Info struct {
@@ -29,22 +33,63 @@ type Info struct {
Team string
Creator string
Updater string
Upstream string
Method string
Methods []string
Protocols []string
Path string
Match string
Disable bool
}
func FromEntity(e *api.Api) *API {
methods := make([]string, 0)
if e.Method != "" {
err := json.Unmarshal([]byte(e.Method), &methods)
if err != nil {
m := strings.ToUpper(e.Method)
if m == http.MethodGet || m == http.MethodPost || m == http.MethodPut || m == http.MethodDelete || m == http.MethodPatch || m == http.MethodHead || m == http.MethodOptions {
methods = append(methods, m)
}
}
}
return &API{
UUID: e.UUID,
CreateAt: e.CreateAt,
IsDelete: e.IsDelete != 0,
Service: e.Service,
Team: e.Team,
Creator: e.Creator,
Method: e.Method,
Path: e.Path,
UUID: e.UUID,
CreateAt: e.CreateAt,
IsDelete: e.IsDelete != 0,
Service: e.Service,
Team: e.Team,
Creator: e.Creator,
Method: methods,
Path: e.Path,
Protocols: e.Protocol,
}
}
func FromEntityInfo(e *api.Info) *Info {
methods := make([]string, 0)
if e.Method != "" {
err := json.Unmarshal([]byte(e.Method), &methods)
if err != nil {
m := strings.ToUpper(e.Method)
if m == http.MethodGet || m == http.MethodPost || m == http.MethodPut || m == http.MethodDelete || m == http.MethodPatch || m == http.MethodHead || m == http.MethodOptions {
methods = append(methods, m)
}
}
}
return &Info{
UUID: e.UUID,
Name: e.Name,
Description: e.Description,
CreateAt: e.CreateAt,
UpdateAt: e.UpdateAt,
Service: e.Service,
Team: e.Team,
Creator: e.Creator,
Updater: e.Updater,
Methods: methods,
Protocols: e.Protocol,
Path: e.Path,
Match: e.Match,
Disable: e.Disable,
}
}
+4 -9
View File
@@ -3,9 +3,9 @@ package api
import (
"context"
"reflect"
"github.com/APIParkLab/APIPark/service/universally/commit"
"github.com/APIParkLab/APIPark/service/universally"
"github.com/eolinker/go-common/autowire"
)
@@ -21,15 +21,10 @@ type IAPIService interface {
ListInfo(ctx context.Context, aids ...string) ([]*Info, error)
ListInfoForService(ctx context.Context, serviceId string) ([]*Info, error)
ListLatestCommitProxy(ctx context.Context, aid ...string) ([]*commit.Commit[Proxy], error)
ListLatestCommitDocument(ctx context.Context, aid ...string) ([]*commit.Commit[Document], error)
LatestProxy(ctx context.Context, aid string) (*commit.Commit[Proxy], error)
LatestDocument(ctx context.Context, aid string) (*commit.Commit[Document], error)
GetProxyCommit(ctx context.Context, commitId string) (*commit.Commit[Proxy], error)
ListProxyCommit(ctx context.Context, commitId ...string) ([]*commit.Commit[Proxy], error)
GetDocumentCommit(ctx context.Context, commitId string) (*commit.Commit[Document], error)
ListDocumentCommit(ctx context.Context, commitId ...string) ([]*commit.Commit[Document], error)
SaveProxy(ctx context.Context, aid string, data *Proxy) error
SaveDocument(ctx context.Context, aid string, data *Document) error
Save(ctx context.Context, id string, model *EditAPI) error
Create(ctx context.Context, input *CreateAPI) (err error)
}
@@ -42,7 +37,7 @@ func init() {
autowire.Auto[IAPIService](func() reflect.Value {
return reflect.ValueOf(new(imlAPIService))
})
commit.InitCommitWithKeyService[Proxy]("api", string(HistoryProxy))
commit.InitCommitWithKeyService[Document]("api", string(HistoryDocument))
}
+65 -16
View File
@@ -3,35 +3,85 @@ package service_doc
import (
"context"
"errors"
"github.com/APIParkLab/APIPark/service/universally/commit"
"time"
"github.com/eolinker/go-common/utils"
"gorm.io/gorm"
"github.com/APIParkLab/APIPark/stores/service"
)
var _ IDocService = (*imlDocService)(nil)
type imlDocService struct {
store service.IServiceDocStore `autowired:""`
store service.IServiceDocStore `autowired:""`
commitService commit.ICommitWithKeyService[DocCommit] `autowired:""`
}
func (i *imlDocService) LatestDocCommit(ctx context.Context, serviceId string) (*commit.Commit[DocCommit], error) {
return i.commitService.Latest(ctx, serviceId)
}
func (i *imlDocService) CommitDoc(ctx context.Context, serviceId string, data *DocCommit) error {
return i.commitService.Save(ctx, serviceId, data)
}
func (i *imlDocService) List(ctx context.Context, sids ...string) ([]*Doc, error) {
w := map[string]interface{}{}
if len(sids) > 0 {
w["sid"] = sids
}
list, err := i.store.List(ctx, w)
if err != nil {
return nil, err
}
return utils.SliceToSlice(list, func(d *service.Doc) *Doc {
return &Doc{
ID: d.Sid,
Creator: d.Creator,
Updater: d.Updater,
Doc: d.Doc,
UpdateTime: d.UpdateAt,
CreateTime: d.CreateAt,
}
}), nil
}
func (i *imlDocService) Map(ctx context.Context, sids ...string) (map[string]*Doc, error) {
w := map[string]interface{}{}
if len(sids) > 0 {
w["sid"] = sids
}
list, err := i.store.List(ctx, w)
if err != nil {
return nil, err
}
return utils.SliceToMapO(list, func(d *service.Doc) (string, *Doc) {
return d.Sid, &Doc{
ID: d.Sid,
Creator: d.Creator,
Updater: d.Updater,
Doc: d.Doc,
UpdateTime: d.UpdateAt,
CreateTime: d.CreateAt,
}
}), nil
}
func (i *imlDocService) Save(ctx context.Context, input *SaveDoc) error {
info, err := i.Get(ctx, input.Sid)
info, err := i.store.First(ctx, map[string]interface{}{"sid": input.Sid})
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return err
}
userID := utils.UserId(ctx)
if info != nil {
_, err = i.store.Update(ctx, &service.Doc{
Id: info.ID,
Sid: input.Sid,
Doc: input.Doc,
CreateAt: info.CreateTime,
UpdateAt: time.Now(),
Creator: info.Creator,
Updater: userID,
})
return err
info.Doc = input.Doc
info.Updater = userID
info.UpdateAt = time.Now()
return i.store.Save(ctx, info)
}
return i.store.Insert(ctx, &service.Doc{
Sid: input.Sid,
@@ -49,8 +99,7 @@ func (i *imlDocService) Get(ctx context.Context, sid string) (*Doc, error) {
return nil, err
}
return &Doc{
ID: doc.Id,
DocID: doc.Sid,
ID: doc.Sid,
Creator: doc.Creator,
Updater: doc.Updater,
Doc: doc.Doc,
+5 -3
View File
@@ -3,9 +3,7 @@ package service_doc
import "time"
type Doc struct {
ID int64
DocID string
Name string
ID string
Creator string
Updater string
Doc string
@@ -17,3 +15,7 @@ type SaveDoc struct {
Sid string
Doc string
}
type DocCommit struct {
Content string `json:"content"`
}
+11
View File
@@ -2,6 +2,7 @@ package service_doc
import (
"context"
"github.com/APIParkLab/APIPark/service/universally/commit"
"reflect"
"github.com/eolinker/go-common/autowire"
@@ -10,10 +11,20 @@ import (
type IDocService interface {
Get(ctx context.Context, sid string) (*Doc, error)
Save(ctx context.Context, input *SaveDoc) error
List(ctx context.Context, sids ...string) ([]*Doc, error)
Map(ctx context.Context, sids ...string) (map[string]*Doc, error)
IDocCommitService
}
type IDocCommitService interface {
LatestDocCommit(ctx context.Context, serviceId string) (*commit.Commit[DocCommit], error)
CommitDoc(ctx context.Context, serviceId string, data *DocCommit) error
}
func init() {
autowire.Auto[IDocService](func() reflect.Value {
return reflect.ValueOf(new(imlDocService))
})
commit.InitCommitWithKeyService[DocCommit]("service", "service_doc")
}
+2 -7
View File
@@ -186,6 +186,7 @@ func (i *imlSubscribeService) uniquestHandler(t *CreateSubscribe) []map[string]i
func (i *imlSubscribeService) createEntityHandler(t *CreateSubscribe) *subscribe.Subscribe {
return &subscribe.Subscribe{
UUID: t.Uuid,
Name: t.Uuid,
Application: t.Application,
Service: t.Service,
From: t.From,
@@ -196,16 +197,9 @@ func (i *imlSubscribeService) createEntityHandler(t *CreateSubscribe) *subscribe
}
func (i *imlSubscribeService) updateHandler(e *subscribe.Subscribe, t *UpdateSubscribe) {
//if t.Approver != nil {
// e.Approver = *t.Approver
//}
if t.ApplyStatus != nil {
e.ApplyStatus = *t.ApplyStatus
}
//if t.ApplyID != nil {
// e.ApplyID = *t.ApplyID
//}
}
var (
@@ -274,6 +268,7 @@ func (i *imlSubscribeApplyService) createEntityHandler(t *CreateApply) *subscrib
now := time.Now()
return &subscribe.Apply{
Uuid: t.Uuid,
Name: t.Uuid,
Service: t.Service,
Team: t.Team,
Application: t.Application,
+23 -3
View File
@@ -3,12 +3,12 @@ package tag
import (
"context"
"time"
"github.com/eolinker/go-common/auto"
"github.com/eolinker/go-common/utils"
"github.com/APIParkLab/APIPark/stores/tag"
"github.com/APIParkLab/APIPark/service/universally"
)
@@ -23,6 +23,26 @@ type imlTagService struct {
universally.IServiceCreate[CreateTag]
}
func (i *imlTagService) Map(ctx context.Context, ids ...string) (map[string]*Tag, error) {
w := make(map[string]interface{})
if len(ids) > 0 {
w["uuid"] = ids
}
list, err := i.store.List(ctx, w)
if err != nil {
return nil, err
}
return utils.SliceToMapO(list, func(i *tag.Tag) (string, *Tag) {
return i.UUID, &Tag{
Id: i.UUID,
Name: i.Name,
CreateTime: i.CreateAt,
UpdateTime: i.UpdateAt,
}
}), nil
}
func (i *imlTagService) GetLabels(ctx context.Context, ids ...string) map[string]string {
if len(ids) == 0 {
return nil
+3 -1
View File
@@ -1,8 +1,9 @@
package tag
import (
"context"
"reflect"
"github.com/APIParkLab/APIPark/service/universally"
"github.com/eolinker/go-common/autowire"
)
@@ -11,6 +12,7 @@ type ITagService interface {
universally.IServiceGet[Tag]
universally.IServiceDelete
universally.IServiceCreate[CreateTag]
Map(ctx context.Context, ids ...string) (map[string]*Tag, error)
}
func init() {
+1 -1
View File
@@ -45,7 +45,7 @@ func (s *imlServiceGet[T, E]) Get(ctx context.Context, uuid string) (*T, error)
return nil, err
}
if v == nil || errors.Is(err, gorm.ErrRecordNotFound) {
return nil, errors.New("not found")
return nil, gorm.ErrRecordNotFound
}
return s.toModelHandler(v), nil
+41 -12
View File
@@ -4,7 +4,7 @@ import (
"context"
"errors"
"time"
"github.com/APIParkLab/APIPark/service/universally/commit"
"github.com/APIParkLab/APIPark/stores/upstream"
"github.com/eolinker/go-common/autowire"
@@ -21,14 +21,43 @@ type imlUpstreamService struct {
commitService commit.ICommitService[Config] `autowired:""`
}
func (i *imlUpstreamService) List(ctx context.Context, serviceIds ...string) ([]*Upstream, error) {
w := make(map[string]interface{})
if len(serviceIds) > 0 {
w["service"] = serviceIds
}
upstreams, err := i.store.List(ctx, w)
if err != nil {
return nil, err
}
return utils.SliceToSlice(upstreams, func(u *upstream.Upstream) *Upstream {
return &Upstream{
Item: &Item{
UUID: u.UUID,
Service: u.Service,
Team: u.Team,
Remark: u.Remark,
Creator: u.Creator,
Updater: u.Updater,
CreateTime: u.CreateAt,
UpdateTime: u.UpdateAt,
},
}
}), nil
}
func (i *imlUpstreamService) ListCommit(ctx context.Context, uuid ...string) ([]*commit.Commit[Config], error) {
return i.commitService.List(ctx, uuid...)
}
func (i *imlUpstreamService) ListLatestCommit(ctx context.Context, project string) ([]*commit.Commit[Config], error) {
upstreams, err := i.store.List(ctx, map[string]interface{}{
"project": project,
})
func (i *imlUpstreamService) ListLatestCommit(ctx context.Context, serviceIds ...string) ([]*commit.Commit[Config], error) {
w := make(map[string]interface{})
if len(serviceIds) > 0 {
w["service"] = serviceIds
}
upstreams, err := i.store.List(ctx, w)
if err != nil {
return nil, err
}
@@ -39,16 +68,16 @@ func (i *imlUpstreamService) ListLatestCommit(ctx context.Context, project strin
return u.UUID
})
return i.commitService.ListLatest(ctx, targetId...)
}
func (i *imlUpstreamService) GetCommit(ctx context.Context, uuid string) (*commit.Commit[Config], error) {
return i.commitService.Get(ctx, uuid)
}
func (i *imlUpstreamService) LatestCommit(ctx context.Context, uid string, partition string) (*commit.Commit[Config], error) {
return i.commitService.Latest(ctx, uid, partition)
func (i *imlUpstreamService) LatestCommit(ctx context.Context, uid string, clusterId string) (*commit.Commit[Config], error) {
return i.commitService.Latest(ctx, uid, clusterId)
}
func (i *imlUpstreamService) SaveCommit(ctx context.Context, uid string, partition string, cfg *Config) error {
@@ -64,11 +93,11 @@ func (i *imlUpstreamService) Get(ctx context.Context, id string) (*Upstream, err
if err != nil {
return nil, err
}
return &Upstream{
Item: &Item{
UUID: t.UUID,
Project: t.Project,
Service: t.Service,
Team: t.Team,
Remark: t.Remark,
Creator: t.Creator,
@@ -85,7 +114,7 @@ func (i *imlUpstreamService) Save(ctx context.Context, u *SaveUpstream) error {
return i.store.Save(ctx, &upstream.Upstream{
UUID: u.UUID,
Name: u.Name,
Project: u.Project,
Service: u.Service,
Team: u.Team,
Remark: u.Remark,
Creator: userId,
+3 -4
View File
@@ -8,7 +8,7 @@ type Item struct {
UUID string
Name string
Type string
Project string
Service string
Team string
Creator string
Updater string
@@ -24,10 +24,9 @@ type Upstream struct {
type SaveUpstream struct {
UUID string
Name string
Project string
Service string
Team string
//Type string
Remark string
Remark string
}
type ProxyHeader struct {
+5 -4
View File
@@ -3,7 +3,7 @@ package upstream
import (
"context"
"reflect"
"github.com/APIParkLab/APIPark/service/universally/commit"
"github.com/eolinker/go-common/autowire"
)
@@ -12,8 +12,9 @@ type IUpstreamService interface {
Get(ctx context.Context, id string) (*Upstream, error)
Save(ctx context.Context, upstream *SaveUpstream) error
Delete(ctx context.Context, id string) error
LatestCommit(ctx context.Context, uid string, partition string) (*commit.Commit[Config], error)
ListLatestCommit(ctx context.Context, project string) ([]*commit.Commit[Config], error)
List(ctx context.Context, serviceIds ...string) ([]*Upstream, error)
LatestCommit(ctx context.Context, uid string, clusterId string) (*commit.Commit[Config], error)
ListLatestCommit(ctx context.Context, serviceIds ...string) ([]*commit.Commit[Config], error)
SaveCommit(ctx context.Context, uid string, partition string, cfg *Config) error
GetCommit(ctx context.Context, uuid string) (*commit.Commit[Config], error)
ListCommit(ctx context.Context, uuid ...string) ([]*commit.Commit[Config], error)
@@ -24,5 +25,5 @@ func init() {
return reflect.ValueOf(new(imlUpstreamService))
})
commit.InitCommitService[Config]("upstream")
}
+11
View File
@@ -15,6 +15,14 @@ type imlApiBaseStore struct {
store.SearchStoreSoftDelete[Api]
}
type imlAPIDocStore struct {
store.Store[Doc]
}
type IAPIDocStore interface {
store.IBaseStore[Doc]
}
func init() {
autowire.Auto[IApiBaseStore](func() reflect.Value {
@@ -23,4 +31,7 @@ func init() {
autowire.Auto[IAPIInfoStore](func() reflect.Value {
return reflect.ValueOf(new(store.Store[Info]))
})
autowire.Auto[IAPIDocStore](func() reflect.Value {
return reflect.ValueOf(new(imlAPIDocStore))
})
}
+13 -1
View File
@@ -13,6 +13,7 @@ type Api struct {
CreateAt time.Time `gorm:"type:timestamp;NOT NULL;DEFAULT:CURRENT_TIMESTAMP;column:create_at;comment:创建时间"`
IsDelete int `gorm:"type:tinyint(1);not null;column:is_delete;comment:是否删除 0:未删除 1:已删除"`
Method string `gorm:"size:36;not null;column:method;comment:请求方法"`
Protocol []string `gorm:"type:text;not null;column:protocol;comment:协议;serializer:json"`
Path string `gorm:"size:512;not null;column:path;comment:请求路径"`
}
type Info struct {
@@ -22,13 +23,15 @@ type Info struct {
Description string `gorm:"size:255;not null;column:description;comment:description"`
Service string `gorm:"size:36;not null;column:service;comment:服务;index:service"`
Team string `gorm:"size:36;not null;column:team;comment:团队;index:team"` // 团队id
Method string `gorm:"size:36;not null;column:method;comment:请求方法"`
Method string `gorm:"size:36;not null;column:method;comment:请求方法" `
Path string `gorm:"size:512;not null;column:path;comment:请求路径"`
Protocol []string `gorm:"type:text;null;column:protocol;comment:协议;serializer:json"`
Match string `gorm:"type:text;null;column:match;comment:匹配规则"`
Creator string `gorm:"size:36;not null;column:creator;comment:创建人;index:creator" aovalue:"creator"` // 创建人
CreateAt time.Time `gorm:"type:timestamp;NOT NULL;DEFAULT:CURRENT_TIMESTAMP;column:create_at;comment:创建时间"`
Updater string `gorm:"size:36;not null;column:updater;comment:更新人;index:updater" aovalue:"updater"` // 更新人
UpdateAt time.Time `gorm:"type:timestamp;NOT NULL;DEFAULT:CURRENT_TIMESTAMP;column:update_at;comment:更新时间"`
Disable bool `gorm:"type:tinyint(1);not null;column:disable;comment:是否禁用 0:否 1:是"`
}
func (i *Info) TableName() string {
@@ -45,3 +48,12 @@ func (a *Api) IdValue() int64 {
func (a *Api) TableName() string {
return "api"
}
type Doc struct {
Id int64 `gorm:"column:id;type:BIGINT(20);AUTO_INCREMENT;NOT NULL;comment:id;primary_key;comment:主键ID;"`
UUID string `gorm:"type:varchar(36);not null;column:uuid;uniqueIndex:uuid;comment:UUID;"`
Service string `gorm:"size:36;not null;column:service;comment:服务;index:service"`
Content string `gorm:"type:text;null;column:content;comment:文档内容"`
Updater string `gorm:"size:36;not null;column:updater;comment:更新人;index:updater" aovalue:"updater"`
UpdateAt time.Time `gorm:"type:timestamp;NOT NULL;DEFAULT:CURRENT_TIMESTAMP;column:update_at;comment:更新时间"`
}
+3 -1
View File
@@ -5,6 +5,7 @@ import "time"
type Subscribe struct {
Id int64 `gorm:"column:id;type:BIGINT(20);AUTO_INCREMENT;NOT NULL;comment:id;primary_key;comment:主键ID;"`
UUID string `gorm:"size:36;not null;column:uuid;comment:uuid;uniqueIndex:uuid;"`
Name string `gorm:"size:36;not null;column:name;comment:名称"`
Service string `gorm:"size:36;not null;column:service;comment:服务id;uniqueIndex:unique_subscribe"`
Application string `gorm:"size:36;not null;column:application;comment:应用id,项目id,系统id;uniqueIndex:unique_subscribe"`
ApplyStatus int `gorm:"type:tinyint(1);not null;column:apply_status;comment:申请状态;index:status;"`
@@ -24,7 +25,8 @@ func (s *Subscribe) TableName() string {
type Apply struct {
Id int64 `gorm:"column:id;type:BIGINT(20);NOT NULL;comment:id;primary_key;comment:主键ID;"`
Uuid string `gorm:"size:36;not null;column:uuid;comment:uuid;uniqueIndex:uuid;"` // uuid
Uuid string `gorm:"size:36;not null;column:uuid;comment:uuid;uniqueIndex:uuid;"` // uuid
Name string `gorm:"size:36;not null;column:name;comment:名称"`
Service string `gorm:"size:36;not null;column:service;comment:服务id;index:service"` // 服务id
Team string `gorm:"size:36;not null;column:team;comment:团队id;index:team;"` // 团队id
Application string `gorm:"size:36;not null;column:application;comment:应用id,项目id,系统id;index:application"` // 订阅应用id
+1 -1
View File
@@ -8,7 +8,7 @@ type Upstream struct {
Id int64 `gorm:"column:id;type:BIGINT(20);AUTO_INCREMENT;NOT NULL;comment:id;primary_key;comment:主键ID;"`
UUID string `gorm:"type:varchar(36);not null;column:uuid;uniqueIndex:uuid;comment:UUID;"`
Name string `gorm:"size:255;not null;column:name;comment:名称"`
Project string `gorm:"size:36;not null;column:project;comment:项目;index:project;"` // 项目id
Service string `gorm:"size:36;not null;column:service;comment:项目;index:service;"` // 服务id
Team string `gorm:"size:36;not null;column:team;comment:团队;index:team;"` // 团队id
Remark string `gorm:"size:255;not null;column:remark;comment:备注"`
Creator string `gorm:"size:36;not null;column:creator;comment:创建人;index:creator;"` // 创建人