Skip to content

Commit

Permalink
Merge pull request #2543 from carlyin0801/issue_1334_atom_del
Browse files Browse the repository at this point in the history
bug: 在工作台删除某个插件后,无法重复创建同名插件 #1334
  • Loading branch information
irwinsun committed Sep 22, 2020
2 parents 0ea6c98 + 609e269 commit c876bd6
Show file tree
Hide file tree
Showing 36 changed files with 449 additions and 23 deletions.
Expand Up @@ -31,6 +31,7 @@ import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.annotations.ApiParam
import javax.ws.rs.Consumes
import javax.ws.rs.DELETE
import javax.ws.rs.GET
import javax.ws.rs.Path
import javax.ws.rs.Produces
Expand All @@ -51,4 +52,16 @@ interface ServiceArchiveAtomResource {
@QueryParam("filePath")
filePath: String
): Result<String>

@ApiOperation("删除插件包文件")
@DELETE
@Path("/atom/file/delete")
fun deleteAtomFile(
@ApiParam("项目编码", required = true)
@QueryParam("projectCode")
projectCode: String,
@ApiParam("插件代码", required = true)
@QueryParam("atomCode")
atomCode: String
): Result<Boolean>
}
Expand Up @@ -27,16 +27,24 @@
package com.tencent.devops.artifactory.resources

import com.tencent.devops.artifactory.api.ServiceArchiveAtomResource
import com.tencent.devops.artifactory.constant.BK_CI_ATOM_DIR
import com.tencent.devops.artifactory.service.ArchiveAtomService
import com.tencent.devops.artifactory.service.ArchiveFileService
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.web.RestResource
import org.springframework.beans.factory.annotation.Autowired

@RestResource
class ServiceArchiveAtomResourceImpl @Autowired constructor(private val archiveAtomService: ArchiveAtomService) :
ServiceArchiveAtomResource {
class ServiceArchiveAtomResourceImpl @Autowired constructor(
private val archiveFileService: ArchiveFileService,
private val archiveAtomService: ArchiveAtomService
) : ServiceArchiveAtomResource {

override fun getAtomFileContent(filePath: String): Result<String> {
return archiveAtomService.getAtomFileContent(filePath)
}

override fun deleteAtomFile(projectCode: String, atomCode: String): Result<Boolean> {
return archiveFileService.deleteFile("$BK_CI_ATOM_DIR/$projectCode/$atomCode")
}
}
Expand Up @@ -63,7 +63,13 @@ class ArchiveAtomToLocalServiceImpl : ArchiveAtomServiceImpl() {
return Result(content)
}

override fun handleArchiveFile(disposition: FormDataContentDisposition, inputStream: InputStream, projectCode: String, atomCode: String, version: String) {
override fun handleArchiveFile(
disposition: FormDataContentDisposition,
inputStream: InputStream,
projectCode: String,
atomCode: String,
version: String
) {
unzipFile(disposition, inputStream, projectCode, atomCode, version)
}

Expand Down
Expand Up @@ -207,4 +207,11 @@ interface ArchiveFileService {
targetProjectId: String,
targetPath: String
): Result<Count>

/**
* 删除文件
*/
fun deleteFile(
filePath: String
): Result<Boolean>
}
Expand Up @@ -44,6 +44,7 @@ import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Service
import org.springframework.util.AntPathMatcher
import org.springframework.util.FileCopyUtils
import org.springframework.util.FileSystemUtils
import java.io.File
import java.io.FileInputStream
import java.io.InputStream
Expand Down Expand Up @@ -300,6 +301,11 @@ class DiskArchiveFileServiceImpl : ArchiveFileService, ArchiveFileServiceImpl()
return Result(Count(fileList.size))
}

override fun deleteFile(filePath: String): Result<Boolean> {
FileSystemUtils.deleteRecursively(File("$archiveLocalBasePath/$filePath"))
return Result(true)
}

companion object {
private val logger = LoggerFactory.getLogger(DiskArchiveFileServiceImpl::class.java)
}
Expand Down
Expand Up @@ -242,6 +242,11 @@ class JFrogArchiveFileServiceImpl : ArchiveFileService, ArchiveFileServiceImpl()
return Result(Count(0))
}

override fun deleteFile(filePath: String): Result<Boolean> {
jFrogService.tryDelete("${getBasePath()}$filePath")
return Result(true)
}

companion object {
private val logger = LoggerFactory.getLogger(JFrogArchiveFileServiceImpl::class.java)
}
Expand Down
Expand Up @@ -326,6 +326,36 @@ class RepositoryService @Autowired constructor(
return Result(true)
}

