From 59b1c92c02c88f0ebc0852817eb9e10620897266 Mon Sep 17 00:00:00 2001 From: yaoxuwan Date: Wed, 27 Oct 2021 11:09:12 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20=E5=88=B6=E5=93=81=E5=BA=93=E5=8C=BF?= =?UTF-8?q?=E5=90=8D=E8=AE=BF=E9=97=AE=E6=B8=85=E7=90=86=20#5354?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/SampleBuildFileResource.kt | 4 ++ .../api/ServiceArchiveAtomResource.kt | 5 +++ .../api/builds/BuildFileResource.kt | 13 +++++++ .../api/service/ServiceArtifactoryResource.kt | 3 ++ .../api/service/ServiceFileResource.kt | 6 +++ .../resources/SampleBuildFileResourceImpl.kt | 2 + .../ServiceArtifactoryResourceImpl.kt | 15 ++++++-- .../resources/UserFileResourceImpl.kt | 4 +- .../resources/UserPipelineFileResourceImpl.kt | 1 + .../SamplePipelineBuildArtifactoryService.kt | 14 +++++-- .../ServiceArchiveAtomResourceImpl.kt | 4 +- .../resources/BuildFileResourceImpl.kt | 13 ++++--- .../resources/ServiceFileResourceImpl.kt | 4 +- .../artifactory/service/ArchiveFileService.kt | 9 +++-- .../impl/BkRepoArchiveFileServiceImpl.kt | 38 +++++++++++-------- .../impl/DiskArchiveFileServiceImpl.kt | 20 ++++++---- .../service/impl/FileTaskServiceImpl.kt | 2 +- .../atom/impl/MarketAtomServiceImpl.kt | 2 +- 18 files changed, 111 insertions(+), 48 deletions(-) diff --git a/src/backend/ci/core/artifactory/api-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/api/SampleBuildFileResource.kt b/src/backend/ci/core/artifactory/api-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/api/SampleBuildFileResource.kt index 5d47418a9ca..f1b4e30f3e7 100644 --- a/src/backend/ci/core/artifactory/api-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/api/SampleBuildFileResource.kt +++ b/src/backend/ci/core/artifactory/api-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/api/SampleBuildFileResource.kt @@ -29,6 +29,7 @@ package com.tencent.devops.artifactory.api import com.tencent.devops.artifactory.pojo.Count import com.tencent.devops.artifactory.pojo.enums.ArtifactoryType +import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID import com.tencent.devops.common.api.pojo.Result import io.swagger.annotations.Api import io.swagger.annotations.ApiOperation @@ -52,6 +53,9 @@ interface SampleBuildFileResource { @Path("/artifactoryType/{artifactoryType}/acrossProjectCopy") @GET fun acrossProjectCopy( + @ApiParam("用户ID", required = true) + @HeaderParam(AUTH_HEADER_USER_ID) + userId: String, @ApiParam("项目ID", required = true) @HeaderParam("X-DEVOPS-PROJECT-ID") projectId: String, diff --git a/src/backend/ci/core/artifactory/api-artifactory-store/src/main/kotlin/com/tencent/devops/artifactory/api/ServiceArchiveAtomResource.kt b/src/backend/ci/core/artifactory/api-artifactory-store/src/main/kotlin/com/tencent/devops/artifactory/api/ServiceArchiveAtomResource.kt index d3b3665115e..2f68f9df284 100644 --- a/src/backend/ci/core/artifactory/api-artifactory-store/src/main/kotlin/com/tencent/devops/artifactory/api/ServiceArchiveAtomResource.kt +++ b/src/backend/ci/core/artifactory/api-artifactory-store/src/main/kotlin/com/tencent/devops/artifactory/api/ServiceArchiveAtomResource.kt @@ -27,6 +27,7 @@ package com.tencent.devops.artifactory.api +import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID import com.tencent.devops.common.api.pojo.Result import io.swagger.annotations.Api import io.swagger.annotations.ApiOperation @@ -34,6 +35,7 @@ import io.swagger.annotations.ApiParam import javax.ws.rs.Consumes import javax.ws.rs.DELETE import javax.ws.rs.GET +import javax.ws.rs.HeaderParam import javax.ws.rs.Path import javax.ws.rs.Produces import javax.ws.rs.QueryParam @@ -58,6 +60,9 @@ interface ServiceArchiveAtomResource { @DELETE @Path("/atom/file/delete") fun deleteAtomFile( + @ApiParam("用户ID", required = true) + @HeaderParam(AUTH_HEADER_USER_ID) + userId: String, @ApiParam("项目编码", required = true) @QueryParam("projectCode") projectCode: String, diff --git a/src/backend/ci/core/artifactory/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/api/builds/BuildFileResource.kt b/src/backend/ci/core/artifactory/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/api/builds/BuildFileResource.kt index 18808fe1291..bd8d0998562 100644 --- a/src/backend/ci/core/artifactory/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/api/builds/BuildFileResource.kt +++ b/src/backend/ci/core/artifactory/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/api/builds/BuildFileResource.kt @@ -32,6 +32,7 @@ import com.tencent.devops.artifactory.pojo.enums.FileTypeEnum import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_BUILD_ID import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_PIPELINE_ID import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_PROJECT_ID +import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID import com.tencent.devops.common.api.pojo.Result import io.swagger.annotations.Api import io.swagger.annotations.ApiOperation @@ -61,6 +62,9 @@ interface BuildFileResource { @GET @Path("/file/download") fun downloadFile( + @ApiParam("用户ID", required = true) + @HeaderParam(AUTH_HEADER_USER_ID) + userId: String, @ApiParam("文件路径", required = true) @QueryParam("filePath") filePath: String, @@ -73,6 +77,9 @@ interface BuildFileResource { @Path("/file/archive") @Consumes(MediaType.MULTIPART_FORM_DATA) fun archiveFile( + @ApiParam("用户ID", required = true) + @HeaderParam(AUTH_HEADER_USER_ID) + userId: String, @ApiParam("projectCode", required = false) @HeaderParam(AUTH_HEADER_DEVOPS_PROJECT_ID) projectCode: String, @@ -99,6 +106,9 @@ interface BuildFileResource { @GET @Path("/file/archive/download") fun downloadArchiveFile( + @ApiParam("用户ID", required = true) + @HeaderParam(AUTH_HEADER_USER_ID) + userId: String, @ApiParam("projectCode", required = true) @HeaderParam(AUTH_HEADER_DEVOPS_PROJECT_ID) projectCode: String, @@ -122,6 +132,9 @@ interface BuildFileResource { @GET @Path("/pipeline/{pipelineId}/build/{buildId}/file/download/urls/get") fun getFileDownloadUrls( + @ApiParam("用户ID", required = true) + @HeaderParam(AUTH_HEADER_USER_ID) + userId: String, @ApiParam("projectCode", required = true) @HeaderParam(AUTH_HEADER_DEVOPS_PROJECT_ID) projectCode: String, diff --git a/src/backend/ci/core/artifactory/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/api/service/ServiceArtifactoryResource.kt b/src/backend/ci/core/artifactory/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/api/service/ServiceArtifactoryResource.kt index b92857cb5bc..78b9018db22 100644 --- a/src/backend/ci/core/artifactory/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/api/service/ServiceArtifactoryResource.kt +++ b/src/backend/ci/core/artifactory/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/api/service/ServiceArtifactoryResource.kt @@ -85,6 +85,9 @@ interface ServiceArtifactoryResource { @Path("/{projectId}/{artifactoryType}/check") @GET fun check( + @ApiParam("用户ID", required = true) + @HeaderParam(AUTH_HEADER_USER_ID) + userId: String, @ApiParam("项目ID", required = true) @PathParam("projectId") projectId: String, diff --git a/src/backend/ci/core/artifactory/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/api/service/ServiceFileResource.kt b/src/backend/ci/core/artifactory/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/api/service/ServiceFileResource.kt index bc54bed8f88..f47f36a1450 100644 --- a/src/backend/ci/core/artifactory/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/api/service/ServiceFileResource.kt +++ b/src/backend/ci/core/artifactory/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/api/service/ServiceFileResource.kt @@ -28,16 +28,19 @@ package com.tencent.devops.artifactory.api.service import com.tencent.devops.artifactory.pojo.enums.FileChannelTypeEnum +import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID import com.tencent.devops.common.api.pojo.Result import io.swagger.annotations.Api import io.swagger.annotations.ApiOperation import io.swagger.annotations.ApiParam +import org.apache.http.auth.AUTH import org.glassfish.jersey.media.multipart.FormDataContentDisposition import org.glassfish.jersey.media.multipart.FormDataParam import java.io.InputStream import javax.servlet.http.HttpServletResponse import javax.ws.rs.Consumes import javax.ws.rs.GET +import javax.ws.rs.HeaderParam import javax.ws.rs.POST import javax.ws.rs.Path import javax.ws.rs.Produces @@ -80,6 +83,9 @@ interface ServiceFileResource { @GET @Path("/file/download") fun downloadFile( + @ApiParam("用户ID", required = true) + @HeaderParam(AUTH_HEADER_USER_ID) + userId: String, @ApiParam("文件路径", required = true) @QueryParam("filePath") filePath: String, diff --git a/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/resources/SampleBuildFileResourceImpl.kt b/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/resources/SampleBuildFileResourceImpl.kt index 35ba8f8a6bf..8ccf4b2d394 100644 --- a/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/resources/SampleBuildFileResourceImpl.kt +++ b/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/resources/SampleBuildFileResourceImpl.kt @@ -40,6 +40,7 @@ class SampleBuildFileResourceImpl @Autowired constructor(private val archiveFile SampleBuildFileResource { override fun acrossProjectCopy( + userId: String, projectId: String, artifactoryType: ArtifactoryType, path: String, @@ -47,6 +48,7 @@ class SampleBuildFileResourceImpl @Autowired constructor(private val archiveFile targetPath: String ): Result { val count = archiveFileService.acrossProjectCopy( + userId = userId, projectId = projectId, artifactoryType = artifactoryType, path = path, diff --git a/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/resources/ServiceArtifactoryResourceImpl.kt b/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/resources/ServiceArtifactoryResourceImpl.kt index d1eccfacd05..7fe39ebc534 100644 --- a/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/resources/ServiceArtifactoryResourceImpl.kt +++ b/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/resources/ServiceArtifactoryResourceImpl.kt @@ -52,9 +52,13 @@ class ServiceArtifactoryResourceImpl @Autowired constructor( private val archiveFileService: ArchiveFileService ) : ServiceArtifactoryResource { - override fun check(projectId: String, artifactoryType: ArtifactoryType, path: String): Result { - val fileDetail = - archiveFileService.show(userId = "", projectId = projectId, artifactoryType = artifactoryType, path = path) + override fun check( + userId: String, + projectId: String, + artifactoryType: ArtifactoryType, + path: String + ): Result { + val fileDetail = archiveFileService.show(userId, projectId, artifactoryType, path) return Result(fileDetail.name.isNotBlank()) } @@ -90,7 +94,10 @@ class ServiceArtifactoryResourceImpl @Autowired constructor( path: String ): Result { val urls = archiveFileService.getFileDownloadUrls( - fileChannelType = FileChannelTypeEnum.WEB_DOWNLOAD, filePath = path, artifactoryType = artifactoryType + userId = userId, + fileChannelType = FileChannelTypeEnum.WEB_DOWNLOAD, + filePath = path, + artifactoryType = artifactoryType ) return Result(Url(urls.fileUrlList[0], urls.fileUrlList[0])) } diff --git a/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/resources/UserFileResourceImpl.kt b/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/resources/UserFileResourceImpl.kt index 0ba77d67a01..a396ca431f0 100644 --- a/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/resources/UserFileResourceImpl.kt +++ b/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/resources/UserFileResourceImpl.kt @@ -85,7 +85,7 @@ class UserFileResourceImpl @Autowired constructor( if (!validateResult) { throw PermissionForbiddenException("no permission") } - return archiveFileService.downloadFileToLocal(filePath, response) + return archiveFileService.downloadFileToLocal(userId, filePath, response) } override fun downloadFile(userId: String, filePath: String, response: HttpServletResponse) { @@ -93,7 +93,7 @@ class UserFileResourceImpl @Autowired constructor( if (!validateResult) { throw PermissionForbiddenException("no permission") } - archiveFileService.downloadFile(filePath, response) + archiveFileService.downloadFile(userId, filePath, response) } override fun downloadFileExt(userId: String, filePath: String, response: HttpServletResponse) { diff --git a/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/resources/UserPipelineFileResourceImpl.kt b/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/resources/UserPipelineFileResourceImpl.kt index 1cbe313fbc9..5060869bba6 100644 --- a/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/resources/UserPipelineFileResourceImpl.kt +++ b/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/resources/UserPipelineFileResourceImpl.kt @@ -74,6 +74,7 @@ class UserPipelineFileResourceImpl @Autowired constructor( path: String ): Result { val urls = archiveFileService.getFileDownloadUrls( + userId = userId, fileChannelType = FileChannelTypeEnum.WEB_DOWNLOAD, filePath = path, artifactoryType = artifactoryType, diff --git a/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/service/SamplePipelineBuildArtifactoryService.kt b/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/service/SamplePipelineBuildArtifactoryService.kt index fdc7d9f19b2..1cc786d56c8 100644 --- a/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/service/SamplePipelineBuildArtifactoryService.kt +++ b/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/service/SamplePipelineBuildArtifactoryService.kt @@ -54,16 +54,22 @@ class SamplePipelineBuildArtifactoryService @Autowired constructor( buildId: String ): List { return if (defaultBkRepoClient.useBkRepo()) { - getBkRepoArtifactoryList(projectId, pipelineId, buildId) + getBkRepoArtifactoryList(userId, projectId, pipelineId, buildId) } else { getLocalArtifactList(projectId, pipelineId, buildId) } } - private fun getBkRepoArtifactoryList(projectId: String, pipelineId: String, buildId: String): List { - logger.info("getBkRepoArtifactoryList, projectId: $projectId, pipelineId: $pipelineId, buildId: $buildId") + private fun getBkRepoArtifactoryList( + userId: String, + projectId: String, + pipelineId: String, + buildId: String + ): List { + logger.info("getBkRepoArtifactoryList, userId: $userId, projectId: $projectId, pipelineId: $pipelineId, " + + "buildId: $buildId") val nodeList = defaultBkRepoClient.queryByNameAndMetadata( - userId = BkRepoUtils.BKREPO_DEFAULT_USER, + userId = userId, projectId = projectId, repoNames = listOf(BkRepoUtils.REPO_NAME_PIPELINE, BkRepoUtils.REPO_NAME_CUSTOM), fileNames = listOf(), diff --git a/src/backend/ci/core/artifactory/biz-artifactory-store/src/main/kotlin/com/tencent/devops/artifactory/resources/ServiceArchiveAtomResourceImpl.kt b/src/backend/ci/core/artifactory/biz-artifactory-store/src/main/kotlin/com/tencent/devops/artifactory/resources/ServiceArchiveAtomResourceImpl.kt index 411667ae1fd..382417baedf 100644 --- a/src/backend/ci/core/artifactory/biz-artifactory-store/src/main/kotlin/com/tencent/devops/artifactory/resources/ServiceArchiveAtomResourceImpl.kt +++ b/src/backend/ci/core/artifactory/biz-artifactory-store/src/main/kotlin/com/tencent/devops/artifactory/resources/ServiceArchiveAtomResourceImpl.kt @@ -45,8 +45,8 @@ class ServiceArchiveAtomResourceImpl @Autowired constructor( return Result(archiveAtomService.getAtomFileContent(filePath)) } - override fun deleteAtomFile(projectCode: String, atomCode: String): Result { - archiveFileService.deleteFile("$BK_CI_ATOM_DIR/$projectCode/$atomCode") + override fun deleteAtomFile(userId: String, projectCode: String, atomCode: String): Result { + archiveFileService.deleteFile(userId, "$BK_CI_ATOM_DIR/$projectCode/$atomCode") return Result(true) } } diff --git a/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/resources/BuildFileResourceImpl.kt b/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/resources/BuildFileResourceImpl.kt index 73d52783366..098cb6e139c 100644 --- a/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/resources/BuildFileResourceImpl.kt +++ b/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/resources/BuildFileResourceImpl.kt @@ -44,11 +44,12 @@ class BuildFileResourceImpl @Autowired constructor( private val archiveFileService: ArchiveFileService ) : BuildFileResource { - override fun downloadFile(filePath: String, response: HttpServletResponse) { - archiveFileService.downloadFile(filePath, response) + override fun downloadFile(userId: String, filePath: String, response: HttpServletResponse) { + archiveFileService.downloadFile(userId, filePath, response) } override fun archiveFile( + userId: String, projectCode: String, pipelineId: String, buildId: String, @@ -58,7 +59,7 @@ class BuildFileResourceImpl @Autowired constructor( disposition: FormDataContentDisposition ): Result { val url = archiveFileService.archiveFile( - userId = "", + userId = userId, projectId = projectCode, pipelineId = pipelineId, buildId = buildId, @@ -72,6 +73,7 @@ class BuildFileResourceImpl @Autowired constructor( } override fun downloadArchiveFile( + userId: String, projectCode: String, pipelineId: String, buildId: String, @@ -80,7 +82,7 @@ class BuildFileResourceImpl @Autowired constructor( response: HttpServletResponse ) { return archiveFileService.downloadArchiveFile( - userId = "", + userId = userId, projectId = projectCode, pipelineId = pipelineId, buildId = buildId, @@ -91,6 +93,7 @@ class BuildFileResourceImpl @Autowired constructor( } override fun getFileDownloadUrls( + userId: String, projectCode: String, pipelineId: String, buildId: String, @@ -98,7 +101,7 @@ class BuildFileResourceImpl @Autowired constructor( customFilePath: String? ): Result { val urls = archiveFileService.getFileDownloadUrls( - userId = "", + userId = userId, projectId = projectCode, pipelineId = pipelineId, buildId = buildId, diff --git a/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/resources/ServiceFileResourceImpl.kt b/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/resources/ServiceFileResourceImpl.kt index b1eb0b7a7b0..a5e9144aa49 100644 --- a/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/resources/ServiceFileResourceImpl.kt +++ b/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/resources/ServiceFileResourceImpl.kt @@ -58,7 +58,7 @@ class ServiceFileResourceImpl @Autowired constructor(private val archiveFileServ return Result(url) } - override fun downloadFile(filePath: String, response: HttpServletResponse) { - archiveFileService.downloadFileToLocal(filePath, response) + override fun downloadFile(userId: String, filePath: String, response: HttpServletResponse) { + archiveFileService.downloadFileToLocal(userId, filePath, response) } } diff --git a/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/service/ArchiveFileService.kt b/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/service/ArchiveFileService.kt index a027d19937a..5655032a7ad 100644 --- a/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/service/ArchiveFileService.kt +++ b/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/service/ArchiveFileService.kt @@ -95,17 +95,17 @@ interface ArchiveFileService { /** * 下载文件至输出流 */ - fun downloadFile(filePath: String, outputStream: OutputStream) + fun downloadFile(userId: String, filePath: String, outputStream: OutputStream) /** * 下载文件 */ - fun downloadFile(filePath: String, response: HttpServletResponse) + fun downloadFile(userId: String, filePath: String, response: HttpServletResponse) /** * 下载文件到本地 */ - fun downloadFileToLocal(filePath: String, response: HttpServletResponse) + fun downloadFileToLocal(userId: String, filePath: String, response: HttpServletResponse) /** * 下载报告文件 @@ -151,6 +151,7 @@ interface ArchiveFileService { * [fullUrl]表示是否返回包含域名的全url地址 */ fun getFileDownloadUrls( + userId: String, filePath: String, artifactoryType: ArtifactoryType, fileChannelType: FileChannelTypeEnum, @@ -207,6 +208,7 @@ interface ArchiveFileService { * 跨项目拷贝文件 */ fun acrossProjectCopy( + userId: String, projectId: String, artifactoryType: ArtifactoryType, path: String, @@ -218,6 +220,7 @@ interface ArchiveFileService { * 删除文件 */ fun deleteFile( + userId: String, filePath: String ) } diff --git a/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/service/impl/BkRepoArchiveFileServiceImpl.kt b/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/service/impl/BkRepoArchiveFileServiceImpl.kt index a11172f7407..2536bba394c 100644 --- a/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/service/impl/BkRepoArchiveFileServiceImpl.kt +++ b/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/service/impl/BkRepoArchiveFileServiceImpl.kt @@ -100,7 +100,7 @@ class BkRepoArchiveFileServiceImpl @Autowired constructor( projectId!! } val repoName = BkRepoUtils.getRepoName(fileType) - defaultBkRepoClient.uploadLocalFile(BKREPO_DEFAULT_USER, repoProjectId, repoName, destPath, file, metadata) + defaultBkRepoClient.uploadLocalFile(userId, repoProjectId, repoName, destPath, file, metadata) return generateFileDownloadUrl(fileChannelType, "$repoProjectId/$repoName/$destPath") } @@ -120,26 +120,26 @@ class BkRepoArchiveFileServiceImpl @Autowired constructor( pipelineId = pipelineId, buildId = buildId ) - downloadFileToLocal("$projectId/${BkRepoUtils.getRepoName(fileType)}/$destPath", response) + downloadFileToLocal(userId, "$projectId/${BkRepoUtils.getRepoName(fileType)}/$destPath", response) } - override fun downloadFile(filePath: String, outputStream: OutputStream) { + override fun downloadFile(userId: String, filePath: String, outputStream: OutputStream) { logger.info("downloadFile, filePath: $filePath") if (filePath.contains("..")) { throw ErrorCodeException(errorCode = CommonMessageCode.PARAMETER_IS_INVALID, params = arrayOf("filePath")) } val artifactInfo = BkRepoUtils.parseArtifactoryInfo(filePath) with(artifactInfo) { - defaultBkRepoClient.downloadFile(BKREPO_DEFAULT_USER, projectId, repoName, artifactUri, outputStream) + defaultBkRepoClient.downloadFile(userId, projectId, repoName, artifactUri, outputStream) } } - override fun downloadFile(filePath: String, response: HttpServletResponse) { + override fun downloadFile(userId: String, filePath: String, response: HttpServletResponse) { response.contentType = MimeUtil.mediaType(filePath) - return downloadFile(filePath, response.outputStream) + return downloadFile(userId, filePath, response.outputStream) } - override fun downloadFileToLocal(filePath: String, response: HttpServletResponse) { + override fun downloadFileToLocal(userId: String, filePath: String, response: HttpServletResponse) { logger.info("downloadFile, filePath: $filePath") val artifactInfo = BkRepoUtils.parseArtifactoryInfo(filePath) val fileName = URLEncoder.encode(artifactInfo.fileName, "UTF-8") @@ -148,11 +148,13 @@ class BkRepoArchiveFileServiceImpl @Autowired constructor( response.setHeader("Content-disposition", "attachment;filename=$fileName") response.setHeader("Cache-Control", "no-cache") with(artifactInfo) { - defaultBkRepoClient.downloadFile(userId = BKREPO_DEFAULT_USER, + defaultBkRepoClient.downloadFile( + userId = userId, projectId = projectId, repoName = repoName, fullPath = artifactUri, - outputStream = response.outputStream) + outputStream = response.outputStream + ) } } @@ -166,7 +168,7 @@ class BkRepoArchiveFileServiceImpl @Autowired constructor( ) { val filePath = "/$projectId/$REPO_NAME_REPORT/$pipelineId/$buildId/$elementId/$path" val response = (RequestContextHolder.getRequestAttributes() as ServletRequestAttributes).response!! - downloadFile(filePath, response) + downloadFile(userId, filePath, response) } override fun searchFileList( @@ -245,18 +247,21 @@ class BkRepoArchiveFileServiceImpl @Autowired constructor( pipelineId = pipelineId, buildId = buildId ) - return getFileDownloadUrls(filePath = "$projectId/${BkRepoUtils.getRepoName(artifactoryType)}/$filePath", + return getFileDownloadUrls( + userId = userId, + filePath = "$projectId/${BkRepoUtils.getRepoName(artifactoryType)}/$filePath", artifactoryType = artifactoryType, fileChannelType = fileChannelType, fullUrl = fullUrl) } override fun getFileDownloadUrls( + userId: String, filePath: String, artifactoryType: ArtifactoryType, fileChannelType: FileChannelTypeEnum, fullUrl: Boolean ): GetFileDownloadUrlsResponse { - logger.info("getFileDownloadUrls, filePath: $filePath, artifactoryType, $artifactoryType, " + + logger.info("getFileDownloadUrls, userId: $userId, filePath: $filePath, artifactoryType, $artifactoryType, " + "fileChannelType, $fileChannelType") if (filePath.contains("..")) { logger.warn("getFileDownloadUrls, path contains '..'") @@ -266,7 +271,7 @@ class BkRepoArchiveFileServiceImpl @Autowired constructor( logger.debug("getFileDownloadUrls, artifactoryInfo, $artifactoryInfo") val repoName = BkRepoUtils.getRepoName(artifactoryType) val fileUrls = defaultBkRepoClient.queryByPathNamePairOrMetadataEqAnd( - userId = BKREPO_DEFAULT_USER, + userId = userId, projectId = artifactoryInfo.projectId, repoNames = listOf(repoName), pathNamePairs = listOf(BkRepoUtils.parsePathNamePair(artifactoryInfo.artifactUri)), @@ -283,6 +288,7 @@ class BkRepoArchiveFileServiceImpl @Autowired constructor( } override fun acrossProjectCopy( + userId: String, projectId: String, artifactoryType: ArtifactoryType, path: String, @@ -291,7 +297,7 @@ class BkRepoArchiveFileServiceImpl @Autowired constructor( ): Count { val repoName = BkRepoUtils.getRepoName(artifactoryType) val fileNodes = defaultBkRepoClient.queryByPathNamePairOrMetadataEqAnd( - userId = BKREPO_DEFAULT_USER, + userId = userId, projectId = projectId, repoNames = listOf(repoName), pathNamePairs = listOf(BkRepoUtils.parsePathNamePair(path)), @@ -301,7 +307,7 @@ class BkRepoArchiveFileServiceImpl @Autowired constructor( fileNodes.forEach { defaultBkRepoClient.copy( - userId = BKREPO_DEFAULT_USER, + userId = userId, fromProject = projectId, fromRepo = repoName, fromPath = it.fullPath, @@ -362,7 +368,7 @@ class BkRepoArchiveFileServiceImpl @Autowired constructor( return flag } - override fun deleteFile(filePath: String) { + override fun deleteFile(userId: String, filePath: String) { logger.info("deleteFile, filePath: $filePath") val artifactInfo = BkRepoUtils.parseArtifactoryInfo(filePath) with(artifactInfo) { diff --git a/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/service/impl/DiskArchiveFileServiceImpl.kt b/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/service/impl/DiskArchiveFileServiceImpl.kt index 9c61667c752..9142822b7e9 100644 --- a/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/service/impl/DiskArchiveFileServiceImpl.kt +++ b/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/service/impl/DiskArchiveFileServiceImpl.kt @@ -131,10 +131,11 @@ class DiskArchiveFileServiceImpl : ArchiveFileServiceImpl() { buildId = buildId ) val destPath = path.substring(getBasePath().length) - downloadFileToLocal(destPath, response) + downloadFileToLocal(userId, destPath, response) } override fun acrossProjectCopy( + userId: String, projectId: String, artifactoryType: ArtifactoryType, path: String, @@ -144,6 +145,7 @@ class DiskArchiveFileServiceImpl : ArchiveFileServiceImpl() { val sourcePathPattern = getSourcePath(projectId, artifactoryType, path) val sourceParentPath = sourcePathPattern.substring(0, sourcePathPattern.lastIndexOf(fileSeparator)) return doAcrossProjectCopy( + userId = userId, sourceParentPath = sourceParentPath, sourcePathPattern = sourcePathPattern, destPath = targetPath, @@ -196,7 +198,7 @@ class DiskArchiveFileServiceImpl : ArchiveFileServiceImpl() { ) ?: "" } - override fun downloadFile(filePath: String, outputStream: OutputStream) { + override fun downloadFile(userId: String, filePath: String, outputStream: OutputStream) { logger.info("downloadFile, filePath: $filePath") if (filePath.contains("..")) { throw ErrorCodeException(errorCode = CommonMessageCode.PARAMETER_IS_INVALID, params = arrayOf("filePath")) @@ -296,7 +298,7 @@ class DiskArchiveFileServiceImpl : ArchiveFileServiceImpl() { return destPath } - override fun downloadFile(filePath: String, response: HttpServletResponse) { + override fun downloadFile(userId: String, filePath: String, response: HttpServletResponse) { logger.info("downloadFile, filePath: $filePath") if (filePath.contains("..")) { throw ErrorCodeException(errorCode = CommonMessageCode.PARAMETER_IS_INVALID, params = arrayOf(filePath)) @@ -306,7 +308,7 @@ class DiskArchiveFileServiceImpl : ArchiveFileServiceImpl() { FileCopyUtils.copy(FileInputStream(file), response.outputStream) } - override fun downloadFileToLocal(filePath: String, response: HttpServletResponse) { + override fun downloadFileToLocal(userId: String, filePath: String, response: HttpServletResponse) { logger.info("downloadFileToLocal, filePath: $filePath") val file = File("${getBasePath()}$fileSeparator${URLDecoder.decode(filePath, "UTF-8")}") // 如果文件不存在,提示404 @@ -332,7 +334,7 @@ class DiskArchiveFileServiceImpl : ArchiveFileServiceImpl() { ) { val filePath = "${FileTypeEnum.BK_REPORT.fileType}/$projectId/$pipelineId/$buildId/$elementId/$path" val response = (RequestContextHolder.getRequestAttributes() as ServletRequestAttributes).response!! - downloadFile(filePath, response) + downloadFile(userId, filePath, response) } fun getBasePath(): String { @@ -415,10 +417,11 @@ class DiskArchiveFileServiceImpl : ArchiveFileServiceImpl() { pipelineId = pipelineId, buildId = buildId ) - return getFileDownloadUrls(filePath, artifactoryType, fileChannelType, fullUrl = fullUrl) + return getFileDownloadUrls(userId, filePath, artifactoryType, fileChannelType, fullUrl = fullUrl) } override fun getFileDownloadUrls( + userId: String, filePath: String, artifactoryType: ArtifactoryType, fileChannelType: FileChannelTypeEnum, @@ -521,6 +524,7 @@ class DiskArchiveFileServiceImpl : ArchiveFileServiceImpl() { } private fun doAcrossProjectCopy( + userId: String, sourceParentPath: String, sourcePathPattern: String, destPath: String, @@ -548,7 +552,7 @@ class DiskArchiveFileServiceImpl : ArchiveFileServiceImpl() { } fileList.forEach { uploadFile( - userId = "", + userId = userId, file = it, projectId = targetProjectId, filePath = "$destPath$fileSeparator${it.name}", @@ -597,7 +601,7 @@ class DiskArchiveFileServiceImpl : ArchiveFileServiceImpl() { return flag } - override fun deleteFile(filePath: String) { + override fun deleteFile(userId: String, filePath: String) { FileSystemUtils.deleteRecursively(File("$archiveLocalBasePath/$filePath")) } diff --git a/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/service/impl/FileTaskServiceImpl.kt b/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/service/impl/FileTaskServiceImpl.kt index a5780db714d..921ffdc6f8e 100644 --- a/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/service/impl/FileTaskServiceImpl.kt +++ b/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/service/impl/FileTaskServiceImpl.kt @@ -150,7 +150,7 @@ class FileTaskServiceImpl : FileTaskService { // 下载文件到本地临时目录 fileTaskDao.updateFileTaskStatus(dslContext, taskId, FileTaskStatusEnum.DOWNLOADING.status) try { - archiveFileService.downloadFile(destPath, FileOutputStream(tmpFile)) + archiveFileService.downloadFile(userId, destPath, FileOutputStream(tmpFile)) fileTaskDao.updateFileTaskStatus(dslContext, taskId, FileTaskStatusEnum.DONE.status) } catch (e: Exception) { logger.error("fail to download file:taskId=$taskId", e) diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/atom/impl/MarketAtomServiceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/atom/impl/MarketAtomServiceImpl.kt index ed3f2f101c0..67eca3376ac 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/atom/impl/MarketAtomServiceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/atom/impl/MarketAtomServiceImpl.kt @@ -857,7 +857,7 @@ abstract class MarketAtomServiceImpl @Autowired constructor() : MarketAtomServic val initProjectCode = storeProjectRelDao.getInitProjectCodeByStoreCode(dslContext, atomCode, StoreTypeEnum.ATOM.type.toByte()) val deleteAtomFileResult = - client.get(ServiceArchiveAtomResource::class).deleteAtomFile(initProjectCode!!, atomCode) + client.get(ServiceArchiveAtomResource::class).deleteAtomFile(userId, initProjectCode!!, atomCode) if (deleteAtomFileResult.isNotOk()) { return deleteAtomFileResult } From c32f9a6f9fdf2175a7f4a502f29e560bb6e5256f Mon Sep 17 00:00:00 2001 From: yaoxuwan Date: Wed, 27 Oct 2021 15:48:06 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=E5=88=B6=E5=93=81=E5=BA=93=E5=8C=BF?= =?UTF-8?q?=E5=90=8D=E8=AE=BF=E9=97=AE=E6=B8=85=E7=90=86=20#5354?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/artifactory/api/service/ServiceFileResource.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/backend/ci/core/artifactory/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/api/service/ServiceFileResource.kt b/src/backend/ci/core/artifactory/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/api/service/ServiceFileResource.kt index f47f36a1450..8ceee0edd3e 100644 --- a/src/backend/ci/core/artifactory/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/api/service/ServiceFileResource.kt +++ b/src/backend/ci/core/artifactory/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/api/service/ServiceFileResource.kt @@ -33,7 +33,6 @@ import com.tencent.devops.common.api.pojo.Result import io.swagger.annotations.Api import io.swagger.annotations.ApiOperation import io.swagger.annotations.ApiParam -import org.apache.http.auth.AUTH import org.glassfish.jersey.media.multipart.FormDataContentDisposition import org.glassfish.jersey.media.multipart.FormDataParam import java.io.InputStream From 0d3c9e435ce87d7bef6309cdeb26284a0c7a7c62 Mon Sep 17 00:00:00 2001 From: yaoxuwan Date: Thu, 28 Oct 2021 10:10:20 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=E5=88=B6=E5=93=81=E5=BA=93=E5=8C=BF?= =?UTF-8?q?=E5=90=8D=E8=AE=BF=E9=97=AE=E6=B8=85=E7=90=86=20#5354?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/SampleBuildFileResource.kt | 8 +++---- .../api/builds/BuildFileResource.kt | 19 +++++---------- .../resources/SampleBuildFileResourceImpl.kt | 11 +++++++-- .../resources/BuildFileResourceImpl.kt | 24 +++++++++++++++---- 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/src/backend/ci/core/artifactory/api-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/api/SampleBuildFileResource.kt b/src/backend/ci/core/artifactory/api-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/api/SampleBuildFileResource.kt index f1b4e30f3e7..70ece87a12a 100644 --- a/src/backend/ci/core/artifactory/api-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/api/SampleBuildFileResource.kt +++ b/src/backend/ci/core/artifactory/api-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/api/SampleBuildFileResource.kt @@ -29,7 +29,7 @@ package com.tencent.devops.artifactory.api import com.tencent.devops.artifactory.pojo.Count import com.tencent.devops.artifactory.pojo.enums.ArtifactoryType -import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID +import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_PIPELINE_ID import com.tencent.devops.common.api.pojo.Result import io.swagger.annotations.Api import io.swagger.annotations.ApiOperation @@ -53,12 +53,12 @@ interface SampleBuildFileResource { @Path("/artifactoryType/{artifactoryType}/acrossProjectCopy") @GET fun acrossProjectCopy( - @ApiParam("用户ID", required = true) - @HeaderParam(AUTH_HEADER_USER_ID) - userId: String, @ApiParam("项目ID", required = true) @HeaderParam("X-DEVOPS-PROJECT-ID") projectId: String, + @ApiParam("流水线ID", required = true) + @HeaderParam(AUTH_HEADER_DEVOPS_PIPELINE_ID) + pipelineId: String, @ApiParam("版本仓库类型", required = true) @PathParam("artifactoryType") artifactoryType: ArtifactoryType, diff --git a/src/backend/ci/core/artifactory/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/api/builds/BuildFileResource.kt b/src/backend/ci/core/artifactory/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/api/builds/BuildFileResource.kt index bd8d0998562..d0001ca05de 100644 --- a/src/backend/ci/core/artifactory/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/api/builds/BuildFileResource.kt +++ b/src/backend/ci/core/artifactory/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/api/builds/BuildFileResource.kt @@ -32,7 +32,6 @@ import com.tencent.devops.artifactory.pojo.enums.FileTypeEnum import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_BUILD_ID import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_PIPELINE_ID import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_PROJECT_ID -import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID import com.tencent.devops.common.api.pojo.Result import io.swagger.annotations.Api import io.swagger.annotations.ApiOperation @@ -62,9 +61,12 @@ interface BuildFileResource { @GET @Path("/file/download") fun downloadFile( - @ApiParam("用户ID", required = true) - @HeaderParam(AUTH_HEADER_USER_ID) - userId: String, + @ApiParam("projectCode", required = false) + @HeaderParam(AUTH_HEADER_DEVOPS_PROJECT_ID) + projectCode: String, + @ApiParam("pipelineId", required = false) + @HeaderParam(AUTH_HEADER_DEVOPS_PIPELINE_ID) + pipelineId: String, @ApiParam("文件路径", required = true) @QueryParam("filePath") filePath: String, @@ -77,9 +79,6 @@ interface BuildFileResource { @Path("/file/archive") @Consumes(MediaType.MULTIPART_FORM_DATA) fun archiveFile( - @ApiParam("用户ID", required = true) - @HeaderParam(AUTH_HEADER_USER_ID) - userId: String, @ApiParam("projectCode", required = false) @HeaderParam(AUTH_HEADER_DEVOPS_PROJECT_ID) projectCode: String, @@ -106,9 +105,6 @@ interface BuildFileResource { @GET @Path("/file/archive/download") fun downloadArchiveFile( - @ApiParam("用户ID", required = true) - @HeaderParam(AUTH_HEADER_USER_ID) - userId: String, @ApiParam("projectCode", required = true) @HeaderParam(AUTH_HEADER_DEVOPS_PROJECT_ID) projectCode: String, @@ -132,9 +128,6 @@ interface BuildFileResource { @GET @Path("/pipeline/{pipelineId}/build/{buildId}/file/download/urls/get") fun getFileDownloadUrls( - @ApiParam("用户ID", required = true) - @HeaderParam(AUTH_HEADER_USER_ID) - userId: String, @ApiParam("projectCode", required = true) @HeaderParam(AUTH_HEADER_DEVOPS_PROJECT_ID) projectCode: String, diff --git a/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/resources/SampleBuildFileResourceImpl.kt b/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/resources/SampleBuildFileResourceImpl.kt index 8ccf4b2d394..c72df19d6c3 100644 --- a/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/resources/SampleBuildFileResourceImpl.kt +++ b/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/resources/SampleBuildFileResourceImpl.kt @@ -32,21 +32,28 @@ import com.tencent.devops.artifactory.pojo.Count import com.tencent.devops.artifactory.pojo.enums.ArtifactoryType import com.tencent.devops.artifactory.service.ArchiveFileService import com.tencent.devops.common.api.pojo.Result +import com.tencent.devops.common.client.Client import com.tencent.devops.common.web.RestResource +import com.tencent.devops.process.api.service.ServicePipelineResource import org.springframework.beans.factory.annotation.Autowired @RestResource -class SampleBuildFileResourceImpl @Autowired constructor(private val archiveFileService: ArchiveFileService) : +class SampleBuildFileResourceImpl @Autowired constructor( + private val archiveFileService: ArchiveFileService, + private val client: Client +) : SampleBuildFileResource { override fun acrossProjectCopy( - userId: String, projectId: String, + pipelineId: String, artifactoryType: ArtifactoryType, path: String, targetProjectId: String, targetPath: String ): Result { + val userId = client.get(ServicePipelineResource::class) + .getPipelineInfo(projectId, pipelineId, null).data!!.lastModifyUser val count = archiveFileService.acrossProjectCopy( userId = userId, projectId = projectId, diff --git a/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/resources/BuildFileResourceImpl.kt b/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/resources/BuildFileResourceImpl.kt index 098cb6e139c..cfe71e18483 100644 --- a/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/resources/BuildFileResourceImpl.kt +++ b/src/backend/ci/core/artifactory/biz-artifactory/src/main/kotlin/com/tencent/devops/artifactory/resources/BuildFileResourceImpl.kt @@ -33,7 +33,9 @@ import com.tencent.devops.artifactory.pojo.enums.FileChannelTypeEnum import com.tencent.devops.artifactory.pojo.enums.FileTypeEnum import com.tencent.devops.artifactory.service.ArchiveFileService import com.tencent.devops.common.api.pojo.Result +import com.tencent.devops.common.client.Client import com.tencent.devops.common.web.RestResource +import com.tencent.devops.process.api.service.ServicePipelineResource import org.glassfish.jersey.media.multipart.FormDataContentDisposition import org.springframework.beans.factory.annotation.Autowired import java.io.InputStream @@ -41,15 +43,21 @@ import javax.servlet.http.HttpServletResponse @RestResource@Suppress("ALL") class BuildFileResourceImpl @Autowired constructor( - private val archiveFileService: ArchiveFileService + private val archiveFileService: ArchiveFileService, + private val client: Client ) : BuildFileResource { - override fun downloadFile(userId: String, filePath: String, response: HttpServletResponse) { + override fun downloadFile( + projectCode: String, + pipelineId: String, + filePath: String, + response: HttpServletResponse + ) { + val userId = getLastModifyUser(projectCode, pipelineId) archiveFileService.downloadFile(userId, filePath, response) } override fun archiveFile( - userId: String, projectCode: String, pipelineId: String, buildId: String, @@ -58,6 +66,7 @@ class BuildFileResourceImpl @Autowired constructor( inputStream: InputStream, disposition: FormDataContentDisposition ): Result { + val userId = getLastModifyUser(projectCode, pipelineId) val url = archiveFileService.archiveFile( userId = userId, projectId = projectCode, @@ -73,7 +82,6 @@ class BuildFileResourceImpl @Autowired constructor( } override fun downloadArchiveFile( - userId: String, projectCode: String, pipelineId: String, buildId: String, @@ -81,6 +89,7 @@ class BuildFileResourceImpl @Autowired constructor( customFilePath: String, response: HttpServletResponse ) { + val userId = getLastModifyUser(projectCode, pipelineId) return archiveFileService.downloadArchiveFile( userId = userId, projectId = projectCode, @@ -93,13 +102,13 @@ class BuildFileResourceImpl @Autowired constructor( } override fun getFileDownloadUrls( - userId: String, projectCode: String, pipelineId: String, buildId: String, fileType: FileTypeEnum, customFilePath: String? ): Result { + val userId = getLastModifyUser(projectCode, pipelineId) val urls = archiveFileService.getFileDownloadUrls( userId = userId, projectId = projectCode, @@ -111,4 +120,9 @@ class BuildFileResourceImpl @Autowired constructor( ) return Result(urls) } + + private fun getLastModifyUser(projectId: String, pipelineId: String): String { + return client.get(ServicePipelineResource::class) + .getPipelineInfo(projectId, pipelineId, null).data!!.lastModifyUser + } } From 5a3c7ef0e3cdb5ac654ed2e87fb8f05a38aacfe8 Mon Sep 17 00:00:00 2001 From: yaoxuwan Date: Thu, 28 Oct 2021 12:06:22 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20=E5=88=B6=E5=93=81=E5=BA=93=E5=8C=BF?= =?UTF-8?q?=E5=90=8D=E8=AE=BF=E9=97=AE=E6=B8=85=E7=90=86=20#5354?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../artifactory/resources/SampleBuildFileResourceImpl.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/resources/SampleBuildFileResourceImpl.kt b/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/resources/SampleBuildFileResourceImpl.kt index c72df19d6c3..1f053173353 100644 --- a/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/resources/SampleBuildFileResourceImpl.kt +++ b/src/backend/ci/core/artifactory/biz-artifactory-sample/src/main/kotlin/com/tencent/devops/artifactory/resources/SampleBuildFileResourceImpl.kt @@ -41,8 +41,7 @@ import org.springframework.beans.factory.annotation.Autowired class SampleBuildFileResourceImpl @Autowired constructor( private val archiveFileService: ArchiveFileService, private val client: Client -) : - SampleBuildFileResource { +) : SampleBuildFileResource { override fun acrossProjectCopy( projectId: String,