Unverified Commit fa8e784c authored by irwinsun's avatar irwinsun Committed by GitHub
Browse files

Merge pull request #4044 from ddlin0719/feat_3987

feat: CodeCC 同步代码到release-1.3分支 #3987
parents 784a3001 56075c6f
Showing with 230 additions and 41 deletions
+230 -41
......@@ -45,6 +45,8 @@ BK_CI_REDIS_HOST=redis-ci.service.consul
BK_CI_REDIS_PASSWORD=
# BK_CI_REDIS_PORT默认为6379. 按需修改.
BK_CI_REDIS_PORT=6379
# BK_PAAS_PRIVATE_URL无默认值. 无需修改. 声明依赖, 蓝鲸环境下会自动填充. 其他环境无需填写.
BK_PAAS_PRIVATE_URL=
##########
# 1-基础配置
......@@ -115,6 +117,8 @@ BK_CODECC_REDIS_PORT=6379
BK_CODECC_DISPATCH_IMAGE_NAME=bkci/ci
# BK_CODECC_DISPATCH_IMAGE_VERSION默认为latest. 按需修改. codecc独立入口任务用到的镜像版本
BK_CODECC_DISPATCH_IMAGE_VERSION=latest
# BK_CODECC_DISPATCH_IMAGE_VERSION默认为latest. 按需修改. codecc独立入口任务用到的镜像版本
BK_CODECC_DISPATCH_BUILD_TYPE=docker
# BK_CODECC_ENCRYPTOR_KEY默认为abcde. 按需修改.
BK_CODECC_ENCRYPTOR_KEY=abcde
# BK_CODECC_TASK_ANALYSIS_MAX_HOUR默认为7. 无需修改. 任务分析的最大时间, 单位小时
......@@ -141,3 +145,13 @@ BK_CODECC_REPORT_API_PORT=38083
BK_CODECC_SCHEDULE_API_PORT=38086
# BK_CODECC_TASK_API_PORT默认为38087. 无需修改.
BK_CODECC_TASK_API_PORT=38087
# codecc插件 atom code
BK_CODECC_ATOM_CODE=CodeccCheckAtom
# codecc插件 atom 版本
BK_CODECC_ATOM_CODE_VERSION=1.*
# codecc独立入口镜像类型
BK_CODECC_PIPELINE_IMAGE_TYPE=THIRD
# 是否使用旧的GITHUB插件
GITHUB_SCM_TYPE_OLD=true
# 是否使用旧的SVN插件
SVN_SCM_TYPE_OLD=true
\ No newline at end of file
......@@ -53,9 +53,7 @@ enum class AuthResourceType(val value: String) {
WETEST_TASK("task"), // 体验任务
WETEST_EMAIL_GROUP("email_group"), // 体验组
PROJECT("project"), // 项目管理
CODECC_TASK("codecc_task"); // codecc任务
PROJECT("project"); // 项目管理
companion object {
fun get(value: String): AuthResourceType {
......
......@@ -29,20 +29,31 @@ package com.tencent.devops.plugin.utils
import com.tencent.devops.common.client.Client
import com.tencent.devops.common.service.utils.SpringContextUtil
import com.tencent.devops.plugin.codecc.CodeccUtils
import com.tencent.devops.plugin.codecc.config.CodeccConfig
import com.tencent.devops.store.api.atom.ServiceMarketAtomResource
import org.apache.commons.lang3.StringUtils
object ElementUtils {
private lateinit var codeccV3AtomCode: String
fun getElementCnName(classType: String, projectId: String): String {
val map = getProjectElement(projectId)
if (CodeccUtils.isCodeccAtom(classType)) {
return map[CodeccUtils.BK_CI_CODECC_V3_ATOM] ?: ""
return map[getCodeCCV3AtomCode()] ?: ""
}
return map[classType] ?: ""
}
fun getCodeCCV3AtomCode(): String {
if (StringUtils.isBlank(codeccV3AtomCode)) {
codeccV3AtomCode = SpringContextUtil.getBean(CodeccConfig::class.java).codeccV3Atom
}
return codeccV3AtomCode
}
private fun getProjectElement(projectId: String): Map<String/* atomCode */, String/* cnName */> {
val client = SpringContextUtil.getBean(Client::class.java)
return client.get(ServiceMarketAtomResource::class).getProjectElements(projectId).data!!
......
......@@ -28,12 +28,17 @@ package com.tencent.devops.plugin.codecc
import com.tencent.devops.common.pipeline.pojo.element.agent.LinuxCodeCCScriptElement
import com.tencent.devops.common.pipeline.pojo.element.agent.LinuxPaasCodeCCScriptElement
import com.tencent.devops.common.service.utils.SpringContextUtil
import com.tencent.devops.plugin.codecc.config.CodeccConfig
object CodeccUtils {
const val BK_CI_CODECC_TASK_ID = "BK_CI_CODECC_TASK_ID"
const val BK_CI_CODECC_V3_ATOM = "CodeccCheckAtomDebug"
private var codeccConfig: CodeccConfig? = null
// 主要是因为codecc插件版本太多,又要统一处理,故加此map
private lateinit var realAtomCodeMap: Map<String, String>
fun isCodeccAtom(atomName: String?): Boolean {
return isCodeccNewAtom(atomName) || isCodeccV1Atom(atomName)
......@@ -49,18 +54,30 @@ object CodeccUtils {
}
fun isCodeccV2Atom(atomName: String?): Boolean {
return atomName == "CodeccCheckAtom"
return atomName == getCodeCCConfig().codeccV2Atom
}
fun isCodeccV3Atom(atomName: String?): Boolean {
return atomName == BK_CI_CODECC_V3_ATOM
return atomName == getCodeCCConfig().codeccV3Atom
}
// 主要是因为codecc插件版本太多,又要统一处理,故加此map
val realAtomCodeMap = mapOf(
LinuxCodeCCScriptElement.classType to BK_CI_CODECC_V3_ATOM,
LinuxPaasCodeCCScriptElement.classType to BK_CI_CODECC_V3_ATOM,
"CodeccCheckAtom" to BK_CI_CODECC_V3_ATOM,
BK_CI_CODECC_V3_ATOM to BK_CI_CODECC_V3_ATOM
)
fun getCodeCCConfig(): CodeccConfig {
if (codeccConfig == null) {
codeccConfig = SpringContextUtil.getBean(CodeccConfig::class.java)
}
return codeccConfig!!
}
fun getRealAtomCodeMap(): Map<String, String> {
val config = getCodeCCConfig()
if (realAtomCodeMap == null) {
realAtomCodeMap = mapOf(
LinuxCodeCCScriptElement.classType to config.codeccV3Atom,
LinuxPaasCodeCCScriptElement.classType to config.codeccV3Atom,
config.codeccV2Atom to config.codeccV3Atom,
config.codeccV3Atom to config.codeccV3Atom
)
}
return realAtomCodeMap
}
}
\ No newline at end of file
......@@ -35,27 +35,33 @@ class CodeccConfig {
/**
* 代码检查网关地址
*/
@Value("\${codeccGateway.gateway:}")
@Value("\${plugin.codecc.gateway:}")
val codeccApiGateWay: String = ""
@Value("\${codeccGateway.proxy:}")
@Value("\${plugin.codecc.proxy:}")
val codeccApiProxyGateWay: String = ""
@Value("\${codeccGateway.api.createTask:/ms/task/api/service/task}")
@Value("\${plugin.codecc.api.createTask:/ms/task/api/service/task}")
val createPath = "/ms/task/api/service/task"
@Value("\${codeccGateway.api.updateTask:/ms/task/api/service/task}")
@Value("\${plugin.codecc.api.updateTask:/ms/task/api/service/task}")
val updatePath = "/ms/task/api/service/task"
@Value("\${codeccGateway.api.checkTaskExists:/ms/task/api/service/task/exists}")
@Value("\${plugin.codecc.api.checkTaskExists:/ms/task/api/service/task/exists}")
val existPath = "/ms/task/api/service/task/exists"
@Value("\${codeccGateway.api.deleteTask:/ms/task/api/service/task}")
@Value("\${plugin.codecc.api.deleteTask:/ms/task/api/service/task}")
val deletePath = "/ms/task/api/service/task"
@Value("\${codeccGateway.api.codeCheckReport:/api}")
@Value("\${plugin.codecc.api.codeCheckReport:/api}")
val report = ""
@Value("\${codeccGateway.api.getRuleSets:/blueShield/getRuleSetsPath}")
@Value("\${plugin.codecc.api.getRuleSets:/blueShield/getRuleSetsPath}")
val getRuleSetsPath = ""
@Value("\${pipeline.atomCode.codeccV2:CodeccCheckAtom}")
val codeccV2Atom = ""
@Value("\${pipeline.atomCode.codecc:CodeccCheckAtomDebug}")
val codeccV3Atom = ""
}
\ No newline at end of file
......@@ -174,7 +174,7 @@ class QualityPipelineService @Autowired constructor(
}
private fun getRealAtomCode(atomCode: String): String {
return CodeccUtils.realAtomCodeMap[atomCode] ?: atomCode
return CodeccUtils.getRealAtomCodeMap()[atomCode] ?: atomCode
}
data class CheckElement(
......
......@@ -29,20 +29,31 @@ package com.tencent.devops.quality.util
import com.tencent.devops.common.client.Client
import com.tencent.devops.common.service.utils.SpringContextUtil
import com.tencent.devops.plugin.codecc.CodeccUtils
import com.tencent.devops.plugin.codecc.config.CodeccConfig
import com.tencent.devops.store.api.atom.ServiceMarketAtomResource
import org.apache.commons.lang3.StringUtils
object ElementUtils {
private lateinit var codeccV3AtomCode: String
fun getElementCnName(classType: String, projectId: String): String {
val map = getProjectElement(projectId)
if (CodeccUtils.isCodeccAtom(classType)) {
return map[CodeccUtils.BK_CI_CODECC_V3_ATOM] ?: ""
return map[getCodeCCV3AtomCode()] ?: ""
}
return map[classType] ?: ""
}
fun getCodeCCV3AtomCode(): String {
if (StringUtils.isBlank(codeccV3AtomCode)) {
codeccV3AtomCode = SpringContextUtil.getBean(CodeccConfig::class.java).codeccV3Atom
}
return codeccV3AtomCode
}
fun getProjectElement(projectId: String): Map<String/* atomCode */, String/* cnName */> {
val client = SpringContextUtil.getBean(Client::class.java)
return client.get(ServiceMarketAtomResource::class).getProjectElements(projectId).data!!
......
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.devops.common.auth.GongfengAuthAutoConfiguration
\ No newline at end of file
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.devops.common.auth.MockAuthExAutoConfiguration
\ No newline at end of file
......@@ -34,11 +34,14 @@ import com.tencent.bk.sdk.iam.service.impl.TokenServiceImpl
import com.tencent.devops.common.auth.api.*
import com.tencent.devops.common.auth.api.external.AuthTaskService
import com.tencent.devops.common.auth.code.PipelineAuthServiceCode
import com.tencent.devops.common.auth.service.IamEsbService
import com.tencent.devops.common.auth.utils.CodeCCAuthResourceApi
import com.tencent.devops.common.client.Client
import com.tencent.devops.common.redis.RedisOperation
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.autoconfigure.AutoConfigureOrder
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
import org.springframework.context.annotation.Bean
......@@ -83,15 +86,22 @@ class V3AuthExAutoConfiguration {
codeccAuthPermissionApi = codeccAuthPermissionStrApi)
@Bean
@Primary
fun authExRegisterApi(authResourceApi: AuthResourceApi) =
fun authExRegisterApi(authResourceApi: CodeCCAuthResourceApi) =
V3AuthExRegisterApi(authResourceApi)
@Bean
@Primary
fun codeCCV3AuthPermissionApi(redisOperation: RedisOperation) =
CodeCCV3AuthPermissionApi(authHelper(), policyService(), redisOperation)
@Bean
fun codeCCV3AuthResourceApi(redisOperation: RedisOperation,
iamEsbService: IamEsbService,
iamConfiguration: IamConfiguration) =
CodeCCAuthResourceApi(iamEsbService, iamConfiguration)
@Bean
fun iamEsbService() = IamEsbService()
@Bean
fun policyService() = PolicyServiceImpl(iamConfiguration(), httpService())
......
......@@ -98,17 +98,7 @@ class V3AuthExPermissionApi(client: Client,
projectId: String,
actions: Set<String>
): List<BkAuthExResourceActionModel> {
return actions.map { action ->
val result = codeccAuthPermissionApi.validateUserResourcePermission(
user = user,
serviceCode = CodeCCAuthServiceCode(),
resourceType = CODECC_RESOURCE_TYPE,
projectCode = projectId,
resourceCode = taskId,
permission = action,
relationResourceType = CODECC_RESOURCE_TYPE)
BkAuthExResourceActionModel(isPass = result)
}
return listOf(BkAuthExResourceActionModel(isPass = true))
}
/**
......
package com.tencent.devops.common.auth.api
import com.tencent.devops.common.auth.api.external.AuthExRegisterApi
import com.tencent.devops.common.auth.pojo.CodeCCAuthResourceType
import com.tencent.devops.common.auth.pojo.CodeCCAuthServiceCode
import com.tencent.devops.common.auth.utils.CodeCCAuthResourceApi
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Qualifier
class V3AuthExRegisterApi @Autowired constructor(
private val authResourceApi: AuthResourceApi
private val authResourceApi: CodeCCAuthResourceApi
): AuthExRegisterApi {
override fun registerCodeCCTask(user: String, taskId: String, taskName: String, projectId: String): Boolean {
authResourceApi.createResource(user, CodeCCAuthServiceCode(), AuthResourceType.CODECC_TASK, projectId, taskId, taskName)
authResourceApi.createResource(user, CodeCCAuthResourceType.CODECC_TASK, projectId, taskId, taskName)
return true
}
......
package com.tencent.devops.common.auth.pojo
/*
* 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.
*/
enum class CodeCCAuthResourceType(val value: String) {
CODECC_TASK("codecc_task"); // codecc任务
}
\ No newline at end of file
package com.tencent.devops.common.auth.utils
import com.tencent.bk.sdk.iam.config.IamConfiguration
import com.tencent.devops.common.auth.api.AuthResourceApi
import com.tencent.devops.common.auth.api.AuthResourceType
import com.tencent.devops.common.auth.api.pojo.BkAuthGroup
import com.tencent.devops.common.auth.api.pojo.ResourceRegisterInfo
import com.tencent.devops.common.auth.code.AuthServiceCode
import com.tencent.devops.common.auth.pojo.AncestorsApiReq
import com.tencent.devops.common.auth.pojo.CodeCCAuthResourceType
import com.tencent.devops.common.auth.pojo.CodeCCAuthServiceCode
import com.tencent.devops.common.auth.pojo.IamCreateApiReq
import com.tencent.devops.common.auth.service.IamEsbService
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
/*
* 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.
*/
class CodeCCAuthResourceApi @Autowired constructor(
val iamEsbService: IamEsbService,
val iamConfiguration: IamConfiguration
) {
fun createResource(user: String, resourceType: CodeCCAuthResourceType, projectCode: String, resourceId: String, resourceName: String) {
}
fun doCreateResource(user: String, resourceType: CodeCCAuthResourceType, projectCode: String, resourceId: String, resourceName: String) {
logger.info("v3 createResource projectCode[$projectCode] resourceName[$resourceName]" +
" resourceId[$resourceId] resourceType[${resourceType.value}]")
val ancestors = mutableListOf<AncestorsApiReq>()
ancestors.add(AncestorsApiReq(
system = iamConfiguration.systemId,
id = projectCode,
type = AuthResourceType.PROJECT.value
))
val iamApiReq = IamCreateApiReq(
creator = user,
name = resourceName,
id = resourceId,
type = resourceType.value,
system = iamConfiguration.systemId,
ancestors = ancestors,
bk_app_code = "",
bk_app_secret = "",
bk_username = user
)
iamEsbService.createRelationResource(iamApiReq)
}
companion object {
val logger = LoggerFactory.getLogger(this::class.java)
}
}
\ No newline at end of file
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.devops.common.auth.V3AuthExAutoConfiguration
\ No newline at end of file
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.devops.common.client.ClientAutoConfiguration
\ No newline at end of file
g.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.devops.common.redis.RedisAutoConfiguration
\ No newline at end of file
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.devops.common.service.ServiceAutoConfiguration,\
com.tencent.devops.common.service.AsyncTaskConfiguration
org.springframework.context.ApplicationContextInitializer=\
com.tencent.devops.common.service.Log4j2Initializer
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.devops.common.web.WebAutoConfiguration,\
com.tencent.devops.common.web.mq.RabbitMQAutoConfiguration,\
com.tencent.devops.common.web.aop.OperationHistoryAop
......@@ -18,7 +18,7 @@ import javax.ws.rs.core.MediaType;
* @date 2020/11/2
*/
@Api(tags = {"BUILD_CHECKER"}, description = "工具执行记录接口")
@Path("/build/taskLogOverview/")
@Path("/build/taskLogOverview")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public interface BuildTaskLogOverviewResource {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment