From 7098ef04986f5ba3e6715aa63ee925203ca6f419 Mon Sep 17 00:00:00 2001 From: carlyin Date: Wed, 18 Dec 2024 11:11:24 +0800 Subject: [PATCH 1/2] =?UTF-8?q?pref:nodejs=E5=AE=89=E8=A3=85=E5=8C=85?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=9C=B0=E5=9D=80=E5=9F=9F=E5=90=8D=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=8C=89=E9=83=A8=E7=BD=B2=E7=8E=AF=E5=A2=83=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=20#11327?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tencent/devops/common/api/auth/Header.kt | 1 + .../store/api/common/BuildStoreResource.kt | 4 ++ .../pojo/common/env/StorePkgRunEnvInfo.kt | 2 +- .../resources/BuildStoreResourceImpl.kt | 1 + .../common/service/AbstractDomainService.kt | 38 +++++++++++++++++++ .../service/StorePkgRunEnvInfoService.kt | 2 + .../impl/StorePkgRunEnvInfoServiceImpl.kt | 19 ++++++++-- 7 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/AbstractDomainService.kt diff --git a/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/auth/Header.kt b/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/auth/Header.kt index 22c0d182e12a..0338fc5c4aa4 100644 --- a/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/auth/Header.kt +++ b/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/auth/Header.kt @@ -121,3 +121,4 @@ const val AUTH_HEADER_DEVOPS_STORE_CODE: String = "X-DEVOPS-STORE-CODE" const val AUTH_HEADER_DEVOPS_STORE_TYPE: String = "X-DEVOPS-STORE-TYPE" const val AUTH_HEADER_DEVOPS_STORE_VERSION: String = "X-DEVOPS-STORE-VERSION" const val AUTH_HEADER_DEVOPS_SIGN_FILE_NAME: String = "X-DEVOPS-SIGN-FILE-NAME" +const val AUTH_HEADER_DEVOPS_ENV: String = "X-DEVOPS-ENV" diff --git a/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/api/common/BuildStoreResource.kt b/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/api/common/BuildStoreResource.kt index 7cbb54d9a152..4a27a9acecbe 100644 --- a/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/api/common/BuildStoreResource.kt +++ b/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/api/common/BuildStoreResource.kt @@ -28,6 +28,7 @@ package com.tencent.devops.store.api.common import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_BUILD_ID +import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_ENV import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_VM_SEQ_ID import com.tencent.devops.common.api.pojo.Result import com.tencent.devops.store.pojo.common.sensitive.SensitiveConfResp @@ -73,6 +74,9 @@ interface BuildStoreResource { @GET @Path("/pkg/envs/types/{storeType}/languages/{language}/versions/{runtimeVersion}/get") fun getStorePkgRunEnvInfo( + @Parameter(description = "环境信息", required = false) + @HeaderParam(AUTH_HEADER_DEVOPS_ENV) + devopsEnv: String? = null, @Parameter(description = "组件类型", required = true) @PathParam("storeType") storeType: StoreTypeEnum, diff --git a/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/pojo/common/env/StorePkgRunEnvInfo.kt b/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/pojo/common/env/StorePkgRunEnvInfo.kt index 42868a44fb31..5cf648db098c 100644 --- a/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/pojo/common/env/StorePkgRunEnvInfo.kt +++ b/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/pojo/common/env/StorePkgRunEnvInfo.kt @@ -46,7 +46,7 @@ data class StorePkgRunEnvInfo( @get:Schema(title = "安装包名称", required = true) val pkgName: String, @get:Schema(title = "安装包下载路径", required = true) - val pkgDownloadPath: String, + var pkgDownloadPath: String, @get:Schema(title = "是否为默认安装包", required = true) val defaultFlag: Boolean, @get:Schema(title = "添加用户", required = true) diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/resources/BuildStoreResourceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/resources/BuildStoreResourceImpl.kt index 1dc6edf00a6d..be6644127208 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/resources/BuildStoreResourceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/resources/BuildStoreResourceImpl.kt @@ -62,6 +62,7 @@ class BuildStoreResourceImpl @Autowired constructor( } override fun getStorePkgRunEnvInfo( + devopsEnv: String?, storeType: StoreTypeEnum, language: String, runtimeVersion: String, diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/AbstractDomainService.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/AbstractDomainService.kt new file mode 100644 index 000000000000..7a5c0d9bc389 --- /dev/null +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/AbstractDomainService.kt @@ -0,0 +1,38 @@ +/* + * 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.common.service + +abstract class AbstractDomainService { + + /** + * 转换url域名 + * @param url url地址 + * @return 转换域名后的url地址 + */ + abstract fun convertDomain(url: String): String +} diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/StorePkgRunEnvInfoService.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/StorePkgRunEnvInfoService.kt index 6fa42ee889bd..1d252837381a 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/StorePkgRunEnvInfoService.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/StorePkgRunEnvInfoService.kt @@ -70,6 +70,7 @@ interface StorePkgRunEnvInfoService { /** * 获取安装包运行时环境信息 + * @param devopsEnv 环境信息 * @param userId userId * @param storeType 组件类型 * @param language 开发语言 @@ -79,6 +80,7 @@ interface StorePkgRunEnvInfoService { * @return 安装包运行时环境信息 */ fun getStorePkgRunEnvInfo( + devopsEnv: String? = null, userId: String, storeType: StoreTypeEnum, language: String, diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StorePkgRunEnvInfoServiceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StorePkgRunEnvInfoServiceImpl.kt index 94d852149a0b..3cf5fcb28845 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StorePkgRunEnvInfoServiceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StorePkgRunEnvInfoServiceImpl.kt @@ -27,12 +27,14 @@ package com.tencent.devops.store.common.service.impl import com.github.benmanes.caffeine.cache.Caffeine -import com.tencent.devops.store.common.dao.StorePkgRunEnvInfoDao +import com.tencent.devops.common.service.utils.SpringContextUtil import com.tencent.devops.store.atom.factory.AtomBusHandleFactory +import com.tencent.devops.store.common.dao.StorePkgRunEnvInfoDao +import com.tencent.devops.store.common.service.AbstractDomainService +import com.tencent.devops.store.common.service.StorePkgRunEnvInfoService +import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum import com.tencent.devops.store.pojo.common.env.StorePkgRunEnvInfo import com.tencent.devops.store.pojo.common.env.StorePkgRunEnvRequest -import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum -import com.tencent.devops.store.common.service.StorePkgRunEnvInfoService import org.jooq.DSLContext import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service @@ -70,6 +72,7 @@ class StorePkgRunEnvInfoServiceImpl @Autowired constructor( } override fun getStorePkgRunEnvInfo( + devopsEnv: String?, userId: String, storeType: StoreTypeEnum, language: String, @@ -88,7 +91,7 @@ class StorePkgRunEnvInfoServiceImpl @Autowired constructor( val atomBusHandleService = AtomBusHandleFactory.createAtomBusHandleService(language) val finalOsName = atomBusHandleService.handleOsName(osName) val finalOsArch = atomBusHandleService.handleOsArch(osName, osArch) - val key = "PkgRunEnvInfo:$storeType:$language:$finalOsName:$finalOsArch:$convertRuntimeVersion" + val key = "PkgRunEnvInfo:$devopsEnv:$storeType:$language:$finalOsName:$finalOsArch:$convertRuntimeVersion" var storePkgRunEnvInfo = pkgRunEnvInfoCache.getIfPresent(key) if (storePkgRunEnvInfo != null) { // 缓存中取到了安装包运行时环境信息则直接返回 @@ -113,6 +116,14 @@ class StorePkgRunEnvInfoServiceImpl @Autowired constructor( null } else { storePkgRunEnvInfo = storePkgRunEnvInfoDao.convert(storePkgRunEnvInfoRecord) + if (!devopsEnv.isNullOrBlank()) { + // 转换域名 + val beanName = "${devopsEnv.uppercase()}_DOMAIN_SERVICE" + if (SpringContextUtil.isBeanExist(beanName)) { + val domainService = SpringContextUtil.getBean(AbstractDomainService::class.java, beanName) + storePkgRunEnvInfo.pkgDownloadPath = domainService.convertDomain(storePkgRunEnvInfo.pkgDownloadPath) + } + } // 把安装包运行时环境信息放入缓存 pkgRunEnvInfoCache.put(key, storePkgRunEnvInfo) storePkgRunEnvInfo From f5e156e1ae65021670c40ed99eeb9272b6f5885a Mon Sep 17 00:00:00 2001 From: carlyin Date: Wed, 18 Dec 2024 11:21:27 +0800 Subject: [PATCH 2/2] =?UTF-8?q?pref:nodejs=E5=AE=89=E8=A3=85=E5=8C=85?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=9C=B0=E5=9D=80=E5=9F=9F=E5=90=8D=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=8C=89=E9=83=A8=E7=BD=B2=E7=8E=AF=E5=A2=83=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=20#11327?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/store/common/resources/BuildStoreResourceImpl.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/resources/BuildStoreResourceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/resources/BuildStoreResourceImpl.kt index be6644127208..ac8c556b4380 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/resources/BuildStoreResourceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/resources/BuildStoreResourceImpl.kt @@ -71,6 +71,7 @@ class BuildStoreResourceImpl @Autowired constructor( ): Result { return Result( storePkgRunEnvInfoService.getStorePkgRunEnvInfo( + devopsEnv = devopsEnv, userId = "", storeType = storeType, language = language,