Skip to content

Commit

Permalink
Merge pull request #11046 from yjieliang/issue_10475_innerPipeline_fi…
Browse files Browse the repository at this point in the history
…x_yj

pref:研发商店组件内置打包流水线都归属到统一的平台项目下 #10475
  • Loading branch information
bkci-bot authored Dec 27, 2024
2 parents b8f4380 + 9d5febc commit 6ef228b
Show file tree
Hide file tree
Showing 24 changed files with 733 additions and 287 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,11 @@ class PipelineAtomService @Autowired constructor(

private fun validateUserAtomPermission(atomCode: String, userId: String) {
val validateResult =
client.get(ServiceStoreResource::class).isStoreMember(atomCode, StoreTypeEnum.ATOM, userId)
client.get(ServiceStoreResource::class).validatePipelineUserStorePermission(
storeCode = atomCode,
storeType = StoreTypeEnum.ATOM,
userId = userId
)
if (validateResult.isNotOk()) {
throw ErrorCodeException(
errorCode = validateResult.status.toString(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license.
*
* A copy of the MIT License is included in this file.
*
*
* Terms of the MIT License:
* ---------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.tencent.devops.store.api.common

import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID
import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID_DEFAULT_VALUE
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.Parameter
import io.swagger.v3.oas.annotations.tags.Tag
import javax.ws.rs.Consumes
import javax.ws.rs.DELETE
import javax.ws.rs.HeaderParam
import javax.ws.rs.Path
import javax.ws.rs.Produces
import javax.ws.rs.QueryParam
import javax.ws.rs.core.MediaType

@Tag(name = "OP_STORE", description = "OP-商店")
@Path("/op/store")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
interface OpStoreResource {

@Operation(summary = "删除组件内置流水线")
@DELETE
@Path("/inner/pipeline/delete")
fun deleteStoreInnerPipeline(
@Parameter(description = "用户ID", required = true, example = AUTH_HEADER_USER_ID_DEFAULT_VALUE)
@HeaderParam(AUTH_HEADER_USER_ID)
userId: String,
@Parameter(description = "组件类型", required = false)
@QueryParam("storeType")
storeType: StoreTypeEnum? = null,
@Parameter(description = "组件标识", required = false)
@QueryParam("storeCode")
storeCode: String? = null,
@Parameter(description = "需排除的项目", required = false)
@QueryParam("excludeProjectCode")
excludeProjectCode: String? = null
): Result<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,30 @@ interface ServiceStoreResource {
userId: String
): Result<Boolean>

@Operation(summary = "判断项目是否是研发商店公共项目")
@GET
@Path("projects/{projectCode}/validate")
fun isPublicProject(
@Parameter(description = "标识", required = true)
@PathParam("projectCode")
projectCode: String
): Result<Boolean>

@Operation(summary = "校验流水线用户访问组件信息权限")
@GET
@Path("/codes/{storeCode}/pipeline/visit/validate")
fun validatePipelineUserStorePermission(
@Parameter(description = "标识", required = true)
@PathParam("storeCode")
storeCode: String,
@Parameter(description = "类型", required = true)
@QueryParam("storeType")
storeType: StoreTypeEnum,
@Parameter(description = "用户ID", required = true)
@QueryParam("userId")
userId: String
): Result<Boolean>

@Operation(summary = "判断错误码是否合规")
@POST
@Path("/codes/{storeCode}/errorCode/compliance")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import com.tencent.devops.store.pojo.common.KEY_CREATOR
import com.tencent.devops.store.pojo.common.KEY_LANGUAGE
import com.tencent.devops.store.pojo.common.KEY_PROJECT_CODE
import com.tencent.devops.store.pojo.common.KEY_STORE_CODE
import com.tencent.devops.store.pojo.common.STORE_CODE
import com.tencent.devops.store.pojo.common.StoreBaseInfo
import com.tencent.devops.store.pojo.common.enums.StoreProjectTypeEnum
import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum
Expand Down Expand Up @@ -193,4 +194,10 @@ class AtomCommonDao : AbstractStoreCommonDao() {
.fetchAny()?.into(String::class.java)
}
}

override fun getStoreCodeById(dslContext: DSLContext, storeId: String): String? {
return with(TAtom.T_ATOM) {
dslContext.select(ATOM_CODE).from(this).where(ID.eq(storeId)).fetchOne(0, String::class.java)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ class MarketAtomEnvInfoDao {
atomCode: String,
version: String,
atomDefaultFlag: Boolean,
atomStatusList: List<Byte>?
atomStatusList: List<Byte>?,
queryProjectFlag: Boolean = true
): Record? {
val tAtom = TAtom.T_ATOM
val tStoreProjectRel = TStoreProjectRel.T_STORE_PROJECT_REL
Expand All @@ -115,17 +116,21 @@ class MarketAtomEnvInfoDao {
atomStatusList = atomStatusList
)).orderBy(tAtom.CREATE_TIME.desc()).limit(1).fetchOne()
} else {
getAtomBaseInfoStep(dslContext, tAtom)
.join(tStoreProjectRel)
.on(tAtom.ATOM_CODE.eq(tStoreProjectRel.STORE_CODE))
.where(queryNormalAtomCondition(
val baseStep = getAtomBaseInfoStep(dslContext, tAtom)
if (queryProjectFlag) {
baseStep.join(tStoreProjectRel).on(tAtom.ATOM_CODE.eq(tStoreProjectRel.STORE_CODE))
}
baseStep.where(
queryNormalAtomCondition(
tAtom = tAtom,
tStoreProjectRel = tStoreProjectRel,
projectCode = projectCode,
atomCode = atomCode,
version = version,
atomStatusList = atomStatusList
)).orderBy(tAtom.CREATE_TIME.desc()).limit(1).fetchOne()
atomStatusList = atomStatusList,
queryProjectFlag = queryProjectFlag
)
).orderBy(tAtom.CREATE_TIME.desc()).limit(1).fetchOne()
}
}

Expand Down Expand Up @@ -164,7 +169,7 @@ class MarketAtomEnvInfoDao {
val conditions = mutableListOf<Condition>()
conditions.add(tAtom.ATOM_CODE.eq(atomCode))
conditions.add(tAtom.VERSION.like(VersionUtils.generateQueryVersion(version)))
if (atomStatusList != null && atomStatusList.isNotEmpty()) {
if (!atomStatusList.isNullOrEmpty()) {
conditions.add(tAtom.ATOM_STATUS.`in`(atomStatusList))
}
return conditions
Expand All @@ -187,12 +192,15 @@ class MarketAtomEnvInfoDao {
projectCode: String,
atomCode: String,
version: String,
atomStatusList: List<Byte>?
atomStatusList: List<Byte>?,
queryProjectFlag: Boolean = true
): MutableList<Condition> {
val conditions = getBaseQueryCondition(tAtom, atomCode, version, atomStatusList)
conditions.add(tAtom.DEFAULT_FLAG.eq(false)) // 查普通插件
conditions.add(tStoreProjectRel.PROJECT_CODE.eq(projectCode))
conditions.add(tStoreProjectRel.STORE_TYPE.eq(StoreTypeEnum.ATOM.type.toByte()))
if (queryProjectFlag) {
conditions.add(tStoreProjectRel.PROJECT_CODE.eq(projectCode))
conditions.add(tStoreProjectRel.STORE_TYPE.eq(StoreTypeEnum.ATOM.type.toByte()))
}
return conditions
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ import com.tencent.devops.common.redis.RedisLock
import com.tencent.devops.common.redis.RedisOperation
import com.tencent.devops.common.web.utils.I18nUtil
import com.tencent.devops.store.atom.dao.MarketAtomDao
import com.tencent.devops.store.pojo.atom.enums.AtomStatusEnum
import com.tencent.devops.store.pojo.common.ATOM_POST_VERSION_TEST_FLAG_KEY_PREFIX
import com.tencent.devops.store.pojo.common.STORE_LATEST_TEST_FLAG_KEY_PREFIX
import com.tencent.devops.store.pojo.common.publication.StoreBuildResultRequest
import com.tencent.devops.store.atom.service.AtomReleaseService
import com.tencent.devops.store.atom.service.MarketAtomService
import com.tencent.devops.store.common.service.AbstractStoreHandleBuildResultService
import com.tencent.devops.store.common.utils.VersionUtils
import com.tencent.devops.store.pojo.atom.enums.AtomStatusEnum
import com.tencent.devops.store.pojo.common.ATOM_POST_VERSION_TEST_FLAG_KEY_PREFIX
import com.tencent.devops.store.pojo.common.STORE_LATEST_TEST_FLAG_KEY_PREFIX
import com.tencent.devops.store.pojo.common.publication.StoreBuildResultRequest
import org.jooq.DSLContext
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import com.tencent.devops.store.atom.factory.AtomBusHandleFactory
import com.tencent.devops.store.atom.service.AtomService
import com.tencent.devops.store.atom.service.MarketAtomCommonService
import com.tencent.devops.store.atom.service.MarketAtomEnvService
import com.tencent.devops.store.common.configuration.StoreInnerPipelineConfig
import com.tencent.devops.store.common.dao.ClassifyDao
import com.tencent.devops.store.common.dao.StoreProjectRelDao
import com.tencent.devops.store.common.service.StoreI18nMessageService
Expand All @@ -63,8 +64,8 @@ import com.tencent.devops.store.pojo.common.ATOM_POST_ENTRY_PARAM
import com.tencent.devops.store.pojo.common.ATOM_POST_FLAG
import com.tencent.devops.store.pojo.common.ATOM_POST_NORMAL_PROJECT_FLAG_KEY_PREFIX
import com.tencent.devops.store.pojo.common.ATOM_POST_VERSION_TEST_FLAG_KEY_PREFIX
import com.tencent.devops.store.pojo.common.version.StoreVersion
import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum
import com.tencent.devops.store.pojo.common.version.StoreVersion
import java.time.LocalDateTime
import org.jooq.DSLContext
import org.slf4j.LoggerFactory
Expand All @@ -88,7 +89,8 @@ class MarketAtomEnvServiceImpl @Autowired constructor(
private val atomService: AtomService,
private val marketAtomCommonService: MarketAtomCommonService,
private val storeI18nMessageService: StoreI18nMessageService,
private val redisOperation: RedisOperation
private val redisOperation: RedisOperation,
private val storeInnerPipelineConfig: StoreInnerPipelineConfig
) : MarketAtomEnvService {

private val logger = LoggerFactory.getLogger(MarketAtomEnvServiceImpl::class.java)
Expand Down Expand Up @@ -263,12 +265,15 @@ class MarketAtomEnvServiceImpl @Autowired constructor(
AtomStatusEnum.UNDERCARRIAGING.status.toByte(),
AtomStatusEnum.UNDERCARRIAGED.status.toByte()
)
val buildingFlag =
projectCode == storeInnerPipelineConfig.innerPipelineProject && atomStatus == AtomStatusEnum.BUILDING.status.toByte()
val atomStatusList = getAtomStatusList(
atomStatus = atomStatus,
version = version,
normalStatusList = normalStatusList,
atomCode = atomCode,
projectCode = projectCode
projectCode = projectCode,
queryTestFlag = buildingFlag
)
val atomDefaultFlag = marketAtomCommonService.isPublicAtom(atomCode)
val atomBaseInfoRecord = marketAtomEnvInfoDao.getProjectAtomBaseInfo(
Expand All @@ -277,7 +282,8 @@ class MarketAtomEnvServiceImpl @Autowired constructor(
atomCode = atomCode,
version = version,
atomDefaultFlag = atomDefaultFlag,
atomStatusList = atomStatusList
atomStatusList = atomStatusList,
queryProjectFlag = !buildingFlag
) ?: throw ErrorCodeException(
errorCode = CommonMessageCode.PARAMETER_IS_INVALID,
params = arrayOf("[project($projectCode)-plugin($atomCode)]")
Expand Down Expand Up @@ -414,7 +420,8 @@ class MarketAtomEnvServiceImpl @Autowired constructor(
version: String,
normalStatusList: List<Byte>,
atomCode: String,
projectCode: String
projectCode: String,
queryTestFlag: Boolean
): List<Byte> {
return if (atomStatus != null) {
mutableListOf(atomStatus)
Expand All @@ -428,7 +435,13 @@ class MarketAtomEnvServiceImpl @Autowired constructor(
this.add(AtomStatusEnum.RELEASED.status.toByte())
}
}
val flag = storeProjectRelDao.isTestProjectCode(dslContext, atomCode, StoreTypeEnum.ATOM, projectCode)
val flag = queryTestFlag ||
storeProjectRelDao.isTestProjectCode(
dslContext = dslContext,
storeCode = atomCode,
storeType = StoreTypeEnum.ATOM,
projectCode = projectCode
)
if (flag) {
// 初始化项目或者调试项目有权查处于测试中、审核中的插件
this.addAll(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@ class StoreInnerPipelineConfig {

@Value("\${store.innerPipeline.user:}")
val innerPipelineUser: String = ""

@Value("\${store.innerPipeline.gray.project:}")
val innerPipelineGrayProject: String = ""

@Value("\${store.innerPipeline.gray.user:}")
val innerPipelineGrayUser: String = ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,9 @@ abstract class AbstractStoreCommonDao {
): StoreBaseInfo?

abstract fun getStoreRepoHashIdByCode(dslContext: DSLContext, storeCode: String): String?

abstract fun getStoreCodeById(
dslContext: DSLContext,
storeId: String
): String?
}
Loading

0 comments on commit 6ef228b

Please sign in to comment.