Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 配置模板新增查看态接口以及脚本管理功能优化 #3324

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,40 @@ func (s *Service) ListTmplRevisionNamesByTmplIDs(ctx context.Context, req *pbcs.
}
return resp, nil
}

// GetTemplateRevision 根据版本号获取 TemplateRevisions
func (s *Service) GetTemplateRevision(ctx context.Context, req *pbcs.GetTemplateRevisionReq) (
*pbcs.GetTemplateRevisionResp, error) {
grpcKit := kit.FromGrpcContext(ctx)

tr, err := s.client.DS.GetTemplateRevision(grpcKit.RpcCtx(), &pbds.GetTemplateRevisionReq{
BizId: req.GetBizId(),
TemplateId: req.GetTemplateId(),
RevisionName: req.GetRevisionName(),
})

if err != nil {
return nil, err
}

return &pbcs.GetTemplateRevisionResp{
Detail: &pbcs.GetTemplateRevisionResp_TemplateRevision{
TemplateId: tr.GetDetail().GetTemplateId(),
Name: tr.GetDetail().GetName(),
Path: tr.GetDetail().GetPath(),
TemplateRevisionId: tr.GetDetail().GetTemplateRevisionId(),
TemplateRevisionName: tr.GetDetail().GetTemplateRevisionName(),
TemplateRevisionMemo: tr.GetDetail().GetTemplateRevisionMemo(),
FileType: tr.GetDetail().GetFileType(),
FileMode: tr.GetDetail().GetFileMode(),
User: tr.GetDetail().GetUser(),
UserGroup: tr.GetDetail().GetUserGroup(),
Privilege: tr.GetDetail().GetPrivilege(),
Signature: tr.GetDetail().GetSignature(),
ByteSize: tr.GetDetail().GetByteSize(),
Creator: tr.GetDetail().GetCreator(),
CreateAt: tr.GetDetail().GetCreateAt(),
Md5: tr.GetDetail().GetMd5(),
},
}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ package service
import (
"context"
"fmt"
"time"

"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/criteria/errf"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/dal/gen"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/dal/table"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/i18n"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/kit"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/logs"
pbbase "github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/protocol/core/base"
Expand Down Expand Up @@ -253,3 +256,43 @@ func (s *Service) doCreateTemplateRevisions(kt *kit.Kit, tx *gen.QueryTx, data [
}
return nil
}

// GetTemplateRevision 根据版本号获取 TemplateRevisions
func (s *Service) GetTemplateRevision(ctx context.Context, req *pbds.GetTemplateRevisionReq) (
*pbds.GetTemplateRevisionResp, error) {
kt := kit.FromGrpcContext(ctx)

var revision *table.TemplateRevision
var err error
if req.RevisionName == "" {
revision, err = s.dao.TemplateRevision().GetLatesTemplateRevision(kt, req.GetBizId(), req.GetTemplateId())
} else {
revision, err = s.dao.TemplateRevision().GetByUniqueKey(kt, req.GetBizId(), req.GetTemplateId(),
req.GetRevisionName())
}

if err != nil {
return nil, errf.Errorf(errf.DBOpFailed, i18n.T(kt, fmt.Sprintf("get template revision failed, err: %v", err)))
}

return &pbds.GetTemplateRevisionResp{
Detail: &pbds.GetTemplateRevisionResp_TemplateRevision{
TemplateId: revision.Attachment.TemplateID,
Name: revision.Spec.Name,
Path: revision.Spec.Path,
TemplateRevisionId: revision.ID,
TemplateRevisionName: revision.Spec.RevisionName,
TemplateRevisionMemo: revision.Spec.RevisionMemo,
FileType: string(revision.Spec.FileType),
FileMode: string(revision.Spec.FileMode),
User: revision.Spec.Permission.User,
UserGroup: revision.Spec.Permission.UserGroup,
Privilege: revision.Spec.Permission.Privilege,
Signature: revision.Spec.ContentSpec.Signature,
ByteSize: revision.Spec.ContentSpec.ByteSize,
Creator: revision.Revision.Creator,
CreateAt: revision.Revision.CreatedAt.Format(time.RFC3339),
Md5: revision.Spec.ContentSpec.Md5,
},
}, nil
}
4 changes: 3 additions & 1 deletion bcs-services/bcs-bscp/pkg/dal/dao/hook_revision.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,9 @@ func (dao *hookRevisionDao) UpdatePubStateWithTx(kit *kit.Kit, tx *gen.QueryTx,
}
ad := dao.auditDao.DecoratorV2(kit, hr.Attachment.BizID).PrepareUpdate(hr, oldOne)

if _, e := q.Where(m.ID.Eq(hr.ID), m.BizID.Eq(hr.Attachment.BizID)).Select(m.State, m.Reviser).Updates(hr); e != nil {
if _, e := q.Where(m.ID.Eq(hr.ID), m.BizID.Eq(hr.Attachment.BizID)).
Omit(m.UpdatedAt).
Select(m.State, m.Reviser).Updates(hr); e != nil {
return e
}

Expand Down
17 changes: 11 additions & 6 deletions bcs-services/bcs-bscp/pkg/dal/dao/template_revision.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ type TemplateRevision interface {
BatchCreateWithTx(kit *kit.Kit, tx *gen.QueryTx, revisions []*table.TemplateRevision) error
// ListLatestRevisionsGroupByTemplateIds Lists the latest version groups by template ids
ListLatestRevisionsGroupByTemplateIds(kit *kit.Kit, templateIDs []uint32) ([]*table.TemplateRevision, error)
// GetLatesTemplateRevision get lates template revision.
GetLatesTemplateRevision(kit *kit.Kit, bizID, templateID uint32) (*table.TemplateRevision, error)
}

var _ TemplateRevision = new(templateRevisionDao)
Expand All @@ -64,6 +66,14 @@ type templateRevisionDao struct {
auditDao AuditDao
}

// GetLatesTemplateRevision get lates template revision.
func (dao *templateRevisionDao) GetLatesTemplateRevision(kit *kit.Kit, bizID uint32, templateID uint32) (
*table.TemplateRevision, error) {
m := dao.genQ.TemplateRevision
q := dao.genQ.TemplateRevision.WithContext(kit.Ctx)
return q.Where(m.BizID.Eq(bizID), m.TemplateID.Eq(templateID)).Order(m.ID.Desc()).Take()
}

// Create one template revision instance.
func (dao *templateRevisionDao) Create(kit *kit.Kit, g *table.TemplateRevision) (uint32, error) {
if err := g.ValidateCreate(); err != nil {
Expand Down Expand Up @@ -204,13 +214,8 @@ func (dao *templateRevisionDao) GetByUniqueKey(kit *kit.Kit, bizID, templateID u
m := dao.genQ.TemplateRevision
q := dao.genQ.TemplateRevision.WithContext(kit.Ctx)

templateRevision, err := q.Where(m.BizID.Eq(bizID), m.TemplateID.Eq(templateID),
return q.Where(m.BizID.Eq(bizID), m.TemplateID.Eq(templateID),
m.RevisionName.Eq(revisionName)).Take()
if err != nil {
return nil, fmt.Errorf("get template revision failed, err: %v", err)
}

return templateRevision, nil
}

// ListByIDs list template revisions by template revision ids.
Expand Down
Loading
Loading