Skip to content

Commit

Permalink
Add verification for String app. And checkbox and key-value verificat…
Browse files Browse the repository at this point in the history
…ion (#831)

  [chore] checkbox and key-value verification

  [refactor] Add verification for String app

  [chore] checkbox and key-value verification

  [fix] UT fail

---------

Co-authored-by: Carpe-Wang <wangcarpe@126.com>
  • Loading branch information
Carpe-Wang and Carpe-Wang authored Apr 2, 2023
1 parent 9af5267 commit a62da9c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
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

0 comments on commit a62da9c

Please sign in to comment.