Skip to content

Commit

Permalink
feat: 加固制品允许匿名下载 TencentBlueKing#1605 (TencentBlueKing#1606)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoxuwan authored Jan 5, 2024
1 parent 8ab0821 commit 52b4df3
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class ShareServiceImpl(
override fun download(userId: String, token: String, artifactInfo: ArtifactInfo) {
logger.info("artifact[$artifactInfo] download user: $userId")
val shareRecord = checkToken(userId, token, artifactInfo)
checkAlphaApkDownloadUser(userId, artifactInfo)
checkAlphaApkDownloadUser(userId, artifactInfo, shareRecord.createdBy)
with(artifactInfo) {
val downloadUser = if (userId == ANONYMOUS_USER) shareRecord.createdBy else userId
val repo = repositoryService.getRepoDetail(projectId, repoName)
Expand All @@ -149,16 +149,16 @@ class ShareServiceImpl(
}

/**
* 加固签名的apk包,不允许匿名下载
* 加固签名的apk包,匿名下载时,使用分享人身份下载
*/
private fun checkAlphaApkDownloadUser(userId: String, artifactInfo: ArtifactInfo) {
private fun checkAlphaApkDownloadUser(userId: String, artifactInfo: ArtifactInfo, shareUserId: String) {
val nodeDetail = ArtifactContextHolder.getNodeDetail(artifactInfo)
?: throw NodeNotFoundException(artifactInfo.getArtifactFullPath())
val appStageKey = nodeDetail.metadata.keys.find { it.equals(BK_CI_APP_STAGE_KEY, true) }
?: return
val alphaApk = nodeDetail.metadata[appStageKey]?.toString().equals(ALPHA, true)
if (alphaApk && userId == ANONYMOUS_USER) {
throw PermissionException("anonymous user can not download the alpha apk.")
HttpContextHolder.getRequest().setAttribute(USER_KEY, shareUserId)
}
}

Expand Down

0 comments on commit 52b4df3

Please sign in to comment.