@Override public boolean apply(IngressRule rule) { return protocol.equals(rule.getProtocol()) && startPort == rule.getStartPort() && endPort == rule.getEndPort() && cidrs.contains(rule.getCIDR()); }
@Override public boolean apply(IngressRule rule) { return protocol.equals(rule.getProtocol()) && startPort == rule.getStartPort() && endPort == rule.getEndPort() && accountGroupNames.containsEntry(rule.getAccount(), rule.getSecurityGroupName()); }
@Override public Rule apply(IngressRule input) { Rule rule; if (input.getProtocol().equalsIgnoreCase("icmp")) { rule = Rule.builder() .anySource() .protocol(Protocol.valueOf(input.getProtocol().toUpperCase())) .cidr(input.getCIDR()) .createRule(); } else { rule = Rule.builder() .anySource() .protocol(Protocol.valueOf(input.getProtocol().toUpperCase())) .ports(input.getStartPort(), input.getEndPort()) .cidr(input.getCIDR()) .createRule(); } return rule; } }
@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); } }
public T fromIngressRule(IngressRule in) { return this .account(in.getAccount()) .CIDR(in.getCIDR()) .endPort(in.getEndPort()) .ICMPCode(in.getICMPCode()) .ICMPType(in.getICMPType()) .protocol(in.getProtocol()) .id(in.getId()) .securityGroupName(in.getSecurityGroupName()) .startPort(in.getStartPort()); } }
assert ICMPPingRule.getStartPort() == -1 : ICMPPingRule; assert ICMPPingRule.getEndPort() == -1 : ICMPPingRule; assert ICMPPingRule.getICMPCode() == 0 : ICMPPingRule; assert SSHRule.getStartPort() == 22 : SSHRule; assert SSHRule.getEndPort() == 22 : SSHRule; assert SSHRule.getICMPCode() == -1 : SSHRule;
@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(); } }
public T fromIngressRule(IngressRule in) { return this .account(in.getAccount()) .CIDR(in.getCIDR()) .endPort(in.getEndPort()) .ICMPCode(in.getICMPCode()) .ICMPType(in.getICMPType()) .protocol(in.getProtocol()) .id(in.getId()) .securityGroupName(in.getSecurityGroupName()) .startPort(in.getStartPort()); } }
assert ICMPPingRule.getStartPort() == -1 : ICMPPingRule; assert ICMPPingRule.getEndPort() == -1 : ICMPPingRule; assert ICMPPingRule.getICMPCode() == 0 : ICMPPingRule; assert SSHRule.getStartPort() == 22 : SSHRule; assert SSHRule.getEndPort() == 22 : SSHRule; assert SSHRule.getICMPCode() == -1 : SSHRule;
public T fromIngressRule(IngressRule in) { return this .account(in.getAccount()) .CIDR(in.getCIDR()) .endPort(in.getEndPort()) .ICMPCode(in.getICMPCode()) .ICMPType(in.getICMPType()) .protocol(in.getProtocol()) .id(in.getId()) .securityGroupName(in.getSecurityGroupName()) .startPort(in.getStartPort()) .tags(in.getTags()); } }