mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-04 10:13:53 +08:00
发布初始提交
This commit is contained in:
@@ -25,7 +25,8 @@ type ServiceDetail struct {
|
||||
Description string `json:"description"`
|
||||
Document string `json:"document"`
|
||||
Basic *ServiceBasic `json:"basic"`
|
||||
Apis []*ServiceApi `json:"apis"`
|
||||
//Apis []*ServiceApi `json:"apis"`
|
||||
APIDoc string `json:"api_doc"`
|
||||
}
|
||||
|
||||
type ServiceBasic struct {
|
||||
|
||||
+13
-44
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
api_doc "github.com/APIParkLab/APIPark/service/api-doc"
|
||||
"math"
|
||||
"sort"
|
||||
|
||||
@@ -43,6 +44,7 @@ var (
|
||||
type imlCatalogueModule struct {
|
||||
catalogueService catalogue.ICatalogueService `autowired:""`
|
||||
apiService api.IAPIService `autowired:""`
|
||||
apiDocService api_doc.IAPIDocService `autowired:""`
|
||||
serviceService service.IServiceService `autowired:""`
|
||||
serviceTagService service_tag.ITagService `autowired:""`
|
||||
serviceDocService service_doc.IDocService `autowired:""`
|
||||
@@ -237,46 +239,14 @@ func (i *imlCatalogueModule) ServiceDetail(ctx context.Context, sid string) (*ca
|
||||
apiIds = append(apiIds, v.API)
|
||||
apiMap[v.API] = v
|
||||
}
|
||||
apiList, err := i.apiService.ListInfo(ctx, apiIds...)
|
||||
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,
|
||||
//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
|
||||
// }
|
||||
//}
|
||||
|
||||
apis = append(apis, &catalogue_dto.ServiceApi{
|
||||
ServiceApiBasic: basicApi,
|
||||
//Doc: tmp,
|
||||
})
|
||||
}
|
||||
//apiList, err := i.apiService.ListInfo(ctx, apiIds...)
|
||||
//if err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
//apiNum := 0
|
||||
//if len(docCommits) > 0 {
|
||||
// i.apiDocService.ListDocCommit(ctx,docCommits[0].Commit)
|
||||
//}
|
||||
countMap, err := i.subscribeService.CountMapByService(ctx, subscribe.ApplyStatusSubscribe, sid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -295,8 +265,8 @@ func (i *imlCatalogueModule) ServiceDetail(ctx context.Context, sid string) (*ca
|
||||
Description: s.Description,
|
||||
Document: docStr,
|
||||
Basic: &catalogue_dto.ServiceBasic{
|
||||
Team: auto.UUID(s.Team),
|
||||
ApiNum: len(apis),
|
||||
Team: auto.UUID(s.Team),
|
||||
//ApiNum: len(apis),
|
||||
AppNum: int(countMap[s.Id]),
|
||||
Tags: auto.List(tagIds),
|
||||
Catalogue: auto.UUID(s.Catalogue),
|
||||
@@ -304,7 +274,6 @@ func (i *imlCatalogueModule) ServiceDetail(ctx context.Context, sid string) (*ca
|
||||
UpdateTime: auto.TimeLabel(r.CreateAt),
|
||||
Logo: s.Logo,
|
||||
},
|
||||
Apis: apis,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -334,7 +303,7 @@ func (i *imlCatalogueModule) Services(ctx context.Context, keyword string) ([]*c
|
||||
}
|
||||
|
||||
// 获取服务API数量
|
||||
apiCountMap, err := i.apiService.CountMapByService(ctx, serviceIds...)
|
||||
apiCountMap, err := i.apiDocService.LatestAPICountByServices(ctx, serviceIds...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -23,32 +23,6 @@ type imlTeamPermitModule struct {
|
||||
}
|
||||
|
||||
func (m *imlTeamPermitModule) Permissions(ctx context.Context, teamId string) ([]string, error) {
|
||||
|
||||
//uid := utils.UserId(ctx)
|
||||
//roleMembers, err := m.roleMemberService.List(ctx, role.TeamTarget(teamId), uid)
|
||||
//if err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
//roleIds := utils.SliceToSlice(roleMembers, func(rm *role.Member) string {
|
||||
// return rm.Role
|
||||
//})
|
||||
//if len(roleMembers) == 0 {
|
||||
// return []string{}, nil
|
||||
//}
|
||||
//roles, err := m.roleService.List(ctx, roleIds...)
|
||||
//if err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
//permits := make(map[string]struct{})
|
||||
//for _, r := range roles {
|
||||
// for _, p := range r.Permit {
|
||||
// permits[p] = struct{}{}
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//return utils.MapToSlice(permits, func(k string, v struct{}) string {
|
||||
// return k
|
||||
//}), nil
|
||||
return m.accesses(ctx, teamId)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,17 +3,16 @@ package publish
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
|
||||
"github.com/APIParkLab/APIPark/gateway"
|
||||
|
||||
|
||||
"github.com/APIParkLab/APIPark/module/publish/dto"
|
||||
"github.com/eolinker/go-common/autowire"
|
||||
)
|
||||
|
||||
type IPublishModule interface {
|
||||
CheckPublish(ctx context.Context, serviceId string, releaseId string) (*dto.DiffOut, error)
|
||||
//ReleaseDo(ctx context.Context, serviceId string, input *dto.ApplyOnReleaseInput) error
|
||||
|
||||
|
||||
Apply(ctx context.Context, serviceId string, input *dto.ApplyInput) (*dto.Publish, error)
|
||||
Stop(ctx context.Context, serviceId string, id string) error
|
||||
Refuse(ctx context.Context, serviceId string, id string, commits string) error
|
||||
|
||||
+94
-68
@@ -4,19 +4,19 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/APIParkLab/APIPark/service/api"
|
||||
api_doc "github.com/APIParkLab/APIPark/service/api-doc"
|
||||
"github.com/APIParkLab/APIPark/service/cluster"
|
||||
"github.com/APIParkLab/APIPark/service/release"
|
||||
"github.com/APIParkLab/APIPark/service/service_diff"
|
||||
"github.com/APIParkLab/APIPark/service/universally/commit"
|
||||
"github.com/APIParkLab/APIPark/service/upstream"
|
||||
"github.com/eolinker/go-common/auto"
|
||||
"github.com/eolinker/go-common/utils"
|
||||
)
|
||||
|
||||
type imlServiceDiff struct {
|
||||
apiService api.IAPIService `autowired:""`
|
||||
apiDocService api_doc.IAPIDocService `autowired:""`
|
||||
upstreamService upstream.IUpstreamService `autowired:""`
|
||||
releaseService release.IReleaseService `autowired:""`
|
||||
clusterService cluster.IClusterService `autowired:""`
|
||||
@@ -89,14 +89,29 @@ func (m *imlServiceDiff) DiffForLatest(ctx context.Context, serviceId string, ba
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
request := make([]*commit.Commit[api.Request], 0, len(apiInfos))
|
||||
for _, apiInfo := range apiInfos {
|
||||
request = append(request, &commit.Commit[api.Request]{
|
||||
Target: apiInfo.UUID,
|
||||
Key: "request",
|
||||
Data: &api.Request{
|
||||
Path: apiInfo.Path,
|
||||
Methods: apiInfo.Methods,
|
||||
Protocols: apiInfo.Protocols,
|
||||
Match: apiInfo.Match,
|
||||
Disable: apiInfo.Disable,
|
||||
},
|
||||
})
|
||||
|
||||
}
|
||||
proxy, err := m.apiService.ListLatestCommitProxy(ctx, apiIds...)
|
||||
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
|
||||
//}
|
||||
apiDocCommits, err := m.apiDocService.ListLatestDocCommit(ctx, serviceId)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
upstreamCommits, err := m.upstreamService.ListLatestCommit(ctx, serviceId)
|
||||
if err != nil {
|
||||
@@ -108,11 +123,11 @@ func (m *imlServiceDiff) DiffForLatest(ctx context.Context, serviceId string, ba
|
||||
return nil, false, err
|
||||
}
|
||||
target := &projectInfo{
|
||||
id: serviceId,
|
||||
apis: apiInfos,
|
||||
apiCommits: proxy,
|
||||
//apiDocs: documents,
|
||||
upstreamCommits: upstreamCommits,
|
||||
id: serviceId,
|
||||
apiRequestCommits: request,
|
||||
apiProxyCommits: proxy,
|
||||
apiDocCommits: apiDocCommits,
|
||||
upstreamCommits: upstreamCommits,
|
||||
}
|
||||
clusters, err := m.clusterService.List(ctx)
|
||||
if err != nil {
|
||||
@@ -128,81 +143,91 @@ func (m *imlServiceDiff) getReleaseInfo(ctx context.Context, releaseId string) (
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
apiIds := utils.SliceToSlice(commits, func(i *release.ProjectCommits) string {
|
||||
apiRequestCommitIds := utils.SliceToSlice(commits, func(i *release.ProjectCommits) string {
|
||||
return i.Target
|
||||
}, func(c *release.ProjectCommits) bool {
|
||||
return c.Type == release.CommitApiProxy || c.Type == release.CommitApiDocument
|
||||
return c.Type == release.CommitApiRequest
|
||||
})
|
||||
apiInfos, err := m.apiService.ListInfo(ctx, apiIds...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
apiProxyCommitIds := utils.SliceToSlice(commits, func(i *release.ProjectCommits) string {
|
||||
return i.Commit
|
||||
}, 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 {
|
||||
return c.Type == release.CommitUpstream
|
||||
})
|
||||
proxyCommits, err := m.apiService.ListProxyCommit(ctx, apiProxyCommitIds...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
var requestCommits []*commit.Commit[api.Request]
|
||||
var proxyCommits []*commit.Commit[api.Proxy]
|
||||
var documentCommits []*commit.Commit[api_doc.DocCommit]
|
||||
if len(apiRequestCommitIds) > 0 {
|
||||
requestCommits, err = m.apiService.ListRequestCommit(ctx, apiRequestCommitIds...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
//documentCommits, err := m.apiService.ListDocumentCommit(ctx, apiDocumentCommitIds...)
|
||||
//if err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
if len(apiProxyCommitIds) > 0 {
|
||||
proxyCommits, err = m.apiService.ListProxyCommit(ctx, apiProxyCommitIds...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if len(apiDocumentCommitIds) > 0 {
|
||||
documentCommits, err = m.apiDocService.ListDocCommit(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,
|
||||
upstreamCommits: upstreamCommits,
|
||||
apiRequestCommits: requestCommits,
|
||||
apiProxyCommits: proxyCommits,
|
||||
apiDocCommits: documentCommits,
|
||||
upstreamCommits: upstreamCommits,
|
||||
}, nil
|
||||
}
|
||||
func (m *imlServiceDiff) diff(partitions []string, base, target *projectInfo) *service_diff.Diff {
|
||||
out := &service_diff.Diff{
|
||||
Apis: nil,
|
||||
Upstreams: nil,
|
||||
//Clusters: partitions,
|
||||
}
|
||||
baseApis := utils.NewSet(utils.SliceToSlice(base.apis, func(i *api.Info) string {
|
||||
return i.UUID
|
||||
baseApis := utils.NewSet(utils.SliceToSlice(base.apiRequestCommits, func(i *commit.Commit[api.Request]) string {
|
||||
return i.Target
|
||||
})...)
|
||||
baseApiProxy := utils.SliceToMap(base.apiCommits, func(i *commit.Commit[api.Proxy]) string {
|
||||
baseApiProxy := utils.SliceToMap(base.apiProxyCommits, func(i *commit.Commit[api.Proxy]) string {
|
||||
return i.Target
|
||||
})
|
||||
baseAPIDoc := utils.SliceToMap(base.apiDocs, func(i *commit.Commit[api.Document]) string {
|
||||
baseAPIDoc := utils.SliceToMap(base.apiDocCommits, func(i *commit.Commit[api_doc.DocCommit]) string {
|
||||
return i.Target
|
||||
})
|
||||
|
||||
targetApiProxy := utils.SliceToMap(target.apiCommits, func(i *commit.Commit[api.Proxy]) string {
|
||||
targetApiProxy := utils.SliceToMap(target.apiProxyCommits, func(i *commit.Commit[api.Proxy]) string {
|
||||
return i.Target
|
||||
})
|
||||
targetAPIDoc := utils.SliceToMap(target.apiDocs, func(i *commit.Commit[api.Document]) string {
|
||||
targetAPIDoc := utils.SliceToMap(target.apiDocCommits, func(i *commit.Commit[api_doc.DocCommit]) string {
|
||||
return i.Target
|
||||
})
|
||||
|
||||
for _, apiInfo := range target.apis {
|
||||
apiId := apiInfo.UUID
|
||||
for _, rc := range target.apiRequestCommits {
|
||||
apiId := rc.Target
|
||||
a := &service_diff.ApiDiff{
|
||||
APi: apiInfo.UUID,
|
||||
Name: apiInfo.Name,
|
||||
//Methods: apiInfo.Methods,
|
||||
Path: apiInfo.Path,
|
||||
Status: service_diff.Status{},
|
||||
APi: rc.Target,
|
||||
Method: rc.Data.Methods,
|
||||
Protocol: rc.Data.Protocols,
|
||||
Disable: false,
|
||||
Path: rc.Data.Path,
|
||||
Change: 0,
|
||||
Status: service_diff.Status{},
|
||||
}
|
||||
|
||||
pc, hasPc := targetApiProxy[apiId]
|
||||
@@ -237,15 +262,17 @@ func (m *imlServiceDiff) diff(partitions []string, base, target *projectInfo) *s
|
||||
baseApis.Remove(utils.SliceToSlice(out.Apis, func(i *service_diff.ApiDiff) string {
|
||||
return i.APi
|
||||
})...)
|
||||
for _, apiInfo := range base.apis {
|
||||
if baseApis.Has(apiInfo.UUID) {
|
||||
for _, rc := range base.apiRequestCommits {
|
||||
apiInfo := rc.Data
|
||||
if baseApis.Has(rc.Target) {
|
||||
out.Apis = append(out.Apis, &service_diff.ApiDiff{
|
||||
APi: apiInfo.UUID,
|
||||
Name: apiInfo.Name,
|
||||
//Methods: apiInfo.Methods,
|
||||
Path: apiInfo.Path,
|
||||
Status: service_diff.Status{},
|
||||
Change: service_diff.ChangeTypeDelete,
|
||||
APi: rc.Target,
|
||||
Method: apiInfo.Methods,
|
||||
Protocol: apiInfo.Protocols,
|
||||
Disable: apiInfo.Disable,
|
||||
Path: apiInfo.Path,
|
||||
Change: service_diff.ChangeTypeDelete,
|
||||
Status: service_diff.Status{},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -262,10 +289,9 @@ func (m *imlServiceDiff) diff(partitions []string, base, target *projectInfo) *s
|
||||
key := fmt.Sprintf("%s-%s", target.id, partitionId)
|
||||
o := &service_diff.UpstreamDiff{
|
||||
Upstream: target.id,
|
||||
//Cluster: partitionId,
|
||||
Data: nil,
|
||||
Change: service_diff.ChangeTypeNone,
|
||||
Status: 0,
|
||||
Data: nil,
|
||||
Change: service_diff.ChangeTypeNone,
|
||||
Status: 0,
|
||||
}
|
||||
out.Upstreams = append(out.Upstreams, o)
|
||||
bu, hasBu := baseUpstreamMap[key]
|
||||
@@ -300,14 +326,14 @@ func (m *imlServiceDiff) Out(ctx context.Context, diff *service_diff.Diff) (*Dif
|
||||
}
|
||||
|
||||
out := &DiffOut{}
|
||||
out.Apis = utils.SliceToSlice(diff.Apis, func(i *service_diff.ApiDiff) *ApiDiffOut {
|
||||
return &ApiDiffOut{
|
||||
Api: auto.UUID(i.APi),
|
||||
Name: i.Name,
|
||||
Method: i.Method,
|
||||
Path: i.Path,
|
||||
Change: i.Change,
|
||||
Status: i.Status,
|
||||
out.Routers = utils.SliceToSlice(diff.Apis, func(i *service_diff.ApiDiff) *RouterDiffOut {
|
||||
return &RouterDiffOut{
|
||||
Methods: i.Method,
|
||||
Path: i.Path,
|
||||
Change: i.Change,
|
||||
Status: i.Status,
|
||||
Protocols: i.Protocol,
|
||||
Disable: i.Disable,
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
+16
-43
@@ -2,25 +2,25 @@ package service_diff
|
||||
|
||||
import (
|
||||
"github.com/APIParkLab/APIPark/service/api"
|
||||
api_doc "github.com/APIParkLab/APIPark/service/api-doc"
|
||||
"github.com/APIParkLab/APIPark/service/service_diff"
|
||||
"github.com/APIParkLab/APIPark/service/universally/commit"
|
||||
"github.com/APIParkLab/APIPark/service/upstream"
|
||||
"github.com/eolinker/go-common/auto"
|
||||
)
|
||||
|
||||
type DiffOut struct {
|
||||
Apis []*ApiDiffOut `json:"apis"`
|
||||
Routers []*RouterDiffOut `json:"routers"`
|
||||
Upstreams []*UpstreamDiffOut `json:"upstreams"`
|
||||
}
|
||||
|
||||
type ApiDiffOut struct {
|
||||
Api auto.Label `json:"api,omitempty" aolabel:"api"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Method string `json:"method,omitempty"`
|
||||
Path string `json:"path,omitempty"`
|
||||
//Upstream auto.Label `json:"upstream,omitempty" aolabel:"upstream"`
|
||||
Change service_diff.ChangeType `json:"change,omitempty"`
|
||||
Status service_diff.Status `json:"status,omitempty"`
|
||||
type RouterDiffOut struct {
|
||||
Methods []string `json:"methods,omitempty"`
|
||||
Protocols []string `json:"protocols,omitempty"`
|
||||
Path string `json:"path,omitempty"`
|
||||
Description string `json:"description"`
|
||||
Change service_diff.ChangeType `json:"change,omitempty"`
|
||||
Status service_diff.Status `json:"status,omitempty"`
|
||||
Disable bool `json:"disable,omitempty"`
|
||||
}
|
||||
type UpstreamDiffOut struct {
|
||||
Change service_diff.ChangeType `json:"change,omitempty"`
|
||||
@@ -29,38 +29,11 @@ type UpstreamDiffOut struct {
|
||||
Addr []string `json:"addr,omitempty"`
|
||||
}
|
||||
|
||||
//
|
||||
//func CreateOut(d *project_diff.Diff) *DiffOut {
|
||||
// if d == nil {
|
||||
// return nil
|
||||
// }
|
||||
// return &DiffOut{
|
||||
// Apis: utils.SliceToSlice(d.Apis, func(s *project_diff.ApiDiff) *ApiDiffOut {
|
||||
// return &ApiDiffOut{
|
||||
// Name: s.Name,
|
||||
// Methods: s.Methods,
|
||||
// Path: s.Path,
|
||||
// Upstream: s.Upstream,
|
||||
// Change: s.Change,
|
||||
// }
|
||||
// }),
|
||||
// Upstreams: utils.SliceToSlice(d.Upstreams, func(s *project_diff.UpstreamDiff) *UpstreamDiffOut {
|
||||
// return &UpstreamDiffOut{
|
||||
// Upstream: s.Name,
|
||||
// Cluster: auto.UUID(s.Cluster),
|
||||
// Cluster: auto.UUID(s.Cluster),
|
||||
// Change: s.Change,
|
||||
// Type: s.Type,
|
||||
// Addr: s.Addr,
|
||||
// }
|
||||
// }),
|
||||
// }
|
||||
//}
|
||||
|
||||
type projectInfo struct {
|
||||
id string
|
||||
apis []*api.Info
|
||||
apiCommits []*commit.Commit[api.Proxy]
|
||||
apiDocs []*commit.Commit[api.Document]
|
||||
upstreamCommits []*commit.Commit[upstream.Config]
|
||||
id string
|
||||
//apis []*api.Info
|
||||
apiRequestCommits []*commit.Commit[api.Request]
|
||||
apiProxyCommits []*commit.Commit[api.Proxy]
|
||||
apiDocCommits []*commit.Commit[api_doc.DocCommit]
|
||||
upstreamCommits []*commit.Commit[upstream.Config]
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ type CreateService struct {
|
||||
ServiceType string `json:"service_type"`
|
||||
Logo string `json:"logo"`
|
||||
Tags []string `json:"tags"`
|
||||
Catalogue string `json:"catalogue" aocheck:"catalogue"`
|
||||
Catalogue string `json:"catalogue"`
|
||||
AsApp *bool `json:"as_app"`
|
||||
AsServer *bool `json:"as_server"`
|
||||
}
|
||||
@@ -17,7 +17,7 @@ type EditService struct {
|
||||
Name *string `json:"name"`
|
||||
Description *string `json:"description"`
|
||||
ServiceType *string `json:"service_type"`
|
||||
Catalogue *string `json:"catalogue" aocheck:"catalogue"`
|
||||
Catalogue *string `json:"catalogue"`
|
||||
Logo *string `json:"logo"`
|
||||
Tags *[]string `json:"tags"`
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
api_doc "github.com/APIParkLab/APIPark/service/api-doc"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@@ -50,6 +51,7 @@ type imlServiceModule struct {
|
||||
serviceDocService service_doc.IDocService `autowired:""`
|
||||
serviceTagService service_tag.ITagService `autowired:""`
|
||||
apiService api.IAPIService `autowired:""`
|
||||
apiDocService api_doc.IAPIDocService `autowired:""`
|
||||
transaction store.ITransaction `autowired:""`
|
||||
}
|
||||
|
||||
@@ -141,7 +143,7 @@ func (i *imlServiceModule) SearchMyServices(ctx context.Context, teamId string,
|
||||
serviceIds := utils.SliceToSlice(services, func(p *service.Service) string {
|
||||
return p.Id
|
||||
})
|
||||
apiCountMap, err := i.apiService.CountByGroup(ctx, "", map[string]interface{}{"service": serviceIds}, "service")
|
||||
apiCountMap, err := i.apiDocService.APICountByServices(ctx, serviceIds...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -263,7 +265,7 @@ func (i *imlServiceModule) Search(ctx context.Context, teamID string, keyword st
|
||||
return s.Id
|
||||
})
|
||||
|
||||
apiCountMap, err := i.apiService.CountByGroup(ctx, "", map[string]interface{}{"service": serviceIds}, "service")
|
||||
apiCountMap, err := i.apiDocService.APICountByServices(ctx, serviceIds...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -19,6 +19,38 @@ type imlAPIDocService struct {
|
||||
commitService commit.ICommitWithKeyService[DocCommit] `autowired:""`
|
||||
}
|
||||
|
||||
func (i *imlAPIDocService) ListDocCommit(ctx context.Context, commitIds ...string) ([]*commit.Commit[DocCommit], error) {
|
||||
return i.commitService.List(ctx, commitIds...)
|
||||
}
|
||||
|
||||
func (i *imlAPIDocService) ListLatestDocCommit(ctx context.Context, serviceIds ...string) ([]*commit.Commit[DocCommit], error) {
|
||||
return i.commitService.ListLatest(ctx, serviceIds...)
|
||||
}
|
||||
|
||||
func (i *imlAPIDocService) LatestAPICountByServices(ctx context.Context, serviceIds ...string) (map[string]int64, error) {
|
||||
list, err := i.commitService.ListLatest(ctx, serviceIds...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return utils.SliceToMapO(list, func(i *commit.Commit[DocCommit]) (string, int64) {
|
||||
return i.Target, i.Data.APICount
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (i *imlAPIDocService) APICountByServices(ctx context.Context, serviceIds ...string) (map[string]int64, error) {
|
||||
w := make(map[string]interface{})
|
||||
if len(serviceIds) > 0 {
|
||||
w["service"] = serviceIds
|
||||
}
|
||||
list, err := i.store.List(ctx, w)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return utils.SliceToMapO(list, func(i *api.Doc) (string, int64) {
|
||||
return i.Service, i.APICount
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (i *imlAPIDocService) UpdateDoc(ctx context.Context, serviceId string, input *UpdateDoc) error {
|
||||
doc, err := NewDocLoader(input.Content)
|
||||
if err != nil {
|
||||
|
||||
@@ -17,5 +17,6 @@ type Doc struct {
|
||||
}
|
||||
|
||||
type DocCommit struct {
|
||||
Content string `json:"content"`
|
||||
Content string `json:"content"`
|
||||
APICount int64 `json:"api_count"`
|
||||
}
|
||||
|
||||
@@ -14,9 +14,14 @@ type IAPIDocService interface {
|
||||
UpdateDoc(ctx context.Context, serviceId string, input *UpdateDoc) error
|
||||
// GetDoc 获取文档
|
||||
GetDoc(ctx context.Context, serviceId string) (*Doc, error)
|
||||
|
||||
APICountByServices(ctx context.Context, serviceIds ...string) (map[string]int64, error)
|
||||
// LatestDocCommit 获取最新文档
|
||||
LatestDocCommit(ctx context.Context, serviceId string) (*commit.Commit[DocCommit], error)
|
||||
CommitDoc(ctx context.Context, serviceId string, data *DocCommit) error
|
||||
ListLatestDocCommit(ctx context.Context, serviceIds ...string) ([]*commit.Commit[DocCommit], error)
|
||||
ListDocCommit(ctx context.Context, commitIds ...string) ([]*commit.Commit[DocCommit], error)
|
||||
LatestAPICountByServices(ctx context.Context, serviceIds ...string) (map[string]int64, error)
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
+26
-4
@@ -27,17 +27,39 @@ var (
|
||||
type HistoryType string
|
||||
|
||||
const (
|
||||
HistoryProxy HistoryType = "proxy"
|
||||
HistoryRequest HistoryType = "request"
|
||||
HistoryProxy HistoryType = "proxy"
|
||||
)
|
||||
|
||||
type imlAPIService struct {
|
||||
store api.IApiBaseStore `autowired:""`
|
||||
apiInfoStore api.IAPIInfoStore `autowired:""`
|
||||
proxyCommitService commit.ICommitWithKeyService[Proxy] `autowired:""`
|
||||
store api.IApiBaseStore `autowired:""`
|
||||
apiInfoStore api.IAPIInfoStore `autowired:""`
|
||||
requestCommitService commit.ICommitWithKeyService[Request] `autowired:""`
|
||||
proxyCommitService commit.ICommitWithKeyService[Proxy] `autowired:""`
|
||||
universally.IServiceGet[API]
|
||||
universally.IServiceDelete
|
||||
}
|
||||
|
||||
func (i *imlAPIService) ListLatestCommitRequest(ctx context.Context, aid ...string) ([]*commit.Commit[Request], error) {
|
||||
return i.requestCommitService.ListLatest(ctx, aid...)
|
||||
}
|
||||
|
||||
func (i *imlAPIService) LatestRequest(ctx context.Context, aid string) (*commit.Commit[Request], error) {
|
||||
return i.requestCommitService.Latest(ctx, aid)
|
||||
}
|
||||
|
||||
func (i *imlAPIService) GetRequestCommit(ctx context.Context, commitId string) (*commit.Commit[Request], error) {
|
||||
return i.requestCommitService.Get(ctx, commitId)
|
||||
}
|
||||
|
||||
func (i *imlAPIService) ListRequestCommit(ctx context.Context, commitId ...string) ([]*commit.Commit[Request], error) {
|
||||
return i.requestCommitService.List(ctx, commitId...)
|
||||
}
|
||||
|
||||
func (i *imlAPIService) SaveRequest(ctx context.Context, aid string, data *Request) error {
|
||||
return i.requestCommitService.Save(ctx, aid, data)
|
||||
}
|
||||
|
||||
func (i *imlAPIService) CountMapByService(ctx context.Context, service ...string) (map[string]int64, error) {
|
||||
w := map[string]interface{}{}
|
||||
if len(service) > 0 {
|
||||
|
||||
@@ -104,6 +104,16 @@ type PluginSetting struct {
|
||||
Disable bool `json:"disable"`
|
||||
Config plugin_model.ConfigType `json:"config"`
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
//ID string `json:"id"`
|
||||
Path string `json:"path"`
|
||||
Methods []string `json:"methods"`
|
||||
Protocols []string `json:"protocols"`
|
||||
Match string `json:"match"`
|
||||
Disable bool `json:"disable"`
|
||||
}
|
||||
|
||||
type Proxy struct {
|
||||
Path string `json:"path"`
|
||||
Timeout int `json:"timeout"`
|
||||
|
||||
@@ -20,11 +20,18 @@ type IAPIService interface {
|
||||
GetInfo(ctx context.Context, aid string) (*Info, error)
|
||||
ListInfo(ctx context.Context, aids ...string) ([]*Info, error)
|
||||
ListInfoForService(ctx context.Context, serviceId string) ([]*Info, error)
|
||||
ListLatestCommitRequest(ctx context.Context, aid ...string) ([]*commit.Commit[Request], error)
|
||||
ListLatestCommitProxy(ctx context.Context, aid ...string) ([]*commit.Commit[Proxy], error)
|
||||
LatestRequest(ctx context.Context, aid string) (*commit.Commit[Request], error)
|
||||
LatestProxy(ctx context.Context, aid string) (*commit.Commit[Proxy], error)
|
||||
GetProxyCommit(ctx context.Context, commitId string) (*commit.Commit[Proxy], error)
|
||||
ListProxyCommit(ctx context.Context, commitId ...string) ([]*commit.Commit[Proxy], error)
|
||||
SaveProxy(ctx context.Context, aid string, data *Proxy) error
|
||||
|
||||
GetRequestCommit(ctx context.Context, commitId string) (*commit.Commit[Request], error)
|
||||
ListRequestCommit(ctx context.Context, commitId ...string) ([]*commit.Commit[Request], error)
|
||||
SaveRequest(ctx context.Context, aid string, data *Request) error
|
||||
|
||||
Save(ctx context.Context, id string, model *Edit) error
|
||||
Create(ctx context.Context, input *Create) (err error)
|
||||
}
|
||||
@@ -39,5 +46,6 @@ func init() {
|
||||
})
|
||||
|
||||
commit.InitCommitWithKeyService[Proxy]("api", string(HistoryProxy))
|
||||
commit.InitCommitWithKeyService[Request]("api", string(HistoryRequest))
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ type CommitType = string
|
||||
|
||||
const (
|
||||
CommitApiDocument CommitType = "api_doc"
|
||||
CommitApiRequest CommitType = "api_request"
|
||||
CommitUpstream CommitType = "upstream"
|
||||
CommitApiProxy CommitType = "api_proxy"
|
||||
CommitServiceDoc CommitType = "service_doc"
|
||||
)
|
||||
|
||||
+22
-22
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
|
||||
"github.com/APIParkLab/APIPark/service/api"
|
||||
"github.com/APIParkLab/APIPark/service/universally/commit"
|
||||
"github.com/APIParkLab/APIPark/service/upstream"
|
||||
@@ -29,11 +29,11 @@ type imlReleaseService struct {
|
||||
}
|
||||
|
||||
func (s *imlReleaseService) Completeness(partitions []string, apis []string, proxyCommits []*commit.Commit[api.Proxy], documentCommits []*commit.Commit[api.Document], upstreamCommits []*commit.Commit[upstream.Config]) bool {
|
||||
|
||||
|
||||
proxys := utils.SliceToMap(proxyCommits, func(o *commit.Commit[api.Proxy]) string {
|
||||
return o.Target
|
||||
})
|
||||
|
||||
|
||||
documents := utils.SliceToMap(documentCommits, func(o *commit.Commit[api.Document]) string {
|
||||
return o.Target
|
||||
})
|
||||
@@ -42,12 +42,12 @@ func (s *imlReleaseService) Completeness(partitions []string, apis []string, pro
|
||||
if !has {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
_, has = documents[aid]
|
||||
if !has {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
upstreamMap := make(map[string]map[string]struct{})
|
||||
for _, upstreamCommit := range upstreamCommits {
|
||||
@@ -56,7 +56,7 @@ func (s *imlReleaseService) Completeness(partitions []string, apis []string, pro
|
||||
}
|
||||
upstreamMap[upstreamCommit.Target][upstreamCommit.Key] = struct{}{}
|
||||
}
|
||||
|
||||
|
||||
for _, partition := range partitions {
|
||||
for _, u := range upstreamMap {
|
||||
if _, has := u[partition]; !has {
|
||||
@@ -64,7 +64,7 @@ func (s *imlReleaseService) Completeness(partitions []string, apis []string, pro
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ func (s *imlReleaseService) GetCommits(ctx context.Context, id string) ([]*Proje
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
return utils.SliceToSlice(list, func(o *release.Commit) *ProjectCommits {
|
||||
return &ProjectCommits{
|
||||
Release: o.Release,
|
||||
@@ -119,7 +119,7 @@ func (s *imlReleaseService) GetApiProxyCommit(ctx context.Context, id string, ap
|
||||
if len(commits) == 0 {
|
||||
return "", errors.New("not found")
|
||||
}
|
||||
|
||||
|
||||
return commits[0].Commit, nil
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ func (s *imlReleaseService) getCommitByType(ctx context.Context, releaseId, t Co
|
||||
}
|
||||
}
|
||||
return s.commitStore.ListQuery(ctx, where, args, "")
|
||||
|
||||
|
||||
}
|
||||
func (s *imlReleaseService) GetApiDocCommit(ctx context.Context, id string, apiUUID string) (string, error) {
|
||||
commits, err := s.getCommitByType(ctx, id, CommitApiDocument, apiUUID, CommitApiDocument)
|
||||
@@ -146,7 +146,7 @@ func (s *imlReleaseService) GetApiDocCommit(ctx context.Context, id string, apiU
|
||||
if len(commits) == 0 {
|
||||
return "", errors.New("not found")
|
||||
}
|
||||
|
||||
|
||||
return commits[0].Commit, nil
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ func (s *imlReleaseService) GetRunningApiDocCommit(ctx context.Context, service
|
||||
return "", err
|
||||
}
|
||||
return s.GetApiDocCommit(ctx, running.Release, apiUUID)
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (s *imlReleaseService) GetRunningApiProxyCommit(ctx context.Context, service string, apiUUID string) (string, error) {
|
||||
@@ -264,7 +264,7 @@ func (s *imlReleaseService) SetRunning(ctx context.Context, service string, id s
|
||||
UpdateTime: time.Now(),
|
||||
Operator: operator,
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (s *imlReleaseService) CreateRelease(ctx context.Context, service string, version string, remark string, apisProxyCommits, apiDocCommits map[string]string, upstreams map[string]map[string]string) (*Release, error) {
|
||||
@@ -317,7 +317,7 @@ func (s *imlReleaseService) CreateRelease(ctx context.Context, service string, v
|
||||
if !ok {
|
||||
return errors.New("version already exists")
|
||||
}
|
||||
|
||||
|
||||
err := s.releaseStore.Insert(ctx, ev)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -367,14 +367,14 @@ func (s *imlReleaseService) GetRelease(ctx context.Context, id string) (*Release
|
||||
// }
|
||||
//
|
||||
// df := new(Diff)
|
||||
// df.Apis = s.DiffApis(ctx, baseApis, targetApis)
|
||||
// df.Routers = s.DiffApis(ctx, baseApis, targetApis)
|
||||
// df.Upstreams = s.DiffUpstreams(ctx, baseUpstreams, targetUpstreams)
|
||||
// return df, nil
|
||||
//}
|
||||
|
||||
func (s *imlReleaseService) DeleteRelease(ctx context.Context, id string) error {
|
||||
//todo 判断版本是否有使用中的未完结流程
|
||||
|
||||
|
||||
return s.releaseStore.Transaction(ctx, func(ctx context.Context) error {
|
||||
first, err := s.releaseRuntime.First(ctx, map[string]interface{}{
|
||||
"release": id,
|
||||
@@ -397,7 +397,7 @@ func (s *imlReleaseService) DeleteRelease(ctx context.Context, id string) error
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (s *imlReleaseService) List(ctx context.Context, service string) ([]*Release, error) {
|
||||
@@ -418,7 +418,7 @@ func (s *imlReleaseService) GetReleaseInfos(ctx context.Context, id string) ([]*
|
||||
apiProxyCommits := make([]*APIProxyCommit, 0, len(commits))
|
||||
apiDocumentCommits := make([]*APIDocumentCommit, 0, len(commits))
|
||||
upstreamCommits := make([]*UpstreamCommit, 0, len(commits))
|
||||
|
||||
|
||||
for _, v := range commits {
|
||||
switch v.Type {
|
||||
case CommitApiProxy:
|
||||
@@ -427,14 +427,14 @@ func (s *imlReleaseService) GetReleaseInfos(ctx context.Context, id string) ([]*
|
||||
API: v.Target,
|
||||
Commit: v.Commit,
|
||||
})
|
||||
|
||||
|
||||
case CommitApiDocument:
|
||||
apiDocumentCommits = append(apiDocumentCommits, &APIDocumentCommit{
|
||||
Release: v.Release,
|
||||
API: v.Target,
|
||||
Commit: v.Commit,
|
||||
})
|
||||
|
||||
|
||||
case CommitUpstream:
|
||||
upstreamCommits = append(upstreamCommits, &UpstreamCommit{
|
||||
Release: v.Release,
|
||||
@@ -443,9 +443,9 @@ func (s *imlReleaseService) GetReleaseInfos(ctx context.Context, id string) ([]*
|
||||
Commit: v.Commit,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return apiProxyCommits, apiDocumentCommits, upstreamCommits, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package release
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
|
||||
"github.com/APIParkLab/APIPark/stores/release"
|
||||
)
|
||||
|
||||
@@ -52,7 +52,7 @@ type ProjectCommits struct {
|
||||
}
|
||||
|
||||
//type Diff struct {
|
||||
// Apis []*APiDiff `json:"apis"`
|
||||
// Routers []*APiDiff `json:"apis"`
|
||||
// Upstreams []*UpstreamDiff `json:"upstream"`
|
||||
//}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package release
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
|
||||
"github.com/APIParkLab/APIPark/service/api"
|
||||
"github.com/APIParkLab/APIPark/service/universally/commit"
|
||||
"github.com/APIParkLab/APIPark/service/upstream"
|
||||
@@ -18,22 +18,22 @@ type IReleaseService interface {
|
||||
// DeleteRelease 删除发布
|
||||
DeleteRelease(ctx context.Context, id string) error
|
||||
List(ctx context.Context, service string) ([]*Release, error)
|
||||
GetApiProxyCommit(ctx context.Context, id string, apiUUID string) (string, error)
|
||||
GetApiDocCommit(ctx context.Context, id string, apiUUID string) (string, error)
|
||||
//GetApiProxyCommit(ctx context.Context, id string, apiUUID string) (string, error)
|
||||
//GetApiDocCommit(ctx context.Context, id string, apiUUID string) (string, error)
|
||||
GetReleaseInfos(ctx context.Context, id string) ([]*APIProxyCommit, []*APIDocumentCommit, []*UpstreamCommit, error)
|
||||
GetCommits(ctx context.Context, id string) ([]*ProjectCommits, error)
|
||||
|
||||
|
||||
GetRunningApiDocCommit(ctx context.Context, service string, apiUUID string) (string, error)
|
||||
GetRunningApiProxyCommit(ctx context.Context, service string, apiUUID string) (string, error)
|
||||
Completeness(partitions []string, apis []string, proxyCommits []*commit.Commit[api.Proxy], documentCommits []*commit.Commit[api.Document], upstreamCommits []*commit.Commit[upstream.Config]) bool
|
||||
|
||||
|
||||
// GetRunning gets the running release with the given service.
|
||||
//
|
||||
// ctx: the context
|
||||
// service: the service name
|
||||
// Return type(s): *Release, error
|
||||
GetRunning(ctx context.Context, service string) (*Release, error)
|
||||
|
||||
|
||||
SetRunning(ctx context.Context, service string, id string) error
|
||||
CheckNewVersion(ctx context.Context, service string, version string) (bool, error)
|
||||
}
|
||||
|
||||
@@ -19,10 +19,12 @@ type Status struct {
|
||||
}
|
||||
|
||||
type ApiDiff struct {
|
||||
APi string `json:"api,omitempty"`
|
||||
Upstream string `json:"upstream,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Method string `json:"method,omitempty"`
|
||||
APi string `json:"api,omitempty"`
|
||||
//Upstream string `json:"upstream,omitempty"`
|
||||
//Name string `json:"name,omitempty"`
|
||||
Method []string `json:"method,omitempty"`
|
||||
Protocol []string `json:"protocol,omitempty"`
|
||||
Disable bool `json:"disable,omitempty"`
|
||||
Path string `json:"path,omitempty"`
|
||||
Change ChangeType `json:"change,omitempty"`
|
||||
Status Status `json:"status,omitempty"`
|
||||
|
||||
@@ -21,7 +21,7 @@ type IServiceGet[T any] interface {
|
||||
|
||||
Search(ctx context.Context, keyword string, condition map[string]interface{}, sortRule ...string) ([]*T, error)
|
||||
Count(ctx context.Context, keyword string, condition map[string]interface{}) (int64, error)
|
||||
CountByGroup(ctx context.Context, keyword string, condition map[string]interface{}, groupBy string) (map[string]int64, error)
|
||||
//CountByGroup(ctx context.Context, keyword string, condition map[string]interface{}, groupBy string) (map[string]int64, error)
|
||||
SearchByPage(ctx context.Context, keyword string, condition map[string]interface{}, page int, pageSize int, sortRule ...string) ([]*T, int64, error)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user