forked from TencentBlueKing/bk-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 支持挂载RemoteGeneric仓库 TencentBlueKing#1462 (TencentBlueKing#1464)
* feat: 支持自定义RemoteGeneric仓库dns解析 TencentBlueKing#1462 * feat: 支持FSServer查询RemoteGeneric仓库 TencentBlueKing#1462 * feat: 支持RemoteGeneric仓库分片下载 TencentBlueKing#1462 * feat: 支持FsServer下载RemoteGeneric制品时重定向 TencentBlueKing#1462 * feat: 修复查询远程仓库节点失败 TencentBlueKing#1462 * feat: 支持RemoteGeneric仓库分片下载 TencentBlueKing#1462 * feat: 支持RemoteGeneric边下载边缓存 TencentBlueKing#1462 * feat: 支持RemoteGeneric仓库分片下载时触发异步缓存任务 TencentBlueKing#1462 * feat: 增加锁避免重复缓存同一远程制品 TencentBlueKing#1462
- Loading branch information
Showing
29 changed files
with
1,334 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...act-service/src/main/kotlin/com/tencent/bkrepo/common/artifact/repository/remote/Utils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. | ||
* | ||
* Copyright (C) 2023 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.bkrepo.common.artifact.repository.remote | ||
|
||
import com.tencent.bkrepo.common.api.constant.HttpHeaders | ||
import com.tencent.bkrepo.common.artifact.pojo.configuration.remote.NetworkProxyConfiguration | ||
import com.tencent.bkrepo.common.artifact.pojo.configuration.remote.RemoteConfiguration | ||
import com.tencent.bkrepo.common.artifact.pojo.configuration.remote.RemoteCredentialsConfiguration | ||
import com.tencent.bkrepo.common.service.util.okhttp.BasicAuthInterceptor | ||
import com.tencent.bkrepo.common.service.util.okhttp.HttpClientBuilderFactory | ||
import okhttp3.Authenticator | ||
import okhttp3.Credentials | ||
import okhttp3.Interceptor | ||
import okhttp3.OkHttpClient | ||
import java.net.InetSocketAddress | ||
import java.net.Proxy | ||
import java.util.concurrent.TimeUnit | ||
|
||
/** | ||
* 创建代理 | ||
*/ | ||
fun createProxy(configuration: NetworkProxyConfiguration?): Proxy { | ||
return configuration?.let { Proxy(Proxy.Type.HTTP, InetSocketAddress(it.host, it.port)) } ?: Proxy.NO_PROXY | ||
} | ||
|
||
/** | ||
* 创建代理身份认证 | ||
*/ | ||
fun createProxyAuthenticator(configuration: NetworkProxyConfiguration?): Authenticator { | ||
val username = configuration?.username | ||
val password = configuration?.password | ||
return if (username != null && password != null) { | ||
Authenticator { _, response -> | ||
response.request | ||
.newBuilder() | ||
.header(HttpHeaders.PROXY_AUTHORIZATION, Credentials.basic(username, password)) | ||
.build() | ||
} | ||
} else Authenticator.NONE | ||
} | ||
|
||
/** | ||
* 创建身份认证拦截器 | ||
*/ | ||
fun createAuthenticateInterceptor(configuration: RemoteCredentialsConfiguration): Interceptor? { | ||
val username = configuration.username | ||
val password = configuration.password | ||
return if (username != null && password != null) { | ||
BasicAuthInterceptor(username, password) | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
fun buildOkHttpClient(configuration: RemoteConfiguration, addInterceptor: Boolean = true): OkHttpClient.Builder { | ||
val builder = HttpClientBuilderFactory.create() | ||
builder.readTimeout(configuration.network.readTimeout, TimeUnit.MILLISECONDS) | ||
builder.connectTimeout(configuration.network.connectTimeout, TimeUnit.MILLISECONDS) | ||
builder.proxy(createProxy(configuration.network.proxy)) | ||
builder.proxyAuthenticator(createProxyAuthenticator(configuration.network.proxy)) | ||
if (addInterceptor) { | ||
createAuthenticateInterceptor(configuration.credentials)?.let { builder.addInterceptor(it) } | ||
} | ||
builder.retryOnConnectionFailure(true) | ||
return builder | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/api/NodeClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. | ||
* | ||
* Copyright (C) 2023 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.bkrepo.fs.server.api | ||
|
||
import com.tencent.bkrepo.common.api.constant.ensureSuffix | ||
import com.tencent.bkrepo.common.artifact.pojo.RepositoryCategory | ||
import com.tencent.bkrepo.common.artifact.pojo.RepositoryType | ||
import com.tencent.bkrepo.common.artifact.pojo.configuration.composite.CompositeConfiguration | ||
import com.tencent.bkrepo.fs.server.context.ReactiveArtifactContextHolder | ||
import com.tencent.bkrepo.fs.server.model.Node | ||
import com.tencent.bkrepo.fs.server.toNode | ||
import com.tencent.bkrepo.repository.pojo.node.NodeDetail | ||
import com.tencent.bkrepo.repository.pojo.node.NodeListOption | ||
import com.tencent.bkrepo.repository.pojo.repo.RepositoryDetail | ||
import com.tencent.bkrepo.repository.pojo.search.NodeQueryBuilder | ||
import kotlinx.coroutines.reactor.awaitSingle | ||
import kotlin.reflect.full.declaredMemberProperties | ||
|
||
class NodeClient( | ||
private val repositoryClient: RRepositoryClient, | ||
private val genericClient: RGenericClient, | ||
) { | ||
|
||
suspend fun getNodeDetail( | ||
projectId: String, | ||
repo: RepositoryDetail, | ||
fullPath: String, | ||
category: String, | ||
): NodeDetail? { | ||
return if (category == RepositoryCategory.LOCAL.name) { | ||
repositoryClient.getNodeDetail( | ||
projectId = projectId, | ||
repoName = repo.name, | ||
fullPath = fullPath | ||
).awaitSingle().data | ||
} else if (repo.type == RepositoryType.GENERIC) { | ||
genericClient.getNodeDetail( | ||
projectId = projectId, | ||
repoName = repo.name, | ||
fullPath = fullPath | ||
).awaitSingle().data | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
|
||
suspend fun listNodes( | ||
projectId: String, | ||
repo: RepositoryDetail, | ||
path: String, | ||
option: NodeListOption | ||
): List<Node>? { | ||
val nodes = if (ReactiveArtifactContextHolder.getRepoDetail().isLocalRepo()) { | ||
repositoryClient.listNodePage( | ||
path = path, | ||
projectId = projectId, | ||
repoName = repo.name, | ||
option = option | ||
).awaitSingle().data?.records?.map { it.toNode() }?.toList() | ||
} else if (repo.type == RepositoryType.GENERIC) { | ||
val builder = NodeQueryBuilder() | ||
.page(option.pageNumber, option.pageSize) | ||
.select(*select) | ||
.projectId(projectId) | ||
.repoName(repo.name) | ||
.path(path.ensureSuffix("/")) | ||
if (!option.includeFolder) { | ||
builder.excludeFolder() | ||
} | ||
return genericClient.search(projectId, repo.name, builder.build()).awaitSingle().data | ||
?.map { (it as Map<String, Any?>).toNode() } | ||
?.toList() | ||
?.filterNotNull() | ||
} else { | ||
null | ||
} | ||
return nodes | ||
} | ||
|
||
private fun RepositoryDetail.isLocalRepo(): Boolean { | ||
val repoConfiguration = configuration | ||
return category == RepositoryCategory.LOCAL || | ||
repoConfiguration is CompositeConfiguration && repoConfiguration.proxy.channelList.isEmpty() | ||
} | ||
|
||
companion object { | ||
private val select = Node::class.declaredMemberProperties.map { it.name }.toTypedArray() | ||
} | ||
} |
Oops, something went wrong.