fun deleteGitProject(
userId: String,
repositoryConfig: RepositoryConfig,
tokenType: TokenTypeEnum
): Result<Boolean> {
logger.info("deleteGitProject userId is:$userId,repositoryConfig is:$repositoryConfig,tokenType is:$tokenType")
val repo: CodeGitRepository = serviceGet("", repositoryConfig) as CodeGitRepository
logger.info("the repo is:$repo")
val finalTokenType = generateFinalTokenType(tokenType, repo.projectName)
val getGitTokenResult = getGitToken(finalTokenType, userId)
if (getGitTokenResult.isNotOk()) {
return Result(status = getGitTokenResult.status, message = getGitTokenResult.message, data = false)
}
val token = getGitTokenResult.data!!
val deleteGitProjectResult = gitService.deleteGitProject(
repoName = repo.projectName,
token = token,
tokenType = finalTokenType
)
logger.info("deleteGitProjectResult is :$deleteGitProjectResult")
if (deleteGitProjectResult.isNotOk()) {
return Result(
status = deleteGitProjectResult.status,
message = deleteGitProjectResult.message,
data = false
)
}
return Result(true)
}

fun moveGitProjectToGroup(
userId: String,
groupCode: String?,
Expand Down
Expand Up @@ -645,6 +645,32 @@ class GitService @Autowired constructor(
}
}

override fun deleteGitProject(repoName: String, token: String, tokenType: TokenTypeEnum): Result<Boolean> {
logger.info("deleteGitProject repoName is:$repoName,token is:$token,tokenType is:$tokenType")
val encodeProjectName = URLEncoder.encode(repoName, "utf-8") // 为代码库名称字段encode
val url = StringBuilder("${gitConfig.gitApiUrl}/projects/$encodeProjectName")
setToken(tokenType, url, token)
val request = Request.Builder()
.url(url.toString())
.delete()
.build()
OkhttpUtils.doHttp(request).use {
val data = it.body()!!.string()
logger.info("deleteGitProject token is:$token, response>> $data")
if (!StringUtils.isEmpty(data)) {
val dataMap = JsonUtil.toMap(data)
val message = dataMap["message"]
if (!StringUtils.isEmpty(message)) {
val validateResult: Result<String?> =
MessageCodeUtil.generateResponseDataObject(RepositoryMessageCode.USER_UPDATE_GIT_CODE_REPOSITORY_FAIL)
// 把工蜂的错误提示抛出去
return Result(validateResult.status, "${validateResult.message}(git error:$message")
}
}
return Result(data = true)
}
}

fun getGitUserInfo(userId: String, token: String, tokenType: TokenTypeEnum): Result<GitUserInfo?> {
logger.info("getGitUserInfo token is:$token, userId is:$userId,tokenType is:$tokenType")
val url = StringBuilder("${gitConfig.gitApiUrl}/users/$userId")
Expand Down
Expand Up @@ -94,6 +94,12 @@ interface IGitService {
tokenType: TokenTypeEnum
): Result<Boolean>

fun deleteGitProject(
repoName: String,
token: String,
tokenType: TokenTypeEnum
): Result<Boolean>

fun updateGitProjectInfo(
projectName: String,
updateGitProjectInfo: UpdateGitProjectInfo,
Expand Down
Expand Up @@ -28,6 +28,7 @@ package com.tencent.devops.store.service.atom.impl

import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.repository.pojo.Repository
import com.tencent.devops.repository.pojo.enums.TokenTypeEnum
import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum
import com.tencent.devops.store.service.atom.SampleMarketAtomService
import org.slf4j.LoggerFactory
Expand Down Expand Up @@ -63,7 +64,12 @@ class SampleMarketAtomServiceImpl : SampleMarketAtomService, MarketAtomServiceIm
return Result(data = null)
}

override fun deleteAtomRepository(userId: String, projectCode: String?, repositoryHashId: String): Result<Boolean> {
override fun deleteAtomRepository(
userId: String,
projectCode: String?,
repositoryHashId: String,
tokenType: TokenTypeEnum
): Result<Boolean> {
// 开源版暂不支持按代码库打成可执行包的方式
return Result(true)
}
Expand Down
Expand Up @@ -27,6 +27,7 @@
package com.tencent.devops.store.dao.atom

import com.tencent.devops.common.api.util.UUIDUtil
import com.tencent.devops.model.store.tables.TAtom
import com.tencent.devops.model.store.tables.TAtomLabelRel
import com.tencent.devops.model.store.tables.TLabel
import com.tencent.devops.store.pojo.common.KEY_CREATE_TIME
Expand Down Expand Up @@ -69,6 +70,16 @@ class AtomLabelRelDao {
}
}

fun deleteByAtomCode(dslContext: DSLContext, atomCode: String) {
val ta = TAtom.T_ATOM
val atomIds = dslContext.select(ta.ID).from(ta).where(ta.ATOM_CODE.eq(atomCode)).fetch()
with(TAtomLabelRel.T_ATOM_LABEL_REL) {
dslContext.deleteFrom(this)
.where(ATOM_ID.`in`(atomIds))
.execute()
}
}

fun batchAdd(dslContext: DSLContext, userId: String, atomId: String, labelIdList: List<String>) {
with(TAtomLabelRel.T_ATOM_LABEL_REL) {
val addStep = labelIdList.map {
Expand Down
Expand Up @@ -216,4 +216,14 @@ class MarketAtomEnvInfoDao {
.execute()
}
}

fun deleteAtomEnvInfo(dslContext: DSLContext, atomCode: String) {
val ta = TAtom.T_ATOM
val atomIds = dslContext.select(ta.ID).from(ta).where(ta.ATOM_CODE.eq(atomCode)).fetch()
with(TAtomEnvInfo.T_ATOM_ENV_INFO) {
dslContext.deleteFrom(this)
.where(ATOM_ID.`in`(atomIds))
.execute()
}
}
}
Expand Up @@ -101,4 +101,12 @@ class MarketAtomFeatureDao {
}
}
}

