Skip to content

Commit

Permalink
pref:完善研发商店组件配置文件参数校验 TencentBlueKing#11269
Browse files Browse the repository at this point in the history
  • Loading branch information
Kzhou991 committed Dec 13, 2024
1 parent 3afd17e commit 484b06b
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Service
import javax.ws.rs.core.Response
import kotlin.reflect.KClass

@Suppress("ALL")
@Service
Expand Down Expand Up @@ -394,9 +395,9 @@ class MarketAtomCommonServiceImpl : MarketAtomCommonService {
val keyInputGroupMapList = taskDataMap[KEY_INPUT_GROUPS] as? List<Map<String, Any>>
if (!keyInputGroupMapList.isNullOrEmpty()) {
keyInputGroupMapList.forEach { inputGroupMap ->
validateTaskJsonField(inputGroupMap, NAME, String::class.java)
validateTaskJsonField(inputGroupMap, LABEL, String::class.java)
validateTaskJsonField(inputGroupMap, IS_EXPANDED, Boolean::class.java)
validateTaskJsonField(inputGroupMap, NAME, String::class)
validateTaskJsonField(inputGroupMap, LABEL, String::class)
validateTaskJsonField(inputGroupMap, IS_EXPANDED, Boolean::class)
}
}
var atomPostInfo: AtomPostInfo? = null
Expand Down Expand Up @@ -463,10 +464,10 @@ class MarketAtomCommonServiceImpl : MarketAtomCommonService {
if (!osList.isNullOrEmpty()) {
val osDefaultEnvNumMap = mutableMapOf<String, Int>()
osList.forEach { osExecutionInfoMap ->
validateTaskJsonField(osExecutionInfoMap, KEY_OS_NAME, String::class.java)
validateTaskJsonField(osExecutionInfoMap, KEY_OS_NAME, String::class)
val osName = osExecutionInfoMap[KEY_OS_NAME].toString()

validateTaskJsonField(osExecutionInfoMap, KEY_TARGET, String::class.java)
validateTaskJsonField(osExecutionInfoMap, KEY_TARGET, String::class)
val target = osExecutionInfoMap[KEY_TARGET].toString()
val osArch = osExecutionInfoMap[KEY_OS_ARCH] as? String
val defaultFlag = osExecutionInfoMap[KEY_DEFAULT_FLAG] as? Boolean ?: false
Expand Down Expand Up @@ -506,7 +507,7 @@ class MarketAtomCommonServiceImpl : MarketAtomCommonService {
}
}
} else {
validateTaskJsonField(executionInfoMap, KEY_TARGET, String::class.java)
validateTaskJsonField(executionInfoMap, KEY_TARGET, String::class)
val target = executionInfoMap[KEY_TARGET] as String
val pkgLocalPath = executionInfoMap[KEY_PACKAGE_PATH] as? String ?: ""
val atomEnvRequest = AtomEnvRequest(
Expand Down Expand Up @@ -536,10 +537,10 @@ class MarketAtomCommonServiceImpl : MarketAtomCommonService {
}


private fun <T> validateTaskJsonField(
private fun <T : Any> validateTaskJsonField(
inputGroupMap: Map<String, Any>,
fieldName: String,
expectedType: Class<T>
expectedType: KClass<T>
) {
val fieldValue = inputGroupMap[fieldName]
if (fieldValue == null || (fieldValue is String && fieldValue.isEmpty())) {
Expand Down Expand Up @@ -572,7 +573,7 @@ class MarketAtomCommonServiceImpl : MarketAtomCommonService {
dataMap.values
.mapNotNull { it as? Map<String, Any> }
.forEach { map ->
validateTaskJsonField(map, KEY_TYPE, String::class.java)
validateTaskJsonField(map, KEY_TYPE, String::class)
val type = map[KEY_TYPE].toString()
if (!isInput && (supportedTypes != null && type !in supportedTypes)) {
throw ErrorCodeException(
Expand Down

0 comments on commit 484b06b

Please sign in to comment.