[collector,manager]监控密钥加密传输,radio入参校验
This commit is contained in:
@@ -10,6 +10,9 @@ import com.usthe.collector.util.SpringContextHolder;
|
|||||||
import com.usthe.common.entity.job.Configmap;
|
import com.usthe.common.entity.job.Configmap;
|
||||||
import com.usthe.common.entity.job.Job;
|
import com.usthe.common.entity.job.Job;
|
||||||
import com.usthe.common.entity.job.Metrics;
|
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.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@@ -22,6 +25,7 @@ import java.util.stream.Collectors;
|
|||||||
* @author tomsun28
|
* @author tomsun28
|
||||||
* @date 2021/11/1 17:18
|
* @date 2021/11/1 17:18
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public class WheelTimerTask implements TimerTask {
|
public class WheelTimerTask implements TimerTask {
|
||||||
|
|
||||||
private final Job job;
|
private final Job job;
|
||||||
@@ -42,7 +46,18 @@ public class WheelTimerTask implements TimerTask {
|
|||||||
private void initJobMetrics(Job job) {
|
private void initJobMetrics(Job job) {
|
||||||
// 将监控实际参数值对采集字段进行替换
|
// 将监控实际参数值对采集字段进行替换
|
||||||
List<Configmap> config = job.getConfigmap();
|
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> metrics = job.getMetrics();
|
||||||
List<Metrics> metricsTmp = new ArrayList<>(metrics.size());
|
List<Metrics> metricsTmp = new ArrayList<>(metrics.size());
|
||||||
for (Metrics metric : metrics) {
|
for (Metrics metric : metrics) {
|
||||||
|
|||||||
@@ -131,10 +131,10 @@ public class MonitorServiceImpl implements MonitorService {
|
|||||||
for (ParamDefine paramDefine : paramDefines) {
|
for (ParamDefine paramDefine : paramDefines) {
|
||||||
String field = paramDefine.getField();
|
String field = paramDefine.getField();
|
||||||
Param param = paramMap.get(field);
|
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.");
|
throw new IllegalArgumentException("Params field " + field + " is required.");
|
||||||
}
|
}
|
||||||
if (param != null) {
|
if (param != null && param.getValue() != null && !"".equals(param.getValue())) {
|
||||||
switch (paramDefine.getType()) {
|
switch (paramDefine.getType()) {
|
||||||
case "number":
|
case "number":
|
||||||
double doubleValue;
|
double doubleValue;
|
||||||
@@ -151,6 +151,7 @@ public class MonitorServiceImpl implements MonitorService {
|
|||||||
+ paramDefine.getType() + " over range " + paramDefine.getRange());
|
+ paramDefine.getType() + " over range " + paramDefine.getRange());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
param.setType(CommonConstants.PARAM_TYPE_NUMBER);
|
||||||
break;
|
break;
|
||||||
case "text":
|
case "text":
|
||||||
Short limit = paramDefine.getLimit();
|
Short limit = paramDefine.getLimit();
|
||||||
@@ -175,6 +176,7 @@ public class MonitorServiceImpl implements MonitorService {
|
|||||||
passwordValue = AesUtil.aesEncode(passwordValue);
|
passwordValue = AesUtil.aesEncode(passwordValue);
|
||||||
param.setValue(passwordValue);
|
param.setValue(passwordValue);
|
||||||
}
|
}
|
||||||
|
param.setType(CommonConstants.PARAM_TYPE_PASSWORD);
|
||||||
break;
|
break;
|
||||||
case "boolean":
|
case "boolean":
|
||||||
// boolean校验
|
// boolean校验
|
||||||
@@ -187,7 +189,21 @@ public class MonitorServiceImpl implements MonitorService {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "radio":
|
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;
|
break;
|
||||||
case "checkbox":
|
case "checkbox":
|
||||||
// todo checkbox校验
|
// todo checkbox校验
|
||||||
|
|||||||
Reference in New Issue
Block a user