fun deleteAtomFeature(dslContext: DSLContext, atomCode: String) {
with(TAtomFeature.T_ATOM_FEATURE) {
dslContext.deleteFrom(this)
.where(ATOM_CODE.eq(atomCode))
.execute()
}
}
}
Expand Up @@ -80,7 +80,6 @@ class MarketAtomOfflineDao {
/**
* 设置状态
*/

fun setStatus(dslContext: DSLContext, id: String, status: Byte, userId: String) {
with(TAtomOffline.T_ATOM_OFFLINE) {
dslContext.update(this)
Expand All @@ -90,4 +89,15 @@ class MarketAtomOfflineDao {
.execute()
}
}

/**
* 删除插件下线记录
*/
fun deleteAtomOffline(dslContext: DSLContext, atomCode: String) {
with(TAtomOffline.T_ATOM_OFFLINE) {
dslContext.deleteFrom(this)
.where(ATOM_CODE.eq(atomCode))
.execute()
}
}
}
Expand Up @@ -27,6 +27,7 @@
package com.tencent.devops.store.dao.atom

import com.tencent.devops.common.api.util.UUIDUtil
import com.tencent.devops.model.store.tables.TAtom
import com.tencent.devops.model.store.tables.TAtomVersionLog
import com.tencent.devops.model.store.tables.records.TAtomVersionLogRecord
import org.jooq.DSLContext
Expand Down Expand Up @@ -70,4 +71,14 @@ class MarketAtomVersionLogDao {
.fetchOne()
}
}

fun deleteByAtomCode(dslContext: DSLContext, atomCode: String) {
val ta = TAtom.T_ATOM
val atomIds = dslContext.select(ta.ID).from(ta).where(ta.ATOM_CODE.eq(atomCode)).fetch()
with(TAtomVersionLog.T_ATOM_VERSION_LOG) {
dslContext.deleteFrom(this)
.where(ATOM_ID.`in`(atomIds))
.execute()
}
}
}
Expand Up @@ -97,4 +97,12 @@ class OperationLogDao {
dslContext.batch(addStep).execute()
}
}

fun deleteOperationLog(dslContext: DSLContext, storeCode: String, storeType: Byte) {
with(TStoreOptLog.T_STORE_OPT_LOG) {
dslContext.deleteFrom(this)
.where(STORE_CODE.eq(storeCode).and(STORE_TYPE.eq(storeType)))
.execute()
}
}
}
Expand Up @@ -38,6 +38,7 @@ class ReasonRelDao {
id: String,
userId: String,
storeCode: String,
storeType: Byte,
reasonId: String,
note: String?,
type: String
Expand All @@ -49,6 +50,7 @@ class ReasonRelDao {
REASON_ID,
NOTE,
STORE_CODE,
STORE_TYPE,
TYPE,
CREATOR
)
Expand All @@ -57,6 +59,7 @@ class ReasonRelDao {
reasonId,
note,
storeCode,
storeType,
type,
userId
).execute()
Expand All @@ -74,4 +77,13 @@ class ReasonRelDao {
.fetchOne(0, Long::class.java) != 0L
}
}

fun deleteReasonRel(dslContext: DSLContext, storeCode: String, storeType: Byte) {
with(TReasonRel.T_REASON_REL) {
dslContext.deleteFrom(this)
.where(STORE_CODE.eq(storeCode))
.and(STORE_TYPE.eq(storeType))
.execute()
}
}
}
Expand Up @@ -168,4 +168,15 @@ class SensitiveConfDao {
.fetch()
}
}

/**
* 删除敏感信息配置
*/
fun deleteSensitiveConf(dslContext: DSLContext, storeCode: String, storeType: Byte) {
with(TStoreSensitiveConf.T_STORE_SENSITIVE_CONF) {
dslContext.deleteFrom(this)
.where(STORE_CODE.eq(storeCode).and(STORE_TYPE.eq(storeType)))
.execute()
}
}
}

0 comments on commit c876bd6

Please sign in to comment.