@Test public void testApplyWithTCP() { IngressRule ruleToConvert = IngressRule.builder() .id("some-id") .account("some-account") .securityGroupName("some-group-name") .protocol(IpProtocol.TCP.toString()) .startPort(10) .endPort(20) .CIDR("0.0.0.0/0") .build(); IngressRuleToIpPermission converter = new IngressRuleToIpPermission(); IpPermission convertedPerm = converter.apply(ruleToConvert); assertEquals(convertedPerm.getIpProtocol(), IpProtocol.fromValue(ruleToConvert.getProtocol())); assertEquals(convertedPerm.getFromPort(), ruleToConvert.getStartPort()); assertEquals(convertedPerm.getToPort(), ruleToConvert.getEndPort()); assertEquals(convertedPerm.getCidrBlocks(), ImmutableSet.of("0.0.0.0/0")); assertEquals(convertedPerm.getTenantIdGroupNamePairs().size(), 1); assertEquals(convertedPerm.getGroupIds().size(), 0); }
@Override public IpPermission apply(IngressRule rule) { IpPermission.Builder builder = IpPermission.builder(); builder.ipProtocol(IpProtocol.fromValue(rule.getProtocol())); builder.fromPort(rule.getStartPort()); builder.toPort(rule.getEndPort()); if (rule.getCIDR() != null) { builder.cidrBlock(rule.getCIDR()); } if (rule.getSecurityGroupName() != null && rule.getAccount() != null) { builder.tenantIdGroupNamePair(rule.getAccount(), rule.getSecurityGroupName()); } return builder.build(); }
IngressRuleToIpPermission implements Function<IngressRule, IpPermission> { @Override public IpPermission apply(IngressRule rule) { IpPermission.Builder builder = IpPermission.builder(); builder.ipProtocol(IpProtocol.fromValue(rule.getProtocol())); builder.fromPort(rule.getStartPort()); builder.toPort(rule.getEndPort()); if (rule.getCIDR() != null) { builder.cidrBlock(rule.getCIDR()); } if (rule.getSecurityGroupName() != null && rule.getAccount() != null) { builder.tenantIdGroupNamePair(rule.getAccount(), rule.getSecurityGroupName()); } return builder.build(); } }
IngressRuleToIpPermission implements Function<IngressRule, IpPermission> { @Override public IpPermission apply(IngressRule rule) { IpPermission.Builder builder = IpPermission.builder(); builder.ipProtocol(IpProtocol.fromValue(rule.getProtocol())); builder.fromPort(rule.getStartPort()); builder.toPort(rule.getEndPort()); if (rule.getCIDR() != null) { builder.cidrBlock(rule.getCIDR()); } if (rule.getSecurityGroupName() != null && rule.getAccount() != null) { builder.tenantIdGroupNamePair(rule.getAccount(), rule.getSecurityGroupName()); } return builder.build(); } IngressRuleToIpPermission(); }
IngressRuleToIpPermission implements Function<IngressRule, IpPermission> { @Override public IpPermission apply(IngressRule rule) { IpPermission.Builder builder = IpPermission.builder(); builder.ipProtocol(IpProtocol.fromValue(rule.getProtocol())); builder.fromPort(rule.getStartPort()); builder.toPort(rule.getEndPort()); if (rule.getCIDR() != null) { builder.cidrBlock(rule.getCIDR()); } if (rule.getSecurityGroupName() != null && rule.getAccount() != null) { builder.tenantIdGroupNamePair(rule.getAccount(), rule.getSecurityGroupName()); } return builder.build(); } IngressRuleToIpPermission(); @Override IpPermission apply(IngressRule rule); }
IngressRuleToIpPermission implements Function<IngressRule, IpPermission> { @Override public IpPermission apply(IngressRule rule) { IpPermission.Builder builder = IpPermission.builder(); builder.ipProtocol(IpProtocol.fromValue(rule.getProtocol())); builder.fromPort(rule.getStartPort()); builder.toPort(rule.getEndPort()); if (rule.getCIDR() != null) { builder.cidrBlock(rule.getCIDR()); } if (rule.getSecurityGroupName() != null && rule.getAccount() != null) { builder.tenantIdGroupNamePair(rule.getAccount(), rule.getSecurityGroupName()); } return builder.build(); } IngressRuleToIpPermission(); @Override IpPermission apply(IngressRule rule);  }