Skip to content

Commit

Permalink
feat:流水线查看和构建详情查看配置界面敏感字段展示优化 #11019
Browse files Browse the repository at this point in the history
  • Loading branch information
yjieliang committed Jan 9, 2025
1 parent 8a707c1 commit 8838f29
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,60 @@

package com.tencent.devops.process.engine.service

import com.tencent.devops.common.api.constant.KEY_VERSION
import com.tencent.devops.common.api.util.JsonUtil
import com.tencent.devops.common.pipeline.pojo.element.Element
import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildAtomElement
import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildLessAtomElement
import com.tencent.devops.common.redis.RedisOperation
import com.tencent.devops.process.engine.dao.PipelineInfoDao
import com.tencent.devops.store.pojo.common.ATOM_SENSITIVE_PARAM_KEY_PREFIX
import com.tencent.devops.store.pojo.common.STORE_NORMAL_PROJECT_RUN_INFO_KEY_PREFIX
import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum
import org.jooq.DSLContext
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

@Service
class PipelineInfoService @Autowired constructor(
private val dslContext: DSLContext,
private val pipelineInfoDao: PipelineInfoDao
private val pipelineInfoDao: PipelineInfoDao,
private val redisOperation: RedisOperation
) {

fun getPipelineName(projectId: String, pipelineId: String): String? {
return pipelineInfoDao.getPipelineInfo(dslContext, projectId, pipelineId)?.pipelineName
}

// 敏感入参解析
fun transferSensitiveParam(projectTestAtomCodes: List<String>, element: Element) {
if (element is MarketBuildAtomElement || element is MarketBuildLessAtomElement) {
val atomCode = element.getAtomCode()
val version = element.version
val hashKey = if (version.contains(".*")) {
var latestVersion: String? = null
if (projectTestAtomCodes.contains(atomCode)) {
latestVersion = version
}
if (latestVersion.isNullOrBlank()) {
val atomRunInfoStr = redisOperation.hget(
key = "$STORE_NORMAL_PROJECT_RUN_INFO_KEY_PREFIX:${StoreTypeEnum.ATOM.name}:$atomCode",
hashKey = version
)
val atomRunInfo = atomRunInfoStr?.let { JsonUtil.toMap(it) }
latestVersion = atomRunInfo?.get(KEY_VERSION).toString()
}
latestVersion
} else {
version
}
val param = redisOperation.hget(
key = "$ATOM_SENSITIVE_PARAM_KEY_PREFIX:$atomCode",
hashKey = hashKey
)
if (!param.isNullOrBlank()) {
element.transferSensitiveParam(param.split(","))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ class PipelineRepositoryService constructor(
private val transferService: PipelineTransferYamlService,
private val redisOperation: RedisOperation,
private val pipelineYamlInfoDao: PipelineYamlInfoDao,
private val pipelineAsCodeService: PipelineAsCodeService
private val pipelineAsCodeService: PipelineAsCodeService,
private val pipelineInfoService: PipelineInfoService
) {

companion object {
Expand Down Expand Up @@ -1358,7 +1359,7 @@ class PipelineRepositoryService constructor(
}
e.additionalOptions?.customEnv = null
if (checkPermission != true) {
transferSensitiveParam(testAtomCodes ?: emptyList(), e)
pipelineInfoService.transferSensitiveParam(testAtomCodes ?: emptyList(), e)
}
}
}
Expand All @@ -1367,38 +1368,6 @@ class PipelineRepositoryService constructor(
return resource
}

// 敏感入参解析
fun transferSensitiveParam(projectTestAtomCodes: List<String>, element: Element) {
if (element is MarketBuildAtomElement || element is MarketBuildLessAtomElement) {
val atomCode = element.getAtomCode()
val version = element.version
val hashKey = if (version.contains(".*")) {
var latestVersion: String? = null
if (projectTestAtomCodes.contains(atomCode)) {
latestVersion = version
}
if (latestVersion.isNullOrBlank()) {
val atomRunInfoStr = redisOperation.hget(
key = "$STORE_NORMAL_PROJECT_RUN_INFO_KEY_PREFIX:${StoreTypeEnum.ATOM.name}:$atomCode",
hashKey = version
)
val atomRunInfo = atomRunInfoStr?.let { JsonUtil.toMap(it) }
latestVersion = atomRunInfo?.get(KEY_VERSION).toString()
}
latestVersion
} else {
version
}
val param = redisOperation.hget(
key = "$ATOM_SENSITIVE_PARAM_KEY_PREFIX:$atomCode",
hashKey = hashKey
)
if (!param.isNullOrBlank()) {
element.transferSensitiveParam(param.split(","))
}
}
}

fun getDraftVersionResource(
projectId: String,
pipelineId: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import com.tencent.devops.process.engine.dao.PipelineTriggerReviewDao
import com.tencent.devops.process.engine.pojo.BuildInfo
import com.tencent.devops.process.engine.service.PipelineBuildDetailService
import com.tencent.devops.process.engine.service.PipelineElementService
import com.tencent.devops.process.engine.service.PipelineInfoService
import com.tencent.devops.process.engine.service.PipelineRepositoryService
import com.tencent.devops.process.engine.utils.ContainerUtils
import com.tencent.devops.process.pojo.BuildStageStatus
Expand Down Expand Up @@ -108,14 +109,15 @@ class PipelineBuildRecordService @Autowired constructor(
private val recordContainerDao: BuildRecordContainerDao,
private val recordTaskDao: BuildRecordTaskDao,
private val client: Client,
private val pipelineInfoService: PipelineInfoService,
recordModelService: PipelineRecordModelService,
pipelineResourceDao: PipelineResourceDao,
pipelineBuildDao: PipelineBuildDao,
pipelineResourceVersionDao: PipelineResourceVersionDao,
pipelineElementService: PipelineElementService,
redisOperation: RedisOperation,
stageTagService: StageTagService,
pipelineEventDispatcher: PipelineEventDispatcher,
pipelineEventDispatcher: PipelineEventDispatcher
) : BaseBuildRecordService(
dslContext = dslContext,
buildRecordModelDao = recordModelDao,
Expand Down Expand Up @@ -262,7 +264,7 @@ class PipelineBuildRecordService @Autowired constructor(
}
if (sensitiveFlag != true) {
container.elements.forEach { e ->
pipelineRepositoryService.transferSensitiveParam(testAtomCodes, e)
pipelineInfoService.transferSensitiveParam(testAtomCodes, e)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import com.tencent.devops.common.pipeline.pojo.transfer.TransferResponse
import com.tencent.devops.common.pipeline.pojo.transfer.YamlWithVersion
import com.tencent.devops.process.engine.dao.PipelineInfoDao
import com.tencent.devops.process.engine.dao.PipelineYamlInfoDao
import com.tencent.devops.process.engine.service.PipelineInfoService
import com.tencent.devops.process.engine.service.PipelineRepositoryService
import com.tencent.devops.process.pojo.pipeline.PipelineResourceVersion
import com.tencent.devops.process.yaml.pojo.TemplatePath
Expand Down Expand Up @@ -90,7 +91,7 @@ class PipelineTransferYamlService @Autowired constructor(
private val pipelineYamlInfoDao: PipelineYamlInfoDao,
private val client: Client,
private val yamlSchemaCheck: CodeSchemaCheck,
private val pipelineRepositoryService: PipelineRepositoryService
private val pipelineInfoService: PipelineInfoService
) {

companion object {
Expand Down Expand Up @@ -230,7 +231,7 @@ class PipelineTransferYamlService @Autowired constructor(
private fun transferElementSensitiveParam(projectTestAtomCodes: List<String>?, containers: List<Container>) {
containers.forEach {
it.elements.forEach { e ->
pipelineRepositoryService.transferSensitiveParam(
pipelineInfoService.transferSensitiveParam(
projectTestAtomCodes = projectTestAtomCodes ?: emptyList(),
element = e
)
Expand Down

0 comments on commit 8838f29

Please sign in to comment.