Skip to content

Commit

Permalink
fix:已生成版本的非模版配置项接口不返回模版数据,添加渲染后的signature和byte_size字段 (TencentBlueKin…
Browse files Browse the repository at this point in the history
…g#2533)

* fix:调整查询已生成版本的非模版配置项接口,不返回模版配置项

* fix: 为已生成版本的模版配置项添加渲染后的signature和byte_size字段
  • Loading branch information
fireyun authored Sep 6, 2023
1 parent d64e8d3 commit a963623
Show file tree
Hide file tree
Showing 11 changed files with 3,093 additions and 2,776 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (s *Service) ListReleasedAppBoundTemplateRevisions(ctx context.Context,

resp := &pbds.ListReleasedAppBoundTemplateRevisionsResp{
Count: uint32(count),
Details: pbatb.PbAppBoundTmplRevisions(details),
Details: pbatb.PbReleasedAppBoundTmplRevisions(details),
}
return resp, nil
}
Expand Down
7 changes: 5 additions & 2 deletions bcs-services/bcs-bscp/cmd/data-service/service/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (s *Service) doTemplateActionForCreateRelease(kt *kit.Kit, req *pbds.Create
return err
}

if err := s.createReleasedAppTemplates(kt, tx, releaseID); err != nil {
if err := s.createReleasedAppTemplates(kt, tx, releaseID, renderedContentMap, signatureMap); err != nil {
logs.Errorf("create released rendered template config items failed, err: %v, rid: %s", err, kt.Rid)
return err
}
Expand Down Expand Up @@ -317,7 +317,8 @@ func (s *Service) createReleasedRenderedTemplateCIs(kt *kit.Kit, tx *gen.QueryTx
}

// createReleasedAppTemplates create released app templates.
func (s *Service) createReleasedAppTemplates(kt *kit.Kit, tx *gen.QueryTx, releaseID uint32) error {
func (s *Service) createReleasedAppTemplates(kt *kit.Kit, tx *gen.QueryTx, releaseID uint32,
renderedContentMap map[uint32][]byte, signatureMap map[uint32]string) error {
revisionsResp, err := s.ListAppBoundTemplateRevisions(kt.Ctx, &pbds.ListAppBoundTemplateRevisionsReq{
BizId: kt.BizID,
AppId: kt.AppID,
Expand Down Expand Up @@ -352,6 +353,8 @@ func (s *Service) createReleasedAppTemplates(kt *kit.Kit, tx *gen.QueryTx, relea
Privilege: r.Privilege,
Signature: r.Signature,
ByteSize: r.ByteSize,
RenderedSignature: signatureMap[r.TemplateRevisionId],
RenderedByteSize: uint64(len(renderedContentMap[r.TemplateRevisionId])),
},
Attachment: &table.ReleasedAppTemplateAttachment{
BizID: kt.BizID,
Expand Down
11 changes: 6 additions & 5 deletions bcs-services/bcs-bscp/pkg/dal/dao/release_ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type ReleasedCI interface {
Get(kit *kit.Kit, id, bizID, releasedID uint32) (*table.ReleasedConfigItem, error)
// GetReleasedLately released config item by app id and biz id
GetReleasedLately(kit *kit.Kit, appId, bizID uint32, searchKey string) ([]*table.ReleasedConfigItem, error)
// List released config items with options.
// List released config items with options, only return non template config items.
List(kit *kit.Kit, opts *types.ListReleasedCIsOption) (*types.ListReleasedCIsDetails, error)
// ListAll list all released config items in biz.
ListAll(kit *kit.Kit, bizID uint32) ([]*table.ReleasedConfigItem, error)
Expand Down Expand Up @@ -106,7 +106,7 @@ func (dao *releasedCIDao) Get(kit *kit.Kit, configItemID, bizID, releaseID uint3
m.ConfigItemID.Eq(configItemID), m.ReleaseID.Eq(releaseID), m.BizID.Eq(bizID)).Take()
}

// List released config items with options.
// List released config items with options, only return non template config items.
func (dao *releasedCIDao) List(kit *kit.Kit, opts *types.ListReleasedCIsOption) (
*types.ListReleasedCIsDetails, error) {

Expand All @@ -124,8 +124,8 @@ func (dao *releasedCIDao) List(kit *kit.Kit, opts *types.ListReleasedCIsOption)
}

m := dao.genQ.ReleasedConfigItem

query := m.WithContext(kit.Ctx).Where(m.ReleaseID.Eq(opts.ReleaseID), m.BizID.Eq(opts.BizID))
// m.ConfigItemID.Neq(0) means not to match template config items
query := m.WithContext(kit.Ctx).Where(m.ReleaseID.Eq(opts.ReleaseID), m.BizID.Eq(opts.BizID), m.ConfigItemID.Neq(0))
if opts.SearchKey != "" {
searchKey := "%" + opts.SearchKey + "%"
query = query.Where(m.Name.Like(searchKey)).Or(m.Creator.Like(searchKey)).Or(m.Reviser.Like(searchKey))
Expand Down Expand Up @@ -200,7 +200,8 @@ func (dao *releasedCIDao) GetReleasedLately(kit *kit.Kit, appId, bizID uint32, s

m := dao.genQ.ReleasedConfigItem
q := dao.genQ.ReleasedConfigItem.WithContext(kit.Ctx)
query := q.Where(m.BizID.Eq(bizID), m.AppID.Eq(appId))
// m.ConfigItemID.Neq(0) means not to match template config items
query := q.Where(m.BizID.Eq(bizID), m.AppID.Eq(appId), m.ConfigItemID.Neq(0))
if searchKey != "" {
param := "%" + searchKey + "%"
query = q.Where(q.Where(m.BizID.Eq(bizID), m.AppID.Eq(appId)),
Expand Down
2 changes: 2 additions & 0 deletions bcs-services/bcs-bscp/pkg/dal/table/released_app_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ type ReleasedAppTemplateSpec struct {
Privilege string `json:"privilege" gorm:"column:privilege"`
Signature string `json:"signature" gorm:"column:signature"`
ByteSize uint64 `json:"byte_size" gorm:"column:byte_size"`
RenderedSignature string `json:"rendered_signature" gorm:"column:rendered_signature"`
RenderedByteSize uint64 `json:"rendered_byte_size" gorm:"column:rendered_byte_size"`
}

// ValidateCreate validate ReleasedAppTemplate spec when it is created.
Expand Down
Loading

0 comments on commit a963623

Please sign in to comment.