Skip to content

Commit

Permalink
Merge pull request #6410 from yjieliang/feat-5939
Browse files Browse the repository at this point in the history
feat: json文件生成的流水线自动下载范围可见插件 #5939
  • Loading branch information
irwinsun authored May 5, 2022
2 parents 5b2ad88 + 129187e commit d436560
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,20 @@ class PipelineInfoFacadeService @Autowired constructor(
}
val model = pipelineModelAndSetting.model
modelCheckPlugin.clearUpModel(model)

if (model.srcTemplateId.isNullOrBlank()) {
val validateRet = client.get(ServiceTemplateResource::class)
.validateModelComponentVisibleDept(
userId = userId,
model = model,
projectCode = projectId
)
if (validateRet.isNotOk()) {
throw ErrorCodeException(
errorCode = validateRet.status.toString(),
defaultMessage = validateRet.message
)
}
}
val newPipelineId = createPipeline(
userId = userId,
projectId = projectId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ package com.tencent.devops.store.api.template

import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.pipeline.Model
import com.tencent.devops.store.pojo.template.InstallTemplateReq
import com.tencent.devops.store.pojo.template.MarketTemplateResp
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.annotations.ApiParam
import javax.validation.Valid
import javax.ws.rs.Consumes
import javax.ws.rs.GET
import javax.ws.rs.HeaderParam
Expand Down Expand Up @@ -84,4 +86,19 @@ interface ServiceTemplateResource {
@QueryParam("projectCode")
projectCode: String
): Result<Boolean>

@ApiOperation("校验流水线模型内组件可见范围")
@POST
@Path("/{projectCode}/verification")
fun validateModelComponentVisibleDept(
@ApiParam("用户", required = true)
@HeaderParam(AUTH_HEADER_USER_ID)
userId: String,
@ApiParam("流水线模型-阶段", required = true)
@Valid
model: Model,
@ApiParam("项目", required = true)
@PathParam("projectCode")
projectCode: String
): Result<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
package com.tencent.devops.store.resources.template

import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.pipeline.Model
import com.tencent.devops.common.pipeline.enums.ChannelCode
import com.tencent.devops.common.web.RestResource
import com.tencent.devops.store.api.template.ServiceTemplateResource
Expand Down Expand Up @@ -78,4 +79,18 @@ class ServiceTemplateResourceImpl @Autowired constructor(
projectCodeList = arrayListOf(projectCode)
)
}

override fun validateModelComponentVisibleDept(
userId: String,
model: Model,
projectCode: String
): Result<Boolean> {
val projectCodeList = ArrayList<String>()
projectCodeList.add(projectCode)
return marketTemplateService.verificationModelComponentVisibleDept(
userId = userId,
model = model,
projectCodeList = projectCodeList
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ package com.tencent.devops.store.service.template

import com.tencent.devops.common.api.pojo.Page
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.pipeline.Model
import com.tencent.devops.common.pipeline.enums.ChannelCode
import com.tencent.devops.store.pojo.template.InstallTemplateReq
import com.tencent.devops.store.pojo.template.MarketTemplateMain
Expand Down Expand Up @@ -109,6 +110,16 @@ interface MarketTemplateService {
projectCodeList: ArrayList<String>
): Result<Boolean>

/**
* 校验流水线模型组件的可见范围
*/
fun verificationModelComponentVisibleDept(
userId: String,
model: Model,
projectCodeList: ArrayList<String>,
templateCode: String? = null
): Result<Boolean>

/**
* 获取工作台模版列表
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,12 +671,27 @@ abstract class MarketTemplateServiceImpl @Autowired constructor() : MarketTempla
val templateDetail = templateDetailResult.data
val templateModel = templateDetail?.templateModel
?: return MessageCodeUtil.generateResponseDataObject(CommonMessageCode.SYSTEM_ERROR)
return verificationModelComponentVisibleDept(
userId = userId,
model = templateModel,
projectCodeList = projectCodeList,
templateCode = templateCode
)
}

override fun verificationModelComponentVisibleDept(
userId: String,
model: Model,
projectCodeList: ArrayList<String>,
templateCode: String?
): Result<Boolean> {

val invalidImageList = mutableListOf<String>()
val invalidAtomList = mutableListOf<String>()
val needInstallImageMap = mutableMapOf<String, StoreBaseInfo>()
val needInstallAtomMap = mutableMapOf<String, StoreBaseInfo>()
val userDeptIdList = storeUserService.getUserDeptList(userId) // 获取用户的机构ID信息
val stageList = templateModel.stages
val stageList = model.stages
// 获取模板下镜像的机构信息
val templateImageDeptMap = storeDeptService.getTemplateImageDeptMap(stageList)
// 获取每个模板下插件的机构信息
Expand Down Expand Up @@ -738,15 +753,18 @@ abstract class MarketTemplateServiceImpl @Autowired constructor() : MarketTempla
params = arrayOf(JsonUtil.toJson(invalidAtomList))
)
}
val validateTempleAtomVisibleResult = validateTemplateVisibleDept(
templateCode = templateDetail.templateCode,
templateModel = templateModel,
validImageCodes = validImageCodes,
validAtomCodes = validAtomCodes
)
if (validateTempleAtomVisibleResult.isNotOk()) {
return validateTempleAtomVisibleResult
if (!templateCode.isNullOrBlank()) {
val validateTempleAtomVisibleResult = validateTemplateVisibleDept(
templateCode = templateCode,
templateModel = model,
validImageCodes = validImageCodes,
validAtomCodes = validAtomCodes
)
if (validateTempleAtomVisibleResult.isNotOk()) {
return validateTempleAtomVisibleResult
}
}

// 安装镜像
installStoreComponent(needInstallImageMap, userId, projectCode, StoreTypeEnum.IMAGE)
// 安装插件
Expand Down

0 comments on commit d436560

Please sign in to comment.