Skip to content

Commit

Permalink
feat: generic类型制品支持S3协议获取 TencentBlueKing#1296 (TencentBlueKing#1621)
Browse files Browse the repository at this point in the history
* feat: generic类型制品支持S3协议获取 TencentBlueKing#1296

* feat: generic类型制品支持S3协议获取 TencentBlueKing#1296
  • Loading branch information
yaoxuwan authored Jan 5, 2024
1 parent 52b4df3 commit 47e22c1
Show file tree
Hide file tree
Showing 33 changed files with 760 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,10 @@ interface ServiceUserClient {
fun userPwdById(
@PathVariable uid: String
): Response<String?>

@ApiOperation("获取用户token")
@GetMapping("/usertoken/{uid}")
fun userTokenById(
@PathVariable uid: String
): Response<List<String>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,8 @@ class ServiceUserController @Autowired constructor(
override fun userPwdById(uid: String): Response<String?> {
return ResponseBuilder.success(userService.getUserPwdById(uid))
}

override fun userTokenById(uid: String): Response<List<String>> {
return ResponseBuilder.success(userService.listValidToken(uid).map { it.id })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ interface UserService {

fun listUserToken(userId: String): List<TokenResult>

fun listValidToken(userId: String): List<Token>

fun removeToken(userId: String, name: String): Boolean

fun findUserByUserToken(userId: String, pwd: String): User?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,13 @@ class UserServiceImpl constructor(
return UserRequestUtil.convTokenResult(userRepository.findFirstByUserId(userId)!!.tokens)
}

override fun listValidToken(userId: String): List<Token> {
checkUserExist(userId)
return userRepository.findFirstByUserId(userId)!!.tokens.filter {
it.expiredAt == null || it.expiredAt!!.isAfter(LocalDateTime.now())
}
}

override fun removeToken(userId: String, name: String): Boolean {
logger.info("remove token userId : [$userId] ,name : [$name]")
checkUserExist(userId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ class AuthenticationManager(
return serviceUserClient.userPwdById(userId).data
}

/**
* 根据用户id[userId]查询用户token
*/
fun findUserToken(userId: String): List<String>? {
return serviceUserClient.userTokenById(userId).data
}

fun findOauthToken(accessToken: String): OauthToken? {
return serviceOauthAuthorizationClient.getToken(accessToken).data
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ import java.net.URLDecoder

object HeaderUtils {

fun getHeaderNames(): List<String>? {
return request()?.headerNames?.toList()
}

fun getHeader(name: String): String? {
return request()?.getHeader(name)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,13 @@ class ArtifactReplicaController(
}

override fun replicaNodeCopyRequest(request: NodeMoveCopyRequest): Response<Void> {
return nodeClient.copyNode(request)
nodeClient.copyNode(request)
return ResponseBuilder.success()
}

override fun replicaNodeMoveRequest(request: NodeMoveCopyRequest): Response<Void> {
return nodeClient.moveNode(request)
nodeClient.moveNode(request)
return ResponseBuilder.success()
}

override fun replicaNodeDeleteRequest(request: NodeDeleteRequest): Response<NodeDeleteResult> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ interface NodeClient {

@ApiOperation("移动节点")
@PostMapping("/move")
fun moveNode(@RequestBody nodeMoveRequest: NodeMoveCopyRequest): Response<Void>
fun moveNode(@RequestBody nodeMoveRequest: NodeMoveCopyRequest): Response<NodeDetail>

@ApiOperation("复制节点")
@PostMapping("/copy")
fun copyNode(@RequestBody nodeCopyRequest: NodeMoveCopyRequest): Response<Void>
fun copyNode(@RequestBody nodeCopyRequest: NodeMoveCopyRequest): Response<NodeDetail>

@ApiOperation("删除节点")
@DeleteMapping("/delete")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ data class MetadataSaveRequest(
val metadata: Map<String, Any>? = null,
@ApiModelProperty("需要创建或更新的元数据", required = true)
val nodeMetadata: List<MetadataModel>? = null,
@ApiModelProperty("是否替换元数据,删除原有元数据再新增元数据", required = false)
val replace: Boolean = false,
@ApiModelProperty("操作用户")
override val operator: String = SYSTEM_USER
) : NodeRequest, ServiceRequest
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ open class AbstractQueryBuilder<T : AbstractQueryBuilder<T>> {
private var rootRule: Rule.NestedRule = createNestedRule(Rule.NestedRule.RelationType.AND)
private var currentRule: Rule.NestedRule = rootRule

fun newBuilder(): T {
val constructor = javaClass.getDeclaredConstructor()
val newInstance = constructor.newInstance() as T
newInstance.projectId = projectId
newInstance.repoNames = repoNames
newInstance.repoType = repoType
newInstance.fields = fields
newInstance.sort = sort?.let { Sort(it.properties, it.direction) }
newInstance.pageLimit = PageLimit(pageLimit.pageNumber, pageLimit.pageSize)
val newRootRule: MutableList<Rule> = mutableListOf()
newRootRule.addAll(rootRule.rules)
newInstance.rootRule = Rule.NestedRule(newRootRule, rootRule.relation)
newInstance.currentRule = newInstance.rootRule
return newInstance
}

/**
* 设置查询字段[fields]
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,12 @@ class NodeController(
return ResponseBuilder.success()
}

override fun moveNode(nodeMoveRequest: NodeMoveCopyRequest): Response<Void> {
nodeService.moveNode(nodeMoveRequest)
return ResponseBuilder.success()
override fun moveNode(nodeMoveRequest: NodeMoveCopyRequest): Response<NodeDetail> {
return ResponseBuilder.success(nodeService.moveNode(nodeMoveRequest))
}

override fun copyNode(nodeCopyRequest: NodeMoveCopyRequest): Response<Void> {
nodeService.copyNode(nodeCopyRequest)
return ResponseBuilder.success()
override fun copyNode(nodeCopyRequest: NodeMoveCopyRequest): Response<NodeDetail> {
return ResponseBuilder.success(nodeService.copyNode(nodeCopyRequest))
}

override fun deleteNode(nodeDeleteRequest: NodeDeleteRequest): Response<NodeDeleteResult> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ class MetadataServiceImpl(
MetadataUtils.changeSystem(nodeMetadata, repositoryProperties.allowUserAddSystemMetadata)
)
checkIfUpdateSystemMetadata(oldMetadata, newMetadata)
node.metadata = MetadataUtils.merge(oldMetadata, newMetadata)
node.metadata = if (replace) {
newMetadata
} else {
MetadataUtils.merge(oldMetadata, newMetadata)
}

nodeDao.save(node)
publishEvent(buildMetadataSavedEvent(request))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

package com.tencent.bkrepo.repository.service.node

import com.tencent.bkrepo.repository.pojo.node.NodeDetail
import com.tencent.bkrepo.repository.pojo.node.service.NodeMoveCopyRequest

/**
Expand All @@ -47,7 +48,7 @@ interface NodeMoveCopyOperation {
* mv 目录名 目录名 目标目录已存在,将源目录(目录本身及子文件)移动到目标目录;目标目录不存在则改名
* mv 目录名 文件名 出错
*/
fun moveNode(moveRequest: NodeMoveCopyRequest)
fun moveNode(moveRequest: NodeMoveCopyRequest): NodeDetail

/**
* 拷贝文件或者文件夹
Expand All @@ -58,5 +59,5 @@ interface NodeMoveCopyOperation {
* cp 目录名 目录名 目标目录已存在,将源目录(目录本身及子文件)拷贝到目标目录;目标目录不存在则将源目录下文件拷贝到目标目录
* cp 目录名 文件名 出错
*/
fun copyNode(copyRequest: NodeMoveCopyRequest)
fun copyNode(copyRequest: NodeMoveCopyRequest): NodeDetail
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import com.tencent.bkrepo.repository.dao.NodeDao
import com.tencent.bkrepo.repository.dao.RepositoryDao
import com.tencent.bkrepo.repository.model.TNode
import com.tencent.bkrepo.repository.model.TRepository
import com.tencent.bkrepo.repository.pojo.node.NodeDetail
import com.tencent.bkrepo.repository.pojo.node.NodeListOption
import com.tencent.bkrepo.repository.pojo.node.service.NodeMoveCopyRequest
import com.tencent.bkrepo.repository.service.node.NodeMoveCopyOperation
Expand All @@ -71,24 +72,32 @@ open class NodeMoveCopySupport(
private val storageCredentialService: StorageCredentialService = nodeBaseService.storageCredentialService
private val quotaService: QuotaService = nodeBaseService.quotaService

override fun moveNode(moveRequest: NodeMoveCopyRequest) {
moveCopy(moveRequest, true)
override fun moveNode(moveRequest: NodeMoveCopyRequest): NodeDetail {
val dstNode = moveCopy(moveRequest, true)
logger.info("Move node success: [$moveRequest]")
return dstNode
}

override fun copyNode(copyRequest: NodeMoveCopyRequest) {
moveCopy(copyRequest, false)
override fun copyNode(copyRequest: NodeMoveCopyRequest): NodeDetail {
val dstNode = moveCopy(copyRequest, false)
logger.info("Copy node success: [$copyRequest]")
return dstNode
}

/**
* 处理节点操作请求
*/
private fun moveCopy(request: NodeMoveCopyRequest, move: Boolean) {
private fun moveCopy(request: NodeMoveCopyRequest, move: Boolean): NodeDetail {
with(resolveContext(request, move)) {
preCheck(this)
if (canIgnore(this)) {
return
return NodeBaseService.convertToDetail(
nodeBaseService.nodeDao.findNode(
projectId = dstProjectId,
repoName = dstRepoName,
fullPath = dstFullPath
)
)!!
}
if (srcNode.folder) {
moveCopyFolder(this)
Expand All @@ -100,6 +109,13 @@ open class NodeMoveCopySupport(
} else {
publishEvent(NodeEventFactory.buildCopiedEvent(request))
}
return NodeBaseService.convertToDetail(
nodeBaseService.nodeDao.findNode(
projectId = dstProjectId,
repoName = dstRepoName,
fullPath = dstFullPath
)
)!!
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ class NodeServiceImpl(
}

@Transactional(rollbackFor = [Throwable::class])
override fun moveNode(moveRequest: NodeMoveCopyRequest) {
NodeMoveCopySupport(this).moveNode(moveRequest)
override fun moveNode(moveRequest: NodeMoveCopyRequest): NodeDetail {
return NodeMoveCopySupport(this).moveNode(moveRequest)
}

@Transactional(rollbackFor = [Throwable::class])
override fun copyNode(copyRequest: NodeMoveCopyRequest) {
NodeMoveCopySupport(this).copyNode(copyRequest)
override fun copyNode(copyRequest: NodeMoveCopyRequest): NodeDetail {
return NodeMoveCopySupport(this).copyNode(copyRequest)
}

@Transactional(rollbackFor = [Throwable::class])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,11 @@ class CommitEdgeCenterNodeServiceImpl(
return CommitEdgeCenterNodeRestoreSupport(this).restoreNode(restoreContext)
}

override fun copyNode(copyRequest: NodeMoveCopyRequest) {
override fun copyNode(copyRequest: NodeMoveCopyRequest): NodeDetail {
return CommitEdgeCenterNodeMoveCopySupport(this, clusterProperties).copyNode(copyRequest)
}

override fun moveNode(moveRequest: NodeMoveCopyRequest) {
override fun moveNode(moveRequest: NodeMoveCopyRequest): NodeDetail {
return CommitEdgeCenterNodeMoveCopySupport(this, clusterProperties).moveNode(moveRequest)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,15 @@ class EdgeNodeServiceImpl(
}

@Transactional(rollbackFor = [Throwable::class])
override fun moveNode(moveRequest: NodeMoveCopyRequest) {
override fun moveNode(moveRequest: NodeMoveCopyRequest): NodeDetail {
centerNodeClient.moveNode(moveRequest)
NodeMoveCopySupport(this).moveNode(moveRequest)
return NodeMoveCopySupport(this).moveNode(moveRequest)
}

@Transactional(rollbackFor = [Throwable::class])
override fun copyNode(copyRequest: NodeMoveCopyRequest) {
override fun copyNode(copyRequest: NodeMoveCopyRequest): NodeDetail {
centerNodeClient.copyNode(copyRequest)
NodeMoveCopySupport(this).copyNode(copyRequest)
return NodeMoveCopySupport(this).copyNode(copyRequest)
}

@Transactional(rollbackFor = [Throwable::class])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ object S3HttpHeaders {
const val X_AMZ_REQUEST_ID = "X-Amz-Request-Id"
const val X_AMZ_DATE = "X-Amz-Date"
const val X_AMZ_CONTENT_SHA256 = "X-Amz-Content-Sha256"
const val X_AMZ_COPY_SOURCE = "X-Amz-Copy-Source"
const val X_AMZ_METADATA_DIRECTIVE = "X-Amz-Metadata-Directive"
const val X_AMZ_META_PREFIX = "X-Amz-Meta-"
const val X_AMZ_META_MTIME = "X-Amz-Meta-Mtime"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.bkrepo.s3.pojo

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement

@JacksonXmlRootElement(localName = "CopyObjectResult")
data class CopyObjectResult(
@JacksonXmlProperty(localName = "ETag")
val eTag: String,

@JacksonXmlProperty(localName = "LastModified")
val lastModified: String,

@JacksonXmlProperty(localName = "ChecksumCRC32")
val checksumCRC32: String,

@JacksonXmlProperty(localName = "ChecksumCRC32C")
val checksumCRC32C: String,

@JacksonXmlProperty(localName = "ChecksumSHA1")
val checksumSHA1: String,

@JacksonXmlProperty(localName = "ChecksumSHA256")
val checksumSHA256: String
)
Loading

0 comments on commit 47e22c1

Please sign in to comment.