Skip to content

Commit

Permalink
feat: get tmpl rev with signature --task=74871191 (#2983)
Browse files Browse the repository at this point in the history
* feat: get tmpl rev with signature --task=74871191

* docs: update api doc
  • Loading branch information
fireyun authored Feb 28, 2024
1 parent 72404a5 commit c26473d
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ paths:
matchSubpath: false
backend:
type: HTTP
method: post
method: get
path: /api/v1/config/list/app/app/biz_id/{biz_id}
matchSubpath: false
timeout: 0
Expand Down Expand Up @@ -1400,6 +1400,30 @@ paths:
authConfig:
userVerifiedRequired: true
disabledStages: [ ]
/api/v1/config/biz/{biz_id}/template_revisions/list_names_by_template_ids:
post:
operationId: list_template_revision_name_by_template_id
description: 批量查询模版的版本名称
tags:
- 模版版本
responses:
default:
description: ''
x-bk-apigateway-resource:
isPublic: true
allowApplyPermission: true
matchSubpath: false
backend:
type: HTTP
method: post
path: /api/v1/config/biz/{biz_id}/template_revisions/list_names_by_template_ids
matchSubpath: false
timeout: 0
upstreams: { }
transformHeaders: { }
authConfig:
userVerifiedRequired: true
disabledStages: [ ]
/api/v1/config/biz/{biz_id}/template_spaces/{template_space_id}/template_sets:
post:
operationId: create_template_set
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
### 描述

该接口提供版本:v1.0.0+

批量查询模版的版本名称

### 输入参数

| 参数名称 | 参数类型 | 必选 | 描述 |
| ------------ | -------- | ---- | --------------------- |
| biz_id | uint32 || 业务ID |
| template_ids | []uint32 || 模版ID列表,最多200个 |

### 调用示例

```json
{
"template_ids": [
1,
2
]
}
```

### 响应示例

```json
{
"data": {
"details": [
[
{
"template_id": 1,
"template_name": "template001",
"latest_template_revision_id": 2,
"latest_signature": "11e3a57c479ebfae641c5821ee70bf61dca74b8e6596b78950526c397a3b1234",
"latest_byte_size": "2067",
"template_revisions": [
{
"template_revision_id": 1,
"template_revision_name": "v20230815120105",
"template_revision_memo": "my revision for test1"
},
{
"template_revision_id": 2,
"template_revision_name": "v20230815130206",
"template_revision_memo": "my revision for test2"
}
]
},
{
"template_id": 2,
"template_name": "template002",
"latest_template_revision_id": 4,
"latest_signature": "22e3a57c479ebfae641c5821ee70bf61dca74b8e6596b78950526c397a3b1253",
"latest_byte_size": "1023",
"template_revisions": [
{
"template_revision_id": 3,
"template_revision_name": "v20230815140307",
"template_revision_memo": "my revision for test3"
},
{
"template_revision_id": 4,
"template_revision_name": "v20230815150408",
"template_revision_memo": "my revision for test2"
}
]
}
]
]
}
}
```

### 响应参数说明

| 参数名称 | 参数类型 | 描述 |
| -------- | -------- | -------- |
| data | object | 响应数据 |

#### data

| 参数名称 | 参数类型 | 描述 |
| -------- | -------- | -------------- |
| detail | array | 查询返回的数据 |

#### data.detail[n]

| 参数名称 | 参数类型 | 描述 |
| --------------------------- | -------- | -------------------------- |
| template_id | uint32 | 模版ID |
| template_name | string | 模版名称 |
| latest_template_revision_id | uint32 | 最新模版版本ID |
| latest_sinature | string | 最新模版版本内容的sha256 |
| latest_byte_size | uint64 | 最新模版版本内容的字节大小 |
| template_revisions | object | 模版版本信息 |

#### template_revisions

| 参数名称 | 参数类型 | 描述 |
| ---------------------- | -------- | ------------ |
| template_revision_id | uint32 | 模版版本ID |
| template_revision_name | string | 模版版本名称 |
| template_revision_memo | string | 模版版本描述 |
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (s *Service) ListAppBoundTmplRevisions(ctx context.Context,
tmplRevisionMap[t.ID] = t
}

/// combine resp details
// combine resp details
details := make([]*pbatb.AppBoundTmplRevision, 0)
for _, b := range atb[0].Spec.Bindings {
for _, r := range b.TemplateRevisions {
Expand Down Expand Up @@ -606,12 +606,12 @@ func (s *Service) getPBSForCascade(kt *kit.Kit, tx *gen.QueryTx, bindings []*tab
logs.Errorf("list template revision names by template ids failed, err: %v, rid: %s", err, kt.Rid)
return nil, err
}
// template id => the latest template revision id
// template id => the latest template revision
latestRevisionMap := getLatestTmplRevisions(latestTmplRevisions)

for tID, rID := range latestRevisionMap {
pbs.TemplateRevisionIDs = append(pbs.TemplateRevisionIDs, rID)
allTmplRevisionMap[tID] = rID
for tID, r := range latestRevisionMap {
pbs.TemplateRevisionIDs = append(pbs.TemplateRevisionIDs, r.ID)
allTmplRevisionMap[tID] = r.ID
}

for tsID, tmpls := range allTmplMap {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ func (s *Service) ListTmplRevisionNamesByTmplIDs(ctx context.Context,
details = append(details, &pbtr.TemplateRevisionNamesDetail{
TemplateId: t.ID,
TemplateName: t.Spec.Name,
LatestTemplateRevisionId: latestRevisionMap[t.ID],
LatestTemplateRevisionId: latestRevisionMap[t.ID].ID,
LatestSignature: latestRevisionMap[t.ID].Spec.ContentSpec.Signature,
LatestByteSize: latestRevisionMap[t.ID].Spec.ContentSpec.ByteSize,
TemplateRevisions: tmplRevisionMap[t.ID].TemplateRevisions,
})
}
Expand All @@ -224,14 +226,14 @@ func (s *Service) ListTmplRevisionNamesByTmplIDs(ctx context.Context,
return resp, nil
}

// getLatestTmplRevisions get the map: tmplID => latest tmplRevisionID
func getLatestTmplRevisions(tmplRevisions []*table.TemplateRevision) map[uint32]uint32 {
latestRevisionMap := make(map[uint32]uint32)
// getLatestTmplRevisions get the map: tmplID => latest tmplRevision
func getLatestTmplRevisions(tmplRevisions []*table.TemplateRevision) map[uint32]*table.TemplateRevision {
latestRevisionMap := make(map[uint32]*table.TemplateRevision)
for _, t := range tmplRevisions {
if _, ok := latestRevisionMap[t.Attachment.TemplateID]; !ok {
latestRevisionMap[t.Attachment.TemplateID] = t.ID
} else if t.ID > latestRevisionMap[t.Attachment.TemplateID] {
latestRevisionMap[t.Attachment.TemplateID] = t.ID
latestRevisionMap[t.Attachment.TemplateID] = t
} else if t.ID > latestRevisionMap[t.Attachment.TemplateID].ID {
latestRevisionMap[t.Attachment.TemplateID] = t
}
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@ message TemplateRevisionNamesDetail {
uint32 template_id = 1;
string template_name = 2;
uint32 latest_template_revision_id = 3;
string latest_signature = 5;
uint64 latest_byte_size = 6;
repeated revision_names template_revisions = 4;
}

0 comments on commit c26473d

Please sign in to comment.