From 9c6c0485312b90a8bfa4f0d2f7d059a4dbf002e2 Mon Sep 17 00:00:00 2001 From: zacyanliu Date: Thu, 7 Sep 2023 16:07:17 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E8=8A=82=E7=82=B9=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E9=80=BB=E8=BE=91=E8=B0=83=E6=95=B4=20#1067?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/artifact/api/ArtifactInfo.kt | 21 ++++++++++++++++++- .../listener/ArtifactDownloadListener.kt | 2 +- .../context/ArtifactContextHolder.kt | 9 ++++---- .../repository/local/LocalRepository.kt | 2 +- .../repository/redirect/CosRedirectService.kt | 10 ++------- .../redirect/EdgeNodeRedirectService.kt | 10 ++------- .../repository/ComposerLocalRepository.kt | 4 ++-- .../artifact/GenericLocalRepository.kt | 6 +----- .../bkrepo/generic/service/DownloadService.kt | 2 +- .../repository/HelmLocalRepository.kt | 3 ++- .../repository/MavenLocalRepository.kt | 9 +++++--- .../repository/OciRegistryLocalRepository.kt | 6 ++++-- .../artifact/repository/RpmLocalRepository.kt | 2 +- 13 files changed, 47 insertions(+), 39 deletions(-) diff --git a/src/backend/common/common-artifact/artifact-api/src/main/kotlin/com/tencent/bkrepo/common/artifact/api/ArtifactInfo.kt b/src/backend/common/common-artifact/artifact-api/src/main/kotlin/com/tencent/bkrepo/common/artifact/api/ArtifactInfo.kt index f46e2015a3..0f9929effb 100644 --- a/src/backend/common/common-artifact/artifact-api/src/main/kotlin/com/tencent/bkrepo/common/artifact/api/ArtifactInfo.kt +++ b/src/backend/common/common-artifact/artifact-api/src/main/kotlin/com/tencent/bkrepo/common/artifact/api/ArtifactInfo.kt @@ -57,6 +57,21 @@ open class ArtifactInfo( private val normalizedUri = PathUtils.normalizeFullPath(artifactUri) + /** + * 构件实际映射路径, 默认情况为空 + * 存在着特殊场景下传入构件url与实际存储路径需要进行转换的场景 + * 如构建路径为/archive/file/tmp.data 实际映射路径可能为/archive/file/tmp/tmp.data + */ + private var artifactMappingUri: String? = null + + + /** + * 设置构件实际映射路径 + */ + open fun setArtifactMappingUri(artifactMappingUri: String) { + this.artifactMappingUri = PathUtils.normalizeFullPath(artifactMappingUri) + } + /** * 构件名称,不同依赖源解析规则不一样,可以override * @@ -75,7 +90,11 @@ open class ArtifactInfo( * * 默认使用传入的artifactUri作为名称 */ - open fun getArtifactFullPath(): String = normalizedUri + open fun getArtifactFullPath(): String = if (artifactMappingUri.isNullOrEmpty()) { + normalizedUri + } else { + artifactMappingUri!! + } /** * 构件下载显示名称,不同依赖源解析规则不一样,可以override diff --git a/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/event/listener/ArtifactDownloadListener.kt b/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/event/listener/ArtifactDownloadListener.kt index 7605c67aca..b3ef78f4c8 100644 --- a/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/event/listener/ArtifactDownloadListener.kt +++ b/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/event/listener/ArtifactDownloadListener.kt @@ -115,7 +115,7 @@ class ArtifactDownloadListener( val repoName = event.context.repoName val fullPath = event.context.artifactInfo.getArtifactFullPath() val userId = event.context.userId - val node = ArtifactContextHolder.getNodeDetail() + val node = ArtifactContextHolder.getNodeDetail(event.context.artifactInfo) if (node == null) { val downloadedEvent = NodeDownloadedEvent( projectId = projectId, diff --git a/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/repository/context/ArtifactContextHolder.kt b/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/repository/context/ArtifactContextHolder.kt index b12afd7580..4e057a60bf 100644 --- a/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/repository/context/ArtifactContextHolder.kt +++ b/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/repository/context/ArtifactContextHolder.kt @@ -262,12 +262,11 @@ class ArtifactContextHolder( return otherRepo ?: throw RepoNotFoundException(repoName) } - fun getNodeDetail(projectId: String? = null, repoName: String? = null, fullPath: String? = null): NodeDetail? { + fun getNodeDetail(artifactInfo: ArtifactInfo): NodeDetail? { val request = HttpContextHolder.getRequestOrNull() ?: return null - val artifactInfo = getArtifactInfo(request) ?: return null - val finalProjectId = projectId ?: artifactInfo.projectId - val finalRepoName = repoName ?: artifactInfo.repoName - val finalFullPath = fullPath ?: artifactInfo.getArtifactFullPath() + val finalProjectId = artifactInfo.projectId + val finalRepoName = artifactInfo.repoName + val finalFullPath = artifactInfo.getArtifactFullPath() val attrKey = "$NODE_DETAIL_KEY:$finalProjectId:$finalRepoName$finalFullPath" val nodeDetailAttribute = request.getAttribute(attrKey) diff --git a/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/repository/local/LocalRepository.kt b/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/repository/local/LocalRepository.kt index 2426a49831..c73b60c492 100644 --- a/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/repository/local/LocalRepository.kt +++ b/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/repository/local/LocalRepository.kt @@ -56,7 +56,7 @@ abstract class LocalRepository : AbstractArtifactRepository() { override fun onDownload(context: ArtifactDownloadContext): ArtifactResource? { with(context) { - val node = ArtifactContextHolder.getNodeDetail() + val node = ArtifactContextHolder.getNodeDetail(artifactInfo) node?.let { downloadIntercept(context, it) } val inputStream = storageManager.loadArtifactInputStream(node, storageCredentials) ?: return null val responseName = artifactInfo.getResponseName() diff --git a/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/repository/redirect/CosRedirectService.kt b/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/repository/redirect/CosRedirectService.kt index ace1c0eb9a..ef5f8009dd 100644 --- a/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/repository/redirect/CosRedirectService.kt +++ b/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/repository/redirect/CosRedirectService.kt @@ -75,10 +75,7 @@ class CosRedirectService( return false } - val node = ArtifactContextHolder.getNodeDetail( - context.repositoryDetail.projectId, - context.repositoryDetail.name - ) + val node = ArtifactContextHolder.getNodeDetail(context.artifactInfo) // 从request uri中获取artifact信息,artifact为null时表示非单制品下载请求,此时不支持重定向 val artifact = ArtifactContextHolder.getArtifactInfo() // node为null时表示制品不存在,或者是Remote仓库的制品尚未被缓存,此时不支持重定向 @@ -115,10 +112,7 @@ class CosRedirectService( override fun redirect(context: ArtifactDownloadContext) { val credentials = context.repositoryDetail.storageCredentials ?: storageProperties.defaultStorageCredentials() require(credentials is InnerCosCredentials) - val node = ArtifactContextHolder.getNodeDetail( - projectId = context.repositoryDetail.projectId, - repoName = context.repositoryDetail.name - )!! + val node = ArtifactContextHolder.getNodeDetail(context.artifactInfo)!! // 创建请求并签名 val clientConfig = ClientConfig(credentials).apply { diff --git a/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/repository/redirect/EdgeNodeRedirectService.kt b/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/repository/redirect/EdgeNodeRedirectService.kt index 9d164ead73..ba2f99169f 100644 --- a/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/repository/redirect/EdgeNodeRedirectService.kt +++ b/src/backend/common/common-artifact/artifact-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/repository/redirect/EdgeNodeRedirectService.kt @@ -67,10 +67,7 @@ class EdgeNodeRedirectService( } override fun shouldRedirect(context: ArtifactDownloadContext): Boolean { - val node = ArtifactContextHolder.getNodeDetail( - context.repositoryDetail.projectId, - context.repositoryDetail.name - ) + val node = ArtifactContextHolder.getNodeDetail(context.artifactInfo) val selfClusterName = clusterProperties.self.name if (logger.isDebugEnabled) { logger.debug("node cluster: ${node?.clusterNames.orEmpty().toJsonString()},in cluster $selfClusterName") @@ -102,10 +99,7 @@ class EdgeNodeRedirectService( * 获取边缘节点名称 * */ private fun getEdgeClusterName(context: ArtifactDownloadContext): String? { - val node = ArtifactContextHolder.getNodeDetail( - context.repositoryDetail.projectId, - context.repositoryDetail.name - ) + val node = ArtifactContextHolder.getNodeDetail(context.artifactInfo) return node?.clusterNames?.firstOrNull() } diff --git a/src/backend/composer/biz-composer/src/main/kotlin/com/tencent/bkrepo/composer/artifact/repository/ComposerLocalRepository.kt b/src/backend/composer/biz-composer/src/main/kotlin/com/tencent/bkrepo/composer/artifact/repository/ComposerLocalRepository.kt index 378e0fd1c6..920f0778fe 100644 --- a/src/backend/composer/biz-composer/src/main/kotlin/com/tencent/bkrepo/composer/artifact/repository/ComposerLocalRepository.kt +++ b/src/backend/composer/biz-composer/src/main/kotlin/com/tencent/bkrepo/composer/artifact/repository/ComposerLocalRepository.kt @@ -221,8 +221,8 @@ class ComposerLocalRepository(private val stageClient: StageClient) : LocalRepos override fun onDownload(context: ArtifactDownloadContext): ArtifactResource? { with(context) { - val artifactPath = artifactInfo.getArtifactFullPath().removePrefix("/$DIRECT_DISTS") - val node = ArtifactContextHolder.getNodeDetail(fullPath = artifactPath) + artifactInfo.setArtifactMappingUri(artifactInfo.getArtifactFullPath().removePrefix("/$DIRECT_DISTS")) + val node = ArtifactContextHolder.getNodeDetail(artifactInfo) node?.let { downloadIntercept(context, it) packageVersion(it)?.let { packageVersion -> downloadIntercept(context, packageVersion) } diff --git a/src/backend/generic/biz-generic/src/main/kotlin/com/tencent/bkrepo/generic/artifact/GenericLocalRepository.kt b/src/backend/generic/biz-generic/src/main/kotlin/com/tencent/bkrepo/generic/artifact/GenericLocalRepository.kt index 30fa24e66a..9eeaf5a7bc 100644 --- a/src/backend/generic/biz-generic/src/main/kotlin/com/tencent/bkrepo/generic/artifact/GenericLocalRepository.kt +++ b/src/backend/generic/biz-generic/src/main/kotlin/com/tencent/bkrepo/generic/artifact/GenericLocalRepository.kt @@ -213,11 +213,7 @@ class GenericLocalRepository( private fun downloadSingleNode(context: ArtifactDownloadContext): ArtifactResource? { with(context) { val node = getNodeDetailsFromReq(true)?.firstOrNull() - ?: ArtifactContextHolder.getNodeDetail( - projectId = projectId, - repoName = repoName, - fullPath = artifactInfo.getArtifactFullPath() - ) + ?: ArtifactContextHolder.getNodeDetail(artifactInfo) ?: return null if (node.folder) { return downloadFolder(this, node) diff --git a/src/backend/generic/biz-generic/src/main/kotlin/com/tencent/bkrepo/generic/service/DownloadService.kt b/src/backend/generic/biz-generic/src/main/kotlin/com/tencent/bkrepo/generic/service/DownloadService.kt index 5c7f3a5e61..2eb1ca8e34 100644 --- a/src/backend/generic/biz-generic/src/main/kotlin/com/tencent/bkrepo/generic/service/DownloadService.kt +++ b/src/backend/generic/biz-generic/src/main/kotlin/com/tencent/bkrepo/generic/service/DownloadService.kt @@ -68,7 +68,7 @@ class DownloadService( fun download(artifactInfo: GenericArtifactInfo) { with(artifactInfo) { - val node = ArtifactContextHolder.getNodeDetail() + val node = ArtifactContextHolder.getNodeDetail(this) ?: throw NodeNotFoundException(getArtifactFullPath()) val download = HttpContextHolder.getRequest().getParameter(PARAM_DOWNLOAD)?.toBoolean() ?: false val context = ArtifactDownloadContext() diff --git a/src/backend/helm/biz-helm/src/main/kotlin/com/tencent/bkrepo/helm/artifact/repository/HelmLocalRepository.kt b/src/backend/helm/biz-helm/src/main/kotlin/com/tencent/bkrepo/helm/artifact/repository/HelmLocalRepository.kt index 2a32c73f0a..7b8a6474a4 100644 --- a/src/backend/helm/biz-helm/src/main/kotlin/com/tencent/bkrepo/helm/artifact/repository/HelmLocalRepository.kt +++ b/src/backend/helm/biz-helm/src/main/kotlin/com/tencent/bkrepo/helm/artifact/repository/HelmLocalRepository.kt @@ -173,7 +173,8 @@ class HelmLocalRepository( override fun onDownload(context: ArtifactDownloadContext): ArtifactResource? { val fullPath = context.getStringAttribute(FULL_PATH)!! - val node = ArtifactContextHolder.getNodeDetail(fullPath = fullPath) + context.artifactInfo.setArtifactMappingUri(fullPath) + val node = ArtifactContextHolder.getNodeDetail(context.artifactInfo) node?.let { node.metadata[NAME]?.let { context.putAttribute(NAME, it) } node.metadata[VERSION]?.let { context.putAttribute(VERSION, it) } diff --git a/src/backend/maven/biz-maven/src/main/kotlin/com/tencent/bkrepo/maven/artifact/repository/MavenLocalRepository.kt b/src/backend/maven/biz-maven/src/main/kotlin/com/tencent/bkrepo/maven/artifact/repository/MavenLocalRepository.kt index e14110b2b9..e5b5d32c57 100644 --- a/src/backend/maven/biz-maven/src/main/kotlin/com/tencent/bkrepo/maven/artifact/repository/MavenLocalRepository.kt +++ b/src/backend/maven/biz-maven/src/main/kotlin/com/tencent/bkrepo/maven/artifact/repository/MavenLocalRepository.kt @@ -774,7 +774,8 @@ class MavenLocalRepository( checksumType: HashType? = null ): NodeDetail? { with(context) { - var node = ArtifactContextHolder.getNodeDetail(fullPath = fullPath) + artifactInfo.setArtifactMappingUri(fullPath) + var node = ArtifactContextHolder.getNodeDetail(artifactInfo) if (node != null || checksumType == null) { return node } @@ -784,11 +785,13 @@ class MavenLocalRepository( "in ${artifactInfo.getRepoIdentify()}" ) val temPath = fullPath.removeSuffix(".${checksumType.ext}") - node = ArtifactContextHolder.getNodeDetail(fullPath = temPath) + artifactInfo.setArtifactMappingUri(temPath) + node = ArtifactContextHolder.getNodeDetail(artifactInfo) // 源文件存在,但是对应checksum文件不存在,需要生成 if (node != null) { verifyPath(context, temPath, checksumType) - node = ArtifactContextHolder.getNodeDetail(fullPath = fullPath) + artifactInfo.setArtifactMappingUri(fullPath) + node = ArtifactContextHolder.getNodeDetail(artifactInfo) } return node } diff --git a/src/backend/oci/biz-oci/src/main/kotlin/com/tencent/bkrepo/oci/artifact/repository/OciRegistryLocalRepository.kt b/src/backend/oci/biz-oci/src/main/kotlin/com/tencent/bkrepo/oci/artifact/repository/OciRegistryLocalRepository.kt index 320e05b323..cb8212f64c 100644 --- a/src/backend/oci/biz-oci/src/main/kotlin/com/tencent/bkrepo/oci/artifact/repository/OciRegistryLocalRepository.kt +++ b/src/backend/oci/biz-oci/src/main/kotlin/com/tencent/bkrepo/oci/artifact/repository/OciRegistryLocalRepository.kt @@ -395,10 +395,12 @@ class OciRegistryLocalRepository( } private fun getNodeDetail(artifactInfo: OciArtifactInfo, fullPath: String): NodeDetail? { - return ArtifactContextHolder.getNodeDetail(fullPath = fullPath) ?: run { + artifactInfo.setArtifactMappingUri(fullPath) + return ArtifactContextHolder.getNodeDetail(artifactInfo) ?: run { val oldDockerPath = ociOperationService.getDockerNode(artifactInfo) ?: return null - ArtifactContextHolder.getNodeDetail(fullPath = oldDockerPath) + artifactInfo.setArtifactMappingUri(oldDockerPath) + ArtifactContextHolder.getNodeDetail(artifactInfo) } } diff --git a/src/backend/rpm/biz-rpm/src/main/kotlin/com/tencent/bkrepo/rpm/artifact/repository/RpmLocalRepository.kt b/src/backend/rpm/biz-rpm/src/main/kotlin/com/tencent/bkrepo/rpm/artifact/repository/RpmLocalRepository.kt index 37a05269bd..14ff8d3703 100644 --- a/src/backend/rpm/biz-rpm/src/main/kotlin/com/tencent/bkrepo/rpm/artifact/repository/RpmLocalRepository.kt +++ b/src/backend/rpm/biz-rpm/src/main/kotlin/com/tencent/bkrepo/rpm/artifact/repository/RpmLocalRepository.kt @@ -136,7 +136,7 @@ class RpmLocalRepository( override fun onDownload(context: ArtifactDownloadContext): ArtifactResource? { with(context) { - val node = ArtifactContextHolder.getNodeDetail() + val node = ArtifactContextHolder.getNodeDetail(artifactInfo) node?.let { downloadIntercept(context, it) packageVersion(context, it)?.let { packageVersion -> downloadIntercept(context, packageVersion) } From 685a66ae4bd8e28a4e53a79407d697a2c8b7073a Mon Sep 17 00:00:00 2001 From: zacyanliu Date: Thu, 7 Sep 2023 22:16:33 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=E9=87=8D=E5=86=99=E5=90=84?= =?UTF-8?q?=E7=A7=8D=E7=B1=BB=E5=9E=8B=E4=BB=93=E5=BA=93=E5=AF=B9=E5=BA=94?= =?UTF-8?q?=E7=9A=84getArtifactFullPath=E5=AE=9E=E7=8E=B0=20#1067?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/artifact/api/ArtifactInfo.kt | 2 ++ .../artifact/CompressedBlobArtifactInfo.kt | 6 ++++- .../ddc/artifact/ReferenceArtifactInfo.kt | 6 ++++- .../git/artifact/GitContentArtifactInfo.kt | 4 +++- .../git/artifact/GitPackFileArtifactInfo.kt | 5 ++++- .../pojo/artifact/HelmDeleteArtifactInfo.kt | 5 ++++- .../npm/pojo/artifact/NpmArtifactInfo.kt | 6 ++++- .../pojo/artifact/NugetDeleteArtifactInfo.kt | 6 ++++- .../artifact/NugetDownloadArtifactInfo.kt | 6 ++++- .../pojo/artifact/NugetPublishArtifactInfo.kt | 6 ++++- .../oci/pojo/artifact/OciBlobArtifactInfo.kt | 12 +++++----- .../pojo/artifact/OciManifestArtifactInfo.kt | 14 +++++++----- .../bkrepo/rpm/artifact/RpmArtifactInfo.kt | 22 ++++++++++--------- 13 files changed, 71 insertions(+), 29 deletions(-) diff --git a/src/backend/common/common-artifact/artifact-api/src/main/kotlin/com/tencent/bkrepo/common/artifact/api/ArtifactInfo.kt b/src/backend/common/common-artifact/artifact-api/src/main/kotlin/com/tencent/bkrepo/common/artifact/api/ArtifactInfo.kt index 0f9929effb..5b04cd6592 100644 --- a/src/backend/common/common-artifact/artifact-api/src/main/kotlin/com/tencent/bkrepo/common/artifact/api/ArtifactInfo.kt +++ b/src/backend/common/common-artifact/artifact-api/src/main/kotlin/com/tencent/bkrepo/common/artifact/api/ArtifactInfo.kt @@ -72,6 +72,8 @@ open class ArtifactInfo( this.artifactMappingUri = PathUtils.normalizeFullPath(artifactMappingUri) } + fun getArtifactMappingUri(): String? = artifactMappingUri + /** * 构件名称,不同依赖源解析规则不一样,可以override * diff --git a/src/backend/ddc/biz-ddc/src/main/kotlin/com/tencent/bkrepo/ddc/artifact/CompressedBlobArtifactInfo.kt b/src/backend/ddc/biz-ddc/src/main/kotlin/com/tencent/bkrepo/ddc/artifact/CompressedBlobArtifactInfo.kt index 8eaed8a601..c20c0dce27 100644 --- a/src/backend/ddc/biz-ddc/src/main/kotlin/com/tencent/bkrepo/ddc/artifact/CompressedBlobArtifactInfo.kt +++ b/src/backend/ddc/biz-ddc/src/main/kotlin/com/tencent/bkrepo/ddc/artifact/CompressedBlobArtifactInfo.kt @@ -40,7 +40,11 @@ class CompressedBlobArtifactInfo( override fun getArtifactName() = "/$DIR_BLOBS/$compressedContentId" - override fun getArtifactFullPath() = "/$DIR_BLOBS/$compressedContentId" + override fun getArtifactFullPath() = if(getArtifactMappingUri().isNullOrEmpty()) { + "/$DIR_BLOBS/$compressedContentId" + } else { + getArtifactMappingUri()!! + } companion object { const val PATH_VARIABLE_CONTENT_ID = "id" diff --git a/src/backend/ddc/biz-ddc/src/main/kotlin/com/tencent/bkrepo/ddc/artifact/ReferenceArtifactInfo.kt b/src/backend/ddc/biz-ddc/src/main/kotlin/com/tencent/bkrepo/ddc/artifact/ReferenceArtifactInfo.kt index 66196cf528..7a3b0251d5 100644 --- a/src/backend/ddc/biz-ddc/src/main/kotlin/com/tencent/bkrepo/ddc/artifact/ReferenceArtifactInfo.kt +++ b/src/backend/ddc/biz-ddc/src/main/kotlin/com/tencent/bkrepo/ddc/artifact/ReferenceArtifactInfo.kt @@ -41,7 +41,11 @@ class ReferenceArtifactInfo( override fun getArtifactName() = "/$bucket/$refId" - override fun getArtifactFullPath() = "/$bucket/$refId" + override fun getArtifactFullPath(): String { + return if(getArtifactMappingUri().isNullOrEmpty()) { + "/$bucket/$refId" + } else getArtifactMappingUri()!! + } companion object { const val PATH_VARIABLE_BUCKET = "bucket" diff --git a/src/backend/git/api-git/src/main/kotlin/com/tencent/bkrepo/git/artifact/GitContentArtifactInfo.kt b/src/backend/git/api-git/src/main/kotlin/com/tencent/bkrepo/git/artifact/GitContentArtifactInfo.kt index 78ace97d70..5ba39ecce5 100644 --- a/src/backend/git/api-git/src/main/kotlin/com/tencent/bkrepo/git/artifact/GitContentArtifactInfo.kt +++ b/src/backend/git/api-git/src/main/kotlin/com/tencent/bkrepo/git/artifact/GitContentArtifactInfo.kt @@ -40,6 +40,8 @@ class GitContentArtifactInfo( ) : GitRepositoryArtifactInfo(projectId, repoName, artifactUri) { override fun getArtifactFullPath(): String { - return String.format("objects/%s/%s", commitId, path) + return if(getArtifactMappingUri().isNullOrEmpty()) { + String.format("objects/%s/%s", commitId, path) + } else getArtifactMappingUri()!! } } diff --git a/src/backend/git/api-git/src/main/kotlin/com/tencent/bkrepo/git/artifact/GitPackFileArtifactInfo.kt b/src/backend/git/api-git/src/main/kotlin/com/tencent/bkrepo/git/artifact/GitPackFileArtifactInfo.kt index 7cac5f8787..ad045638d5 100644 --- a/src/backend/git/api-git/src/main/kotlin/com/tencent/bkrepo/git/artifact/GitPackFileArtifactInfo.kt +++ b/src/backend/git/api-git/src/main/kotlin/com/tencent/bkrepo/git/artifact/GitPackFileArtifactInfo.kt @@ -10,7 +10,10 @@ class GitPackFileArtifactInfo( companion object { const val PACKS = "packs" } + override fun getArtifactFullPath(): String { - return "$PACKS/$fileName" + return if(getArtifactMappingUri().isNullOrEmpty()) { + "$PACKS/$fileName" + } else getArtifactMappingUri()!! } } diff --git a/src/backend/helm/biz-helm/src/main/kotlin/com/tencent/bkrepo/helm/pojo/artifact/HelmDeleteArtifactInfo.kt b/src/backend/helm/biz-helm/src/main/kotlin/com/tencent/bkrepo/helm/pojo/artifact/HelmDeleteArtifactInfo.kt index cbfdd381cf..05c03ae7c9 100644 --- a/src/backend/helm/biz-helm/src/main/kotlin/com/tencent/bkrepo/helm/pojo/artifact/HelmDeleteArtifactInfo.kt +++ b/src/backend/helm/biz-helm/src/main/kotlin/com/tencent/bkrepo/helm/pojo/artifact/HelmDeleteArtifactInfo.kt @@ -46,7 +46,10 @@ class HelmDeleteArtifactInfo( private val chartFullPath = HelmUtils.getChartFileFullPath(name, version) - override fun getArtifactFullPath(): String = chartFullPath + override fun getArtifactFullPath(): String { + return if(getArtifactMappingUri().isNullOrEmpty()) chartFullPath + else getArtifactMappingUri()!! + } override fun getArtifactName(): String = name diff --git a/src/backend/npm-registry/biz-npm-registry/src/main/kotlin/com/tencent/bkrepo/npm/pojo/artifact/NpmArtifactInfo.kt b/src/backend/npm-registry/biz-npm-registry/src/main/kotlin/com/tencent/bkrepo/npm/pojo/artifact/NpmArtifactInfo.kt index 5f9cb89561..b749e64a0b 100644 --- a/src/backend/npm-registry/biz-npm-registry/src/main/kotlin/com/tencent/bkrepo/npm/pojo/artifact/NpmArtifactInfo.kt +++ b/src/backend/npm-registry/biz-npm-registry/src/main/kotlin/com/tencent/bkrepo/npm/pojo/artifact/NpmArtifactInfo.kt @@ -54,7 +54,11 @@ open class NpmArtifactInfo( */ private val tarballFullPath: String = NpmUtils.formatTarballPath(packageName, version, delimiter) - override fun getArtifactFullPath() = tarballFullPath + override fun getArtifactFullPath(): String { + return if(getArtifactMappingUri().isNullOrEmpty()) { + tarballFullPath + } else getArtifactMappingUri()!! + } override fun getArtifactVersion() = version diff --git a/src/backend/nuget/biz-nuget/src/main/kotlin/com/tencent/bkrepo/nuget/pojo/artifact/NugetDeleteArtifactInfo.kt b/src/backend/nuget/biz-nuget/src/main/kotlin/com/tencent/bkrepo/nuget/pojo/artifact/NugetDeleteArtifactInfo.kt index 080f55106a..6830e55e73 100644 --- a/src/backend/nuget/biz-nuget/src/main/kotlin/com/tencent/bkrepo/nuget/pojo/artifact/NugetDeleteArtifactInfo.kt +++ b/src/backend/nuget/biz-nuget/src/main/kotlin/com/tencent/bkrepo/nuget/pojo/artifact/NugetDeleteArtifactInfo.kt @@ -13,7 +13,11 @@ class NugetDeleteArtifactInfo( private val nugetFullPath = NugetUtils.getNupkgFullPath(packageName, version) - override fun getArtifactFullPath(): String = nugetFullPath + override fun getArtifactFullPath(): String { + return if(getArtifactMappingUri().isNullOrEmpty()) { + nugetFullPath + } else getArtifactMappingUri()!! + } override fun getArtifactName(): String = packageName diff --git a/src/backend/nuget/biz-nuget/src/main/kotlin/com/tencent/bkrepo/nuget/pojo/artifact/NugetDownloadArtifactInfo.kt b/src/backend/nuget/biz-nuget/src/main/kotlin/com/tencent/bkrepo/nuget/pojo/artifact/NugetDownloadArtifactInfo.kt index 4266fc8954..ef654796d8 100644 --- a/src/backend/nuget/biz-nuget/src/main/kotlin/com/tencent/bkrepo/nuget/pojo/artifact/NugetDownloadArtifactInfo.kt +++ b/src/backend/nuget/biz-nuget/src/main/kotlin/com/tencent/bkrepo/nuget/pojo/artifact/NugetDownloadArtifactInfo.kt @@ -16,7 +16,11 @@ class NugetDownloadArtifactInfo( private val nupkgFullPath = NugetUtils.getNupkgFullPath(packageName, version) private val nuspecFullPath = NugetUtils.getNuspecFullPath(packageName, version) - override fun getArtifactFullPath(): String = if (type == MANIFEST) nuspecFullPath else nupkgFullPath + override fun getArtifactFullPath(): String { + return if(getArtifactMappingUri().isNullOrEmpty()) { + if (type == MANIFEST) nuspecFullPath else nupkgFullPath + } else getArtifactMappingUri()!! + } override fun getArtifactName(): String = packageName diff --git a/src/backend/nuget/biz-nuget/src/main/kotlin/com/tencent/bkrepo/nuget/pojo/artifact/NugetPublishArtifactInfo.kt b/src/backend/nuget/biz-nuget/src/main/kotlin/com/tencent/bkrepo/nuget/pojo/artifact/NugetPublishArtifactInfo.kt index aa4d3901cd..6a6d48ef9a 100644 --- a/src/backend/nuget/biz-nuget/src/main/kotlin/com/tencent/bkrepo/nuget/pojo/artifact/NugetPublishArtifactInfo.kt +++ b/src/backend/nuget/biz-nuget/src/main/kotlin/com/tencent/bkrepo/nuget/pojo/artifact/NugetPublishArtifactInfo.kt @@ -19,5 +19,9 @@ class NugetPublishArtifactInfo( ) : NugetArtifactInfo(projectId, repoName, StringPool.EMPTY) { lateinit var artifactFile: ArtifactFile - override fun getArtifactFullPath(): String = NugetUtils.getNupkgFullPath(packageName, version) + override fun getArtifactFullPath(): String { + return if(getArtifactMappingUri().isNullOrEmpty()) { + NugetUtils.getNupkgFullPath(packageName, version) + } else getArtifactMappingUri()!! + } } diff --git a/src/backend/oci/api-oci/src/main/kotlin/com/tencent/bkrepo/oci/pojo/artifact/OciBlobArtifactInfo.kt b/src/backend/oci/api-oci/src/main/kotlin/com/tencent/bkrepo/oci/pojo/artifact/OciBlobArtifactInfo.kt index 097cd7a3d6..49dfbee901 100644 --- a/src/backend/oci/api-oci/src/main/kotlin/com/tencent/bkrepo/oci/pojo/artifact/OciBlobArtifactInfo.kt +++ b/src/backend/oci/api-oci/src/main/kotlin/com/tencent/bkrepo/oci/pojo/artifact/OciBlobArtifactInfo.kt @@ -67,10 +67,12 @@ class OciBlobArtifactInfo( } override fun getArtifactFullPath(): String { - return if (digest.isNullOrBlank()) { - "" - } else { - OciLocationUtils.buildDigestBlobsPath(packageName, ociDigest) - } + return if(getArtifactMappingUri().isNullOrEmpty()) { + if (digest.isNullOrBlank()) { + "" + } else { + OciLocationUtils.buildDigestBlobsPath(packageName, ociDigest) + } + } else getArtifactMappingUri()!! } } diff --git a/src/backend/oci/api-oci/src/main/kotlin/com/tencent/bkrepo/oci/pojo/artifact/OciManifestArtifactInfo.kt b/src/backend/oci/api-oci/src/main/kotlin/com/tencent/bkrepo/oci/pojo/artifact/OciManifestArtifactInfo.kt index 7075830925..0314c8a54e 100644 --- a/src/backend/oci/api-oci/src/main/kotlin/com/tencent/bkrepo/oci/pojo/artifact/OciManifestArtifactInfo.kt +++ b/src/backend/oci/api-oci/src/main/kotlin/com/tencent/bkrepo/oci/pojo/artifact/OciManifestArtifactInfo.kt @@ -37,11 +37,15 @@ class OciManifestArtifactInfo( val reference: String, val isValidDigest: Boolean ) : OciArtifactInfo(projectId, repoName, packageName, version) { + override fun getArtifactFullPath(): String { - return if (isValidDigest) { - OciLocationUtils.buildDigestManifestPathWithReference(packageName, reference) - } else { - OciLocationUtils.buildManifestPath(packageName, reference) - } + return if(getArtifactMappingUri().isNullOrEmpty()) { + if (isValidDigest) { + OciLocationUtils.buildDigestManifestPathWithReference(packageName, reference) + } else { + OciLocationUtils.buildManifestPath(packageName, reference) + } + } else getArtifactMappingUri()!! + } } diff --git a/src/backend/rpm/api-rpm/src/main/kotlin/com/tencent/bkrepo/rpm/artifact/RpmArtifactInfo.kt b/src/backend/rpm/api-rpm/src/main/kotlin/com/tencent/bkrepo/rpm/artifact/RpmArtifactInfo.kt index 626c72cf43..48b04706b5 100644 --- a/src/backend/rpm/api-rpm/src/main/kotlin/com/tencent/bkrepo/rpm/artifact/RpmArtifactInfo.kt +++ b/src/backend/rpm/api-rpm/src/main/kotlin/com/tencent/bkrepo/rpm/artifact/RpmArtifactInfo.kt @@ -56,17 +56,19 @@ class RpmArtifactInfo( } override fun getArtifactFullPath(): String { - val action = HttpContextHolder.getRequest().method - return if (action.equals("delete", ignoreCase = true)) { - val packageKey = HttpContextHolder.getRequest().getParameter("packageKey") - val version = HttpContextHolder.getRequest().getParameter("version") - if (StringUtils.isBlank(packageKey)) { - super.getArtifactFullPath() + return if(getArtifactMappingUri().isNullOrEmpty()) { + val action = HttpContextHolder.getRequest().method + if (action.equals("delete", ignoreCase = true)) { + val packageKey = HttpContextHolder.getRequest().getParameter("packageKey") + val version = HttpContextHolder.getRequest().getParameter("version") + if (StringUtils.isBlank(packageKey)) { + super.getArtifactFullPath() + } else { + "/${PackageKeys.resolveRpm(packageKey)}-$version.rpm" + } } else { - "/${PackageKeys.resolveRpm(packageKey)}-$version.rpm" + super.getArtifactFullPath() } - } else { - super.getArtifactFullPath() - } + } else getArtifactMappingUri()!! } } From b595627c8a15deb5c71e243eb1d599abb0b6ee87 Mon Sep 17 00:00:00 2001 From: zacyanliu Date: Tue, 10 Oct 2023 16:09:22 +0800 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=E4=BB=A3=E7=A0=81=E8=B0=83?= =?UTF-8?q?=E6=95=B4=20#1067?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bkrepo/repository/service/file/impl/ShareServiceImpl.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/file/impl/ShareServiceImpl.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/file/impl/ShareServiceImpl.kt index 27efcd3ea0..ec659cba08 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/file/impl/ShareServiceImpl.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/file/impl/ShareServiceImpl.kt @@ -152,7 +152,7 @@ class ShareServiceImpl( * 加固签名的apk包,不允许匿名下载 */ private fun checkAlphaApkDownloadUser(userId: String, artifactInfo: ArtifactInfo) { - val nodeDetail = ArtifactContextHolder.getNodeDetail() + val nodeDetail = ArtifactContextHolder.getNodeDetail(artifactInfo) ?: throw NodeNotFoundException(artifactInfo.getArtifactFullPath()) val appStageKey = nodeDetail.metadata.keys.find { it.equals(BK_CI_APP_STAGE_KEY, true) } ?: return