Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 增加ohpm仓库 #2850 #2858 #2859

Open
wants to merge 1 commit into
base: feature-patch
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ enum class RepositoryType(val supportPackage: Boolean) {
SVN(false),
S3(false),
MEDIA(false),

OHPM(true),
;

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ object PackageKeys {

private const val DOCKER = "docker"
private const val NPM = "npm"
private const val OHPM = "ohpm"
private const val HELM = "helm"
private const val RPM = "rpm"
private const val PYPI = "pypi"
Expand Down Expand Up @@ -100,6 +101,15 @@ object PackageKeys {
return ofName(NPM, name)
}

/**
* 生成ohpm格式key
*
* 例子: ohpm://test
*/
fun ofOhpm(name: String): String {
return ofName(OHPM, name)
}

/**
* 生成helm格式key
*
Expand Down Expand Up @@ -166,6 +176,15 @@ object PackageKeys {
return resolveName(NPM, npmKey)
}

/**
* 解析ohpm格式的key
*
* 例子: ohpm://test -> test
*/
fun resolveOhpm(ohpmKey: String): String {
return resolveName(OHPM, ohpmKey)
}

/**
* 解析helm格式的key
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ object ProxyEnv {
private fun getProperty(key: String): String {
if (properties.isEmpty) {
if (!propertyFileResource.exists()) {
throw RuntimeException()
throw RuntimeException("properties is empty and property file resource not exist")
}

properties.load(propertyFileResource.inputStream)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ const val NPM_PKG_TGZ_FILE_FULL_PATH = NPM_PACKAGE_TGZ_FILE + "_full_path"
const val NPM_PKG_VERSION_JSON_FILE_FULL_PATH = NPM_PACKAGE_VERSION_JSON_FILE + "_full_path"
const val NPM_PKG_JSON_FILE_FULL_PATH = NPM_PACKAGE_JSON_FILE + "_full_path"
// full path value
const val NPM_PKG_TGZ_FULL_PATH = "/%s/-/%s-%s.tgz"
const val NPM_PKG_TGZ_WITH_DOWNLOAD_FULL_PATH = "/%s/download/%s-%s.tgz"
const val NPM_PKG_TGZ_FULL_PATH = "/%s/-/%s-%s%s"
const val NPM_PKG_TGZ_WITH_DOWNLOAD_FULL_PATH = "/%s/download/%s-%s%s"
const val NPM_PKG_VERSION_METADATA_FULL_PATH = "/.npm/%s/%s-%s.json"
const val NPM_PKG_METADATA_FULL_PATH = "/.npm/%s/package.json"

Expand All @@ -71,3 +71,18 @@ const val PKG_NAME = "pkg_name"
val ERROR_MAP = mapOf("error" to "not_found", "reason" to "document not found")

const val NPM_TGZ_TARBALL_PREFIX = "X-BKREPO-NPM-PREFIX"

// OHPM
const val INTEGRITY_HSP = "integrity_hsp"
const val RESOLVED_HSP = "resolved_hsp"
const val HSP_FILE_EXT = ".hsp"
const val HAR_FILE_EXT = ".har"
const val HSP_TYPE = "hspType"
const val HSP_TYPE_BUNDLE_APP = "bundle_app"
const val OHPM_PACKAGE_TYPE = "packageType"
const val OHPM_PACKAGE_TYPE_HSP = "InterfaceHar"
const val OHPM_ARTIFACT_TYPE = "artifactType"
const val OHPM_DEFAULT_ARTIFACT_TYPE = "original"
const val OHPM_DEPRECATE = "deprecate"
const val OHPM_CHANGELOG_FILE_NAME = "changelog.md"
const val OHPM_README_FILE_NAME = "readme.md"
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
*
* Copyright (C) 2024 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.npm.pojo

import com.fasterxml.jackson.annotation.JsonInclude
import com.tencent.bkrepo.common.api.constant.HttpStatus

@JsonInclude(JsonInclude.Include.NON_NULL)
data class OhpmResponse(
val code: Int = HttpStatus.OK.value,
val message: String? = null,
/**
* 出错时ohpm客户端会取响应体中error字段的值进行打印提示
*/
val error: String? = null,
/**
* ohpm客户端会在发布包成功后打印该字段的值
*/
val additionalMsg: String? = null,
) {
companion object {
fun success(message: String = "success") = OhpmResponse(HttpStatus.OK.value, message)
fun error(code: Int, error: String) = OhpmResponse(code = code, error = error)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
*
* Copyright (C) 2024 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.npm.pojo.user

data class OhpmDistTagRequest(
val version: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
*
* Copyright (C) 2024 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.npm.pojo.user

data class OhpmUnpublishRequest(
val version: String
)
1 change: 1 addition & 0 deletions src/backend/npm/biz-npm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ dependencies {
api(project(":common:common-artifact:artifact-service"))
implementation("org.springframework.retry:spring-retry")
implementation("com.google.code.gson:gson")
implementation("com.github.zafarkhaja:java-semver")
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,23 @@ import com.tencent.bkrepo.common.api.pojo.Response
import com.tencent.bkrepo.common.artifact.config.ArtifactConfigurerSupport
import com.tencent.bkrepo.common.artifact.exception.ExceptionResponseTranslator
import com.tencent.bkrepo.common.artifact.pojo.RepositoryType
import com.tencent.bkrepo.common.artifact.repository.context.ArtifactContextHolder
import com.tencent.bkrepo.common.security.http.core.HttpAuthSecurityCustomizer
import com.tencent.bkrepo.common.service.util.HttpContextHolder
import com.tencent.bkrepo.common.service.util.SpringContextUtils
import com.tencent.bkrepo.npm.artifact.repository.NpmLocalRepository
import com.tencent.bkrepo.npm.artifact.repository.NpmRemoteRepository
import com.tencent.bkrepo.npm.artifact.repository.NpmVirtualRepository
import com.tencent.bkrepo.npm.pojo.NpmErrorResponse
import com.tencent.bkrepo.npm.pojo.OhpmResponse
import org.springframework.http.server.ServerHttpRequest
import org.springframework.http.server.ServerHttpResponse
import org.springframework.stereotype.Component

@Component
class NpmArtifactConfigurer : ArtifactConfigurerSupport() {

override fun getRepositoryTypes() = listOf(RepositoryType.OHPM)
override fun getRepositoryType() = RepositoryType.NPM
override fun getLocalRepository() = SpringContextUtils.getBean<NpmLocalRepository>()
override fun getRemoteRepository() = SpringContextUtils.getBean<NpmRemoteRepository>()
Expand All @@ -62,7 +66,11 @@ class NpmArtifactConfigurer : ArtifactConfigurerSupport() {

override fun getExceptionResponseTranslator() = object : ExceptionResponseTranslator {
override fun translate(payload: Response<*>, request: ServerHttpRequest, response: ServerHttpResponse): Any {
return NpmErrorResponse(payload.message.orEmpty(), StringPool.EMPTY)
return if (ArtifactContextHolder.getRepoDetailOrNull()?.type == RepositoryType.OHPM) {
OhpmResponse.error(HttpContextHolder.getResponse().status, payload.message.orEmpty())
} else {
NpmErrorResponse(payload.message.orEmpty(), StringPool.EMPTY)
}
}
}
}
Loading