Skip to content

Commit

Permalink
feature: 白名单IP添加时增加对“执行方式”的判断,如仅开文件分发则在脚本执行中不可选中 #115
Browse files Browse the repository at this point in the history
  • Loading branch information
jsonwan committed Jul 28, 2021
1 parent 13ede7c commit f1b2932
Showing 1 changed file with 46 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -789,19 +789,9 @@ public List<ApplicationHostInfoDTO> getHostInfoById(String username, Long appId,
return hostInfoList;
}

@Override
public List<HostInfoVO> getHostsByIp(
String username,
Long appId,
ActionScopeEnum actionScope,
List<String> checkIpList
) {
log.info("Input=({},{},{})", username, appId, checkIpList);
if (checkIpList == null || checkIpList.isEmpty()) {
return Collections.emptyList();
}
checkIpList = checkIpList.stream().filter(StringUtils::isNotBlank).collect(Collectors.toList());
private List<CloudIPDTO> parseInputCloudIPList(List<String> checkIpList) {
List<CloudIPDTO> inputCloudIPList = new ArrayList<>();
checkIpList = checkIpList.stream().filter(StringUtils::isNotBlank).collect(Collectors.toList());
for (int i = 0; i < checkIpList.size(); i++) {
String ip = checkIpList.get(i);
if (!StringUtils.isBlank(ip)) {
Expand All @@ -821,26 +811,16 @@ public List<HostInfoVO> getHostsByIp(
}
}
}
//1.先查IP白名单中是否存在该IP
List<CloudIPDTO> appWhiteIPList = whiteIPService.listWhiteIP(appId, actionScope);
//生成IP为索引的Map
Map<String, List<CloudIPDTO>> whiteIPMap = new HashMap<>();
appWhiteIPList.forEach(cloudIPDTO -> {
String ip = cloudIPDTO.getIp();
if (whiteIPMap.containsKey(ip)) {
List<CloudIPDTO> list = whiteIPMap.get(ip);
list.add(cloudIPDTO);
whiteIPMap.put(ip, list);
} else {
List<CloudIPDTO> list = new ArrayList<>();
list.add(cloudIPDTO);
whiteIPMap.put(ip, list);
}
});
return inputCloudIPList;
}

private void separateWhiteIP(
List<CloudIPDTO> inputCloudIPList,
List<CloudIPDTO> inputWhiteIPList,
List<CloudIPDTO> inputNotWhiteIPList,
Map<String, List<CloudIPDTO>> whiteIPMap
) {
Set<String> whiteIPSet = whiteIPMap.keySet();
//找出输入IP中的白名单IP
List<CloudIPDTO> inputWhiteIPList = new ArrayList<>();
List<CloudIPDTO> inputNotWhiteIPList = new ArrayList<>();
inputCloudIPList.forEach(cloudIPDTO -> {
String ip = cloudIPDTO.getIp();
Long cloudId = cloudIPDTO.getCloudAreaId();
Expand All @@ -864,6 +844,41 @@ public List<HostInfoVO> getHostsByIp(
inputNotWhiteIPList.add(cloudIPDTO);
}
});
}

@Override
public List<HostInfoVO> getHostsByIp(
String username,
Long appId,
ActionScopeEnum actionScope,
List<String> checkIpList
) {
log.info("Input=({},{},{})", username, appId, checkIpList);
if (checkIpList == null || checkIpList.isEmpty()) {
return Collections.emptyList();
}
List<CloudIPDTO> inputCloudIPList = parseInputCloudIPList(checkIpList);
//1.先查IP白名单中是否存在该IP
List<CloudIPDTO> appWhiteIPList = whiteIPService.listWhiteIP(appId, actionScope);
//生成IP为索引的Map
Map<String, List<CloudIPDTO>> whiteIPMap = new HashMap<>();
appWhiteIPList.forEach(cloudIPDTO -> {
String ip = cloudIPDTO.getIp();
if (whiteIPMap.containsKey(ip)) {
List<CloudIPDTO> list = whiteIPMap.get(ip);
list.add(cloudIPDTO);
whiteIPMap.put(ip, list);
} else {
List<CloudIPDTO> list = new ArrayList<>();
list.add(cloudIPDTO);
whiteIPMap.put(ip, list);
}
});

//找出输入IP中的白名单IP
List<CloudIPDTO> inputWhiteIPList = new ArrayList<>();
List<CloudIPDTO> inputNotWhiteIPList = new ArrayList<>();
separateWhiteIP(inputCloudIPList,inputWhiteIPList,inputNotWhiteIPList,whiteIPMap);
//使用不带业务信息接口查询白名单IP对应的主机详情
//仅根据IP查询,查出后再根据指定云区域过滤
//根据IP查主机(缺少业务信息)本地
Expand Down

0 comments on commit f1b2932

Please sign in to comment.