diff --git a/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/constant/StoreMessageCode.kt b/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/constant/StoreMessageCode.kt index 82aa425d2b1..8864b5e8ae7 100644 --- a/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/constant/StoreMessageCode.kt +++ b/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/constant/StoreMessageCode.kt @@ -95,7 +95,7 @@ object StoreMessageCode { const val USER_PULL_FILE_FAIL = "2120041" // 插件包文件[{0}]不存在,请检查文件所在路径是否正确 const val ATOM_PACKAGE_FILE_NOT_FOUND = "2120042" - const val USER_REPOSITORY_TASK_JSON_FIELD_IS_NOT_SUPPORT = "2120043" // 研发商店:插件配置文件[task.json]{0}字段暂时只支持{1},{2},{3},{4} + const val USER_REPOSITORY_TASK_JSON_FIELD_IS_NOT_SUPPORT = "2120043" // 研发商店:插件配置文件[task.json]{0}字段里面的{1}字段暂时只支持{2} const val USER_TEMPLATE_VERSION_IS_NOT_FINISH = "2120201" // 研发商店:模板{0}的{1}版本发布未结束,请稍后再试 const val USER_TEMPLATE_RELEASE_STEPS_ERROR = "2120202" // 研发商店:模板发布流程状态变更顺序不正确 diff --git a/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/pojo/common/StoreConstants.kt b/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/pojo/common/StoreConstants.kt index ffe9f6fee89..16247070205 100644 --- a/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/pojo/common/StoreConstants.kt +++ b/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/pojo/common/StoreConstants.kt @@ -117,6 +117,8 @@ const val KEY_TARGET = "target" const val KEY_LANGUAGE = "language" const val KEY_MINIMUM_VERSION = "minimumVersion" const val KEY_DEMANDS = "demands" +const val KEY_TYPE = "type" +const val IS_EXPANDED="isExpanded" // 是否默认展开分组 const val KEY_PACKAGE_PATH = "packagePath" const val KEY_DEFAULT = "default" const val KEY_ATOM_CODE = "atomCode" diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/impl/MarketAtomCommonServiceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/impl/MarketAtomCommonServiceImpl.kt index 270f1378dd5..aa38b62a01d 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/impl/MarketAtomCommonServiceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/impl/MarketAtomCommonServiceImpl.kt @@ -27,6 +27,7 @@ package com.tencent.devops.store.atom.service.impl +import com.tencent.devops.common.api.constant.ARTIFACT import com.tencent.devops.common.api.constant.COMPONENT import com.tencent.devops.common.api.constant.CommonMessageCode import com.tencent.devops.common.api.constant.GOLANG @@ -35,9 +36,13 @@ import com.tencent.devops.common.api.constant.JAVA import com.tencent.devops.common.api.constant.KEY_OS import com.tencent.devops.common.api.constant.KEY_OS_ARCH import com.tencent.devops.common.api.constant.KEY_OS_NAME +import com.tencent.devops.common.api.constant.LABEL +import com.tencent.devops.common.api.constant.NAME import com.tencent.devops.common.api.constant.NODEJS import com.tencent.devops.common.api.constant.PYTHON +import com.tencent.devops.common.api.constant.REPORT import com.tencent.devops.common.api.constant.REQUIRED +import com.tencent.devops.common.api.constant.STRING import com.tencent.devops.common.api.constant.TYPE import com.tencent.devops.common.api.enums.FrontendTypeEnum import com.tencent.devops.common.api.exception.ErrorCodeException @@ -81,6 +86,7 @@ import com.tencent.devops.store.pojo.common.ATOM_POST_ENTRY_PARAM import com.tencent.devops.store.pojo.common.ATOM_POST_FLAG import com.tencent.devops.store.pojo.common.ATOM_POST_NORMAL_PROJECT_FLAG_KEY_PREFIX import com.tencent.devops.store.pojo.common.ATOM_POST_VERSION_TEST_FLAG_KEY_PREFIX +import com.tencent.devops.store.pojo.common.IS_EXPANDED import com.tencent.devops.store.pojo.common.KEY_ATOM_CODE import com.tencent.devops.store.pojo.common.KEY_CONFIG import com.tencent.devops.store.pojo.common.KEY_DEFAULT @@ -89,12 +95,14 @@ import com.tencent.devops.store.pojo.common.KEY_DEMANDS import com.tencent.devops.store.pojo.common.KEY_EXECUTION import com.tencent.devops.store.pojo.common.KEY_FINISH_KILL_FLAG import com.tencent.devops.store.pojo.common.KEY_INPUT +import com.tencent.devops.store.pojo.common.KEY_INPUT_GROUPS import com.tencent.devops.store.pojo.common.KEY_LANGUAGE import com.tencent.devops.store.pojo.common.KEY_MINIMUM_VERSION import com.tencent.devops.store.pojo.common.KEY_OUTPUT import com.tencent.devops.store.pojo.common.KEY_PACKAGE_PATH import com.tencent.devops.store.pojo.common.KEY_RUNTIME_VERSION import com.tencent.devops.store.pojo.common.KEY_TARGET +import com.tencent.devops.store.pojo.common.KEY_TYPE import com.tencent.devops.store.pojo.common.TASK_JSON_NAME import com.tencent.devops.store.pojo.common.enums.ReleaseTypeEnum import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum @@ -383,6 +391,21 @@ class MarketAtomCommonServiceImpl : MarketAtomCommonService { ) } val executionInfoMap = taskDataMap[KEY_EXECUTION] as? Map + val keyInputGroupMapList = taskDataMap[KEY_INPUT_GROUPS] as? List> + if (!keyInputGroupMapList.isNullOrEmpty()) { + fun checkInputGroupFieldNotNull(inputGroupMap: Map, fieldName: String) { + inputGroupMap[fieldName] as? String + ?: throw ErrorCodeException( + errorCode = StoreMessageCode.USER_REPOSITORY_TASK_JSON_FIELD_IS_NULL, + params = arrayOf(fieldName) + ) + } + keyInputGroupMapList.forEach { inputGroupMap -> + checkInputGroupFieldNotNull(inputGroupMap, NAME) + checkInputGroupFieldNotNull(inputGroupMap, LABEL) + checkInputGroupFieldNotNull(inputGroupMap, IS_EXPANDED) + } + } var atomPostInfo: AtomPostInfo? = null if (executionInfoMap == null) { // 抛出错误提示 @@ -393,22 +416,13 @@ class MarketAtomCommonServiceImpl : MarketAtomCommonService { } // pref:完善研发商店组件配置文件参数校验 #11269 val supportedLanguages = setOf(JAVA, PYTHON, GOLANG, NODEJS) - val language = executionInfoMap[KEY_LANGUAGE]?.let { language -> - when (language) { - is String -> { - if (language in supportedLanguages) { - language - } else { - throw ErrorCodeException( - errorCode = StoreMessageCode.USER_REPOSITORY_TASK_JSON_FIELD_IS_NOT_SUPPORT, - params = arrayOf(KEY_LANGUAGE, supportedLanguages.joinToString(separator = ",")) - ) - } - } - - else -> throw ErrorCodeException( - errorCode = StoreMessageCode.USER_REPOSITORY_TASK_JSON_FIELD_IS_INVALID, - params = arrayOf(KEY_LANGUAGE) + val language = executionInfoMap[KEY_LANGUAGE]?.toString()?.let { language -> + if (language in supportedLanguages) { + language + } else { + throw ErrorCodeException( + errorCode = StoreMessageCode.USER_REPOSITORY_TASK_JSON_FIELD_IS_NOT_SUPPORT, + params = arrayOf(KEY_EXECUTION,KEY_LANGUAGE, supportedLanguages.joinToString(separator = ",")) ) } } ?: throw ErrorCodeException( @@ -453,7 +467,7 @@ class MarketAtomCommonServiceImpl : MarketAtomCommonService { } else { runtimeVersion } - if (null != osList) { + if (!osList.isNullOrEmpty()) { val osDefaultEnvNumMap = mutableMapOf() osList.forEach { osExecutionInfoMap -> val osName = osExecutionInfoMap[KEY_OS_NAME] as? String @@ -526,22 +540,49 @@ class MarketAtomCommonServiceImpl : MarketAtomCommonService { atomEnvRequests.add(atomEnvRequest) } - // 校验参数输入参数和输出参数是否超过最大值 val inputDataMap = taskDataMap[KEY_INPUT] as? Map - if (inputDataMap != null && inputDataMap.size > maxInputNum) { + inputDataMap?.let { validateInputOutputData(it, maxInputNum) } + + val supportedTypes = setOf(STRING, ARTIFACT, REPORT) + val outputDataMap = taskDataMap[KEY_OUTPUT] as? Map + outputDataMap?.let { validateInputOutputData(it, maxInputNum, supportedTypes, isInput = false) } + return GetAtomConfigResult("0", arrayOf(""), taskDataMap, atomEnvRequests) + } + + + private fun validateInputOutputData( + dataMap: Map, + maxInputNum: Int, + supportedTypes: Set? = null, + isInput: Boolean = true + ) { + if (dataMap.size > maxInputNum) { throw ErrorCodeException( errorCode = StoreMessageCode.USER_ATOM_INPUT_NUM_IS_TOO_MANY, params = arrayOf(maxInputNum.toString()) ) } - val outputDataMap = taskDataMap[KEY_OUTPUT] as? Map - if (outputDataMap != null && outputDataMap.size > maxOutputNum) { - throw ErrorCodeException( - errorCode = StoreMessageCode.USER_ATOM_OUTPUT_NUM_IS_TOO_MANY, - params = arrayOf(maxOutputNum.toString()) - ) - } - return GetAtomConfigResult("0", arrayOf(""), taskDataMap, atomEnvRequests) + + dataMap.values + .mapNotNull { it as? Map<*, *> } + .forEach { map -> + val type = map[KEY_TYPE]?.toString() + when { + type.isNullOrEmpty() -> { + throw ErrorCodeException( + errorCode = StoreMessageCode.USER_REPOSITORY_TASK_JSON_FIELD_IS_NULL, + params = arrayOf(KEY_TYPE) + ) + } + + !isInput && (supportedTypes != null && type !in supportedTypes) -> { + throw ErrorCodeException( + errorCode = StoreMessageCode.USER_REPOSITORY_TASK_JSON_FIELD_IS_NOT_SUPPORT, + params = arrayOf(KEY_OUTPUT, KEY_TYPE,supportedTypes.joinToString(separator = ",")) + ) + } + } + } } private fun validateConfigMap(configMap: Map) { diff --git a/support-files/i18n/store/message_en_US.properties b/support-files/i18n/store/message_en_US.properties index fdc7a59cf75..f2f73248a81 100644 --- a/support-files/i18n/store/message_en_US.properties +++ b/support-files/i18n/store/message_en_US.properties @@ -109,7 +109,7 @@ 2120935=When the queryProjectComponentFlag, installed, or updateFlag parameters are not empty, the projectCode parameter must be non-empty 2120936=store: Unreleased versions are not allowed to be removed from the shelves -2120043=store: The [task.json] file's {0} field currently only supports {1} +2120043=store: In the plugin configuration file [task.json], the field {0} contains the subfield {1}, which currently only supports {2} ATOM.classify.common=Others ATOM.classify.compileBuild=Compile ATOM.classify.deploy=Deploy diff --git a/support-files/i18n/store/message_zh_CN.properties b/support-files/i18n/store/message_zh_CN.properties index e778926b642..5ef1e4d39c8 100644 --- a/support-files/i18n/store/message_zh_CN.properties +++ b/support-files/i18n/store/message_zh_CN.properties @@ -40,7 +40,7 @@ 2120040=研发商店:插件配置文件[task.json]config配置格式不正确,{0} 2120041=研发商店: 拉取文件[{0}]失败,失败原因:{1} 2120042=插件包文件[{0}]不存在,请检查文件所在路径是否正确 -2120043=研发商店:插件配置文件[task.json]{0}字段暂时只支持{1} +2120043=研发商店:插件配置文件[task.json]{0}字段里面的{1}字段暂时只支持{2} 2120201=研发商店: 模板{0}的{1}版本发布未结束,请稍后再试 2120202=研发商店: 模板发布流程状态变更顺序不正确 2120203=研发商店: 模板的可见范围不在插件{0}的可见范围之内,如有需要请联系插件的发布者