[collector,manager]监控密钥加密传输,radio入参校验

This commit is contained in:
tomsun28
2022-01-30 13:00:12 +08:00
parent 34458bf468
commit d055446f98
2 changed files with 35 additions and 4 deletions

View File

@@ -10,6 +10,9 @@ import com.usthe.collector.util.SpringContextHolder;
import com.usthe.common.entity.job.Configmap;
import com.usthe.common.entity.job.Job;
import com.usthe.common.entity.job.Metrics;
import com.usthe.common.util.AesUtil;
import com.usthe.common.util.CommonConstants;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.Iterator;
@@ -22,6 +25,7 @@ import java.util.stream.Collectors;
* @author tomsun28
* @date 2021/11/1 17:18
*/
@Slf4j
public class WheelTimerTask implements TimerTask {
private final Job job;
@@ -42,7 +46,18 @@ public class WheelTimerTask implements TimerTask {
private void initJobMetrics(Job job) {
// 将监控实际参数值对采集字段进行替换
List<Configmap> config = job.getConfigmap();
Map<String, Configmap> configmap = config.stream().collect(Collectors.toMap(Configmap::getKey, item -> item));
Map<String, Configmap> configmap = config.stream()
.peek(item -> {
// 对加密串进行解密
if (item.getType() == CommonConstants.PARAM_TYPE_PASSWORD && item.getValue() != null) {
String decodeValue = AesUtil.aesDecode(String.valueOf(item.getValue()));
if (decodeValue == null) {
log.error("Aes Decode value {} error.", item.getValue());
}
item.setValue(decodeValue);
}
})
.collect(Collectors.toMap(Configmap::getKey, item -> item));
List<Metrics> metrics = job.getMetrics();
List<Metrics> metricsTmp = new ArrayList<>(metrics.size());
for (Metrics metric : metrics) {

View File

@@ -131,10 +131,10 @@ public class MonitorServiceImpl implements MonitorService {
for (ParamDefine paramDefine : paramDefines) {
String field = paramDefine.getField();
Param param = paramMap.get(field);
if (paramDefine.isRequired() && param == null) {
if (paramDefine.isRequired() && (param == null || param.getValue() == null)) {
throw new IllegalArgumentException("Params field " + field + " is required.");
}
if (param != null) {
if (param != null && param.getValue() != null && !"".equals(param.getValue())) {
switch (paramDefine.getType()) {
case "number":
double doubleValue;
@@ -151,6 +151,7 @@ public class MonitorServiceImpl implements MonitorService {
+ paramDefine.getType() + " over range " + paramDefine.getRange());
}
}
param.setType(CommonConstants.PARAM_TYPE_NUMBER);
break;
case "text":
Short limit = paramDefine.getLimit();
@@ -175,6 +176,7 @@ public class MonitorServiceImpl implements MonitorService {
passwordValue = AesUtil.aesEncode(passwordValue);
param.setValue(passwordValue);
}
param.setType(CommonConstants.PARAM_TYPE_PASSWORD);
break;
case "boolean":
// boolean校验
@@ -187,7 +189,21 @@ public class MonitorServiceImpl implements MonitorService {
}
break;
case "radio":
// todo radio校验
// radio单选值校验
List<ParamDefine.Option> options = paramDefine.getOptions();
boolean invalid = true;
if (options != null) {
for (ParamDefine.Option option : options) {
if (param.getValue().equalsIgnoreCase(option.getValue())) {
invalid = false;
break;
}
}
}
if (invalid) {
throw new IllegalArgumentException("Params field " + field + " value "
+ param.getValue() + " is invalid option value");
}
break;
case "checkbox":
// todo checkbox校验