forked from TencentBlueKing/bk-ci
-
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.
Merge branch 'master' of https://github.com/Tencent/bk-ci into issue5…
…640_github_branch
- Loading branch information
Showing
221 changed files
with
4,340 additions
and
1,334 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
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
22 changes: 22 additions & 0 deletions
22
...c/main/kotlin/com/tencent/devops/artifactory/api/builds/BuildArtifactoryConfigResource.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,22 @@ | ||
package com.tencent.devops.artifactory.api.builds | ||
|
||
import com.tencent.devops.common.api.pojo.Result | ||
import io.swagger.annotations.Api | ||
import io.swagger.annotations.ApiOperation | ||
import javax.ws.rs.Consumes | ||
import javax.ws.rs.GET | ||
import javax.ws.rs.Path | ||
import javax.ws.rs.Produces | ||
import javax.ws.rs.core.MediaType | ||
|
||
@Api(tags = ["BUILD_ARTIFACTORY_CONF"], description = "仓库-配置管理") | ||
@Path("/build/artifactories/conf") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
interface BuildArtifactoryConfigResource { | ||
|
||
@ApiOperation("获取配置项artifactory.realm") | ||
@GET | ||
@Path("/realm") | ||
fun getRealm(): Result<String> | ||
} |
57 changes: 57 additions & 0 deletions
57
...ory/src/main/kotlin/com/tencent/devops/artifactory/api/builds/BuildFileGatewayResource.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,57 @@ | ||
/* | ||
* 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.devops.artifactory.api.builds | ||
|
||
import com.tencent.devops.artifactory.pojo.FileGatewayInfo | ||
import com.tencent.devops.common.api.auth.AUTH_HEADER_PROJECT_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 javax.ws.rs.Consumes | ||
import javax.ws.rs.GET | ||
import javax.ws.rs.HeaderParam | ||
import javax.ws.rs.Path | ||
import javax.ws.rs.Produces | ||
import javax.ws.rs.core.MediaType | ||
|
||
@Api(tags = ["BUILD_URL"], description = "文件网关") | ||
@Path("/build/fileGateway") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
interface BuildFileGatewayResource { | ||
|
||
@ApiOperation("获取项目文件网关配置") | ||
@Path("/get") | ||
@GET | ||
fun getFileGateway( | ||
@ApiParam("项目ID", required = true) | ||
@HeaderParam(AUTH_HEADER_PROJECT_ID) | ||
projectId: String | ||
): Result<FileGatewayInfo> | ||
} |
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
33 changes: 33 additions & 0 deletions
33
...ry/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/pojo/FileGatewayInfo.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,33 @@ | ||
/* | ||
* 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.devops.artifactory.pojo | ||
|
||
data class FileGatewayInfo( | ||
val fileDevnetGateway: String, | ||
val fileIdcGateway: String | ||
) |
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
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
103 changes: 103 additions & 0 deletions
103
...main/kotlin/com/tencent/devops/artifactory/service/impl/ArchiveAtomToBkRepoServiceImpl.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,103 @@ | ||
package com.tencent.devops.artifactory.service.impl | ||
|
||
import com.tencent.devops.artifactory.client.bkrepo.DefaultBkRepoClient | ||
import com.tencent.devops.artifactory.constant.BK_CI_ATOM_DIR | ||
import com.tencent.devops.artifactory.constant.BK_CI_PLUGIN_FE_DIR | ||
import com.tencent.devops.artifactory.constant.REALM_BK_REPO | ||
import com.tencent.devops.artifactory.util.BkRepoUtils.BKREPO_DEFAULT_USER | ||
import com.tencent.devops.artifactory.util.BkRepoUtils.BKREPO_STORE_PROJECT_ID | ||
import com.tencent.devops.artifactory.util.BkRepoUtils.REPO_NAME_PLUGIN | ||
import com.tencent.devops.artifactory.util.BkRepoUtils.REPO_NAME_STATIC | ||
import com.tencent.devops.artifactory.util.DefaultPathUtils | ||
import com.tencent.devops.common.api.constant.STATIC | ||
import com.tencent.devops.common.api.exception.RemoteServiceException | ||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty | ||
import org.springframework.stereotype.Service | ||
import java.io.File | ||
import java.io.InputStream | ||
import javax.ws.rs.NotFoundException | ||
|
||
@Service | ||
@ConditionalOnProperty(prefix = "artifactory", name = ["realm"], havingValue = REALM_BK_REPO) | ||
class ArchiveAtomToBkRepoServiceImpl( | ||
private val bkRepoClient: DefaultBkRepoClient | ||
) : ArchiveAtomServiceImpl() { | ||
|
||
override fun getAtomArchiveBasePath(): String { | ||
return System.getProperty("java.io.tmpdir") | ||
} | ||
|
||
override fun handleArchiveFile( | ||
disposition: FormDataContentDisposition, | ||
inputStream: InputStream, | ||
projectCode: String, | ||
atomCode: String, | ||
version: String | ||
) { | ||
unzipFile( | ||
disposition = disposition, | ||
inputStream = inputStream, | ||
projectCode = projectCode, | ||
atomCode = atomCode, | ||
version = version | ||
) | ||
val atomArchivePath = buildAtomArchivePath(projectCode, atomCode, version) | ||
val frontendDir = buildAtomFrontendPath(atomCode, version) | ||
logger.info("atom plugin: $atomArchivePath, $frontendDir") | ||
File(atomArchivePath).walk().filter { it.path != atomArchivePath }.forEach { | ||
val path = it.path.removePrefix("${getAtomArchiveBasePath()}/$BK_CI_ATOM_DIR") | ||
bkRepoClient.uploadLocalFile( | ||
userId = BKREPO_DEFAULT_USER, | ||
projectId = BKREPO_STORE_PROJECT_ID, | ||
repoName = REPO_NAME_PLUGIN, | ||
path = path, | ||
file = it | ||
) | ||
} | ||
File(frontendDir).walk().filter { it.path != frontendDir }.forEach { | ||
val path = it.path.removePrefix("${getAtomArchiveBasePath()}/$STATIC/$BK_CI_PLUGIN_FE_DIR") | ||
bkRepoClient.uploadLocalFile( | ||
userId = BKREPO_DEFAULT_USER, | ||
projectId = BKREPO_STORE_PROJECT_ID, | ||
repoName = REPO_NAME_STATIC, | ||
path = path, | ||
file = it | ||
) | ||
} | ||
} | ||
|
||
override fun getAtomFileContent(filePath: String): String { | ||
val tmpFile = DefaultPathUtils.randomFile() | ||
return try { | ||
bkRepoClient.downloadFile( | ||
userId = BKREPO_DEFAULT_USER, | ||
projectId = BKREPO_STORE_PROJECT_ID, | ||
repoName = REPO_NAME_PLUGIN, | ||
fullPath = filePath, | ||
destFile = tmpFile | ||
) | ||
tmpFile.readText(Charsets.UTF_8) | ||
} catch (e: NotFoundException) { | ||
logger.warn("file[$filePath] not exists") | ||
"" | ||
} catch (e: RemoteServiceException) { | ||
logger.warn("download file[$filePath] error: $e") | ||
"" | ||
} finally { | ||
tmpFile.delete() | ||
} | ||
} | ||
|
||
override fun clearServerTmpFile(projectCode: String, atomCode: String, version: String) { | ||
val atomArchivePath = buildAtomArchivePath(projectCode, atomCode, version) | ||
val frontendDir = buildAtomFrontendPath(atomCode, version) | ||
File(atomArchivePath).deleteRecursively() | ||
File(frontendDir).deleteRecursively() | ||
} | ||
|
||
companion object { | ||
private val logger = LoggerFactory.getLogger(ArchiveAtomToBkRepoServiceImpl::class.java) | ||
} | ||
} |
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
Oops, something went wrong.