@Test void overrideSecurityAccessWhenMultipleCidrRangeProvidedThenShouldUpdateTheCidrRanges() { InstanceGroupType gateway = InstanceGroupType.GATEWAY; List<InstanceGroupV4Request> instanceGroups = getInstanceGroups(); String theWholeWorldAndASimpleCidr = "0.0.0.0/0,172.16.0.0/16"; securityAccessManifester.overrideSecurityAccess(gateway, instanceGroups, null, theWholeWorldAndASimpleCidr); assertEquals(2, instanceGroups.get(0).getSecurityGroup().getSecurityRules().size()); assertEquals(List.of(theWholeWorldAndASimpleCidr.split(",")), collectSubnets(instanceGroups)); }
public void overrideSecurityAccess(InstanceGroupType instanceGroupType, List<InstanceGroupV4Request> instanceGroups, String securityGroupId, String cidrs) { instanceGroups.stream() .filter(ig -> ig.getType() == instanceGroupType) .findFirst() .ifPresent(ig -> { SecurityGroupV4Request securityGroup = ig.getSecurityGroup(); if (securityGroup == null) { securityGroup = new SecurityGroupV4Request(); } if (!internalApiCallCalculator.isInternalApiCall(securityGroup)) { if (!Strings.isNullOrEmpty(securityGroupId)) { securityGroup.setSecurityGroupIds(Set.of(securityGroupId)); securityGroup.setSecurityRules(new ArrayList<>()); } else if (!Strings.isNullOrEmpty(cidrs)) { List<SecurityRuleV4Request> generatedSecurityRules = new ArrayList<>(); List<SecurityRuleV4Request> originalSecurityRules = securityGroup.getSecurityRules(); for (String cidr : CidrUtil.cidrs(cidrs)) { SecurityRuleUtil.propagateCidr(generatedSecurityRules, originalSecurityRules, cidr); } if (originalSecurityRules != null) { securityGroup.setSecurityRules(generatedSecurityRules); } securityGroup.setSecurityGroupIds(new HashSet<>()); } else { securityGroup.setSecurityGroupIds(new HashSet<>()); securityGroup.setSecurityRules(new ArrayList<>()); } } }); }
SecurityAccessManifester { public void overrideSecurityAccess(InstanceGroupType instanceGroupType, List<InstanceGroupV4Request> instanceGroups, String securityGroupId, String cidrs) { instanceGroups.stream() .filter(ig -> ig.getType() == instanceGroupType) .findFirst() .ifPresent(ig -> { SecurityGroupV4Request securityGroup = ig.getSecurityGroup(); if (securityGroup == null) { securityGroup = new SecurityGroupV4Request(); } if (!internalApiCallCalculator.isInternalApiCall(securityGroup)) { if (!Strings.isNullOrEmpty(securityGroupId)) { securityGroup.setSecurityGroupIds(Set.of(securityGroupId)); securityGroup.setSecurityRules(new ArrayList<>()); } else if (!Strings.isNullOrEmpty(cidrs)) { List<SecurityRuleV4Request> generatedSecurityRules = new ArrayList<>(); List<SecurityRuleV4Request> originalSecurityRules = securityGroup.getSecurityRules(); for (String cidr : CidrUtil.cidrs(cidrs)) { SecurityRuleUtil.propagateCidr(generatedSecurityRules, originalSecurityRules, cidr); } if (originalSecurityRules != null) { securityGroup.setSecurityRules(generatedSecurityRules); } securityGroup.setSecurityGroupIds(new HashSet<>()); } else { securityGroup.setSecurityGroupIds(new HashSet<>()); securityGroup.setSecurityRules(new ArrayList<>()); } } }); } }
SecurityAccessManifester { public void overrideSecurityAccess(InstanceGroupType instanceGroupType, List<InstanceGroupV4Request> instanceGroups, String securityGroupId, String cidrs) { instanceGroups.stream() .filter(ig -> ig.getType() == instanceGroupType) .findFirst() .ifPresent(ig -> { SecurityGroupV4Request securityGroup = ig.getSecurityGroup(); if (securityGroup == null) { securityGroup = new SecurityGroupV4Request(); } if (!internalApiCallCalculator.isInternalApiCall(securityGroup)) { if (!Strings.isNullOrEmpty(securityGroupId)) { securityGroup.setSecurityGroupIds(Set.of(securityGroupId)); securityGroup.setSecurityRules(new ArrayList<>()); } else if (!Strings.isNullOrEmpty(cidrs)) { List<SecurityRuleV4Request> generatedSecurityRules = new ArrayList<>(); List<SecurityRuleV4Request> originalSecurityRules = securityGroup.getSecurityRules(); for (String cidr : CidrUtil.cidrs(cidrs)) { SecurityRuleUtil.propagateCidr(generatedSecurityRules, originalSecurityRules, cidr); } if (originalSecurityRules != null) { securityGroup.setSecurityRules(generatedSecurityRules); } securityGroup.setSecurityGroupIds(new HashSet<>()); } else { securityGroup.setSecurityGroupIds(new HashSet<>()); securityGroup.setSecurityRules(new ArrayList<>()); } } }); }  }
SecurityAccessManifester { public void overrideSecurityAccess(InstanceGroupType instanceGroupType, List<InstanceGroupV4Request> instanceGroups, String securityGroupId, String cidrs) { instanceGroups.stream() .filter(ig -> ig.getType() == instanceGroupType) .findFirst() .ifPresent(ig -> { SecurityGroupV4Request securityGroup = ig.getSecurityGroup(); if (securityGroup == null) { securityGroup = new SecurityGroupV4Request(); } if (!internalApiCallCalculator.isInternalApiCall(securityGroup)) { if (!Strings.isNullOrEmpty(securityGroupId)) { securityGroup.setSecurityGroupIds(Set.of(securityGroupId)); securityGroup.setSecurityRules(new ArrayList<>()); } else if (!Strings.isNullOrEmpty(cidrs)) { List<SecurityRuleV4Request> generatedSecurityRules = new ArrayList<>(); List<SecurityRuleV4Request> originalSecurityRules = securityGroup.getSecurityRules(); for (String cidr : CidrUtil.cidrs(cidrs)) { SecurityRuleUtil.propagateCidr(generatedSecurityRules, originalSecurityRules, cidr); } if (originalSecurityRules != null) { securityGroup.setSecurityRules(generatedSecurityRules); } securityGroup.setSecurityGroupIds(new HashSet<>()); } else { securityGroup.setSecurityGroupIds(new HashSet<>()); securityGroup.setSecurityRules(new ArrayList<>()); } } }); }  void overrideSecurityAccess(InstanceGroupType instanceGroupType, List<InstanceGroupV4Request> instanceGroups, String securityGroupId, String cidrs); }
SecurityAccessManifester { public void overrideSecurityAccess(InstanceGroupType instanceGroupType, List<InstanceGroupV4Request> instanceGroups, String securityGroupId, String cidrs) { instanceGroups.stream() .filter(ig -> ig.getType() == instanceGroupType) .findFirst() .ifPresent(ig -> { SecurityGroupV4Request securityGroup = ig.getSecurityGroup(); if (securityGroup == null) { securityGroup = new SecurityGroupV4Request(); } if (!internalApiCallCalculator.isInternalApiCall(securityGroup)) { if (!Strings.isNullOrEmpty(securityGroupId)) { securityGroup.setSecurityGroupIds(Set.of(securityGroupId)); securityGroup.setSecurityRules(new ArrayList<>()); } else if (!Strings.isNullOrEmpty(cidrs)) { List<SecurityRuleV4Request> generatedSecurityRules = new ArrayList<>(); List<SecurityRuleV4Request> originalSecurityRules = securityGroup.getSecurityRules(); for (String cidr : CidrUtil.cidrs(cidrs)) { SecurityRuleUtil.propagateCidr(generatedSecurityRules, originalSecurityRules, cidr); } if (originalSecurityRules != null) { securityGroup.setSecurityRules(generatedSecurityRules); } securityGroup.setSecurityGroupIds(new HashSet<>()); } else { securityGroup.setSecurityGroupIds(new HashSet<>()); securityGroup.setSecurityRules(new ArrayList<>()); } } }); }  void overrideSecurityAccess(InstanceGroupType instanceGroupType, List<InstanceGroupV4Request> instanceGroups, String securityGroupId, String cidrs);  }