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

Add verification for String app. And checkbox and key-value verification #831

Merged
merged 5 commits into from
Apr 2, 2023
Merged
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 @@ -69,7 +69,7 @@ public class AppServiceImpl implements AppService, CommandLineRunner {

@Override
public List<ParamDefine> getAppParamDefines(String app) {
if (app == null) {
if (app == null || app.chars().allMatch(Character::isSpaceChar)) {
return Collections.emptyList();
}
Job appDefine = appDefines.get(app.toLowerCase());
Expand All @@ -82,7 +82,7 @@ public List<ParamDefine> getAppParamDefines(String app) {

@Override
public Job getAppDefine(String app) throws IllegalArgumentException {
if (app == null) {
if (app == null || app.chars().allMatch(Character::isSpaceChar)) {
throw new IllegalArgumentException("The app can not null.");
}
Job appDefine = appDefines.get(app.toLowerCase());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@
import org.dromara.hertzbeat.common.entity.job.Metrics;
import org.dromara.hertzbeat.common.entity.manager.Tag;
import org.dromara.hertzbeat.common.entity.message.CollectRep;
import org.dromara.hertzbeat.common.util.AesUtil;
import org.dromara.hertzbeat.common.util.CommonConstants;
import org.dromara.hertzbeat.common.util.IntervalExpressionUtil;
import org.dromara.hertzbeat.common.util.IpDomainUtil;
import org.dromara.hertzbeat.common.util.SnowFlakeIdGenerator;
import org.dromara.hertzbeat.common.util.*;
import org.dromara.hertzbeat.manager.dao.MonitorDao;
import org.dromara.hertzbeat.manager.dao.ParamDao;
import org.dromara.hertzbeat.manager.pojo.dto.AppCount;
Expand All @@ -50,6 +46,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.InvalidMimeTypeException;

import java.time.LocalDateTime;
import java.util.*;
Expand Down Expand Up @@ -332,10 +329,28 @@ public void validate(MonitorDto monitorDto, Boolean isModify) throws IllegalArgu
}
break;
case "checkbox":
// todo checkbox校验
List<ParamDefine.Option> checkboxOptions = paramDefine.getOptions();
boolean checkboxInvalid = true;
if (checkboxOptions != null) {
for (ParamDefine.Option option : checkboxOptions) {
if (param.getValue().equalsIgnoreCase(option.getValue())) {
checkboxInvalid = false;
break;
}
}
}
if (checkboxInvalid){
throw new IllegalArgumentException("Params field " + field + " value "
+ param.getValue() + " is invalid checkbox value");
}
break;
case "key-value":
// todo key-value校验
try{
GsonUtil.toJson(param.getValue());
} catch (Exception e){
throw new IllegalArgumentException("Params field " + field + " value "
+ param.getValue() + " is invalid key-value value");
}
break;
// todo More parameter definitions and actual value format verification
// 更多参数定义与实际值格式校验
Expand Down