use of com.microsoft.azure.management.network.SecurityRuleProtocol in project photon-model by vmware.
the class AzureSecurityGroupUtils method buildSecurityRule.
private static SecurityRuleInner buildSecurityRule(Rule rule, SecurityRuleDirection direction, int priority) {
SecurityRuleInner sr = new SecurityRuleInner();
sr.withPriority(priority);
sr.withAccess(rule.access == Access.Allow ? SecurityRuleAccess.ALLOW : SecurityRuleAccess.DENY);
sr.withDirection(direction);
String addressPrefix = rule.ipRangeCidr.equals(ANY_RANGE) ? SecurityGroupService.ANY : rule.ipRangeCidr;
String portRange = rule.ports.equals(SecurityGroupService.ALL_PORTS) ? SecurityGroupService.ANY : rule.ports;
sr.withName(rule.name);
sr.withProtocol(rule.protocol.equals(ALL_TRAFFIC) ? SecurityRuleProtocol.ASTERISK : new SecurityRuleProtocol(rule.protocol));
if (SecurityRuleDirection.INBOUND.equals(direction)) {
sr.withSourceAddressPrefix(addressPrefix);
sr.withDestinationAddressPrefix(SecurityGroupService.ANY);
sr.withSourcePortRange(portRange);
sr.withDestinationPortRange(SecurityGroupService.ANY);
} else {
sr.withSourceAddressPrefix(SecurityGroupService.ANY);
sr.withDestinationAddressPrefix(addressPrefix);
sr.withSourcePortRange(SecurityGroupService.ANY);
sr.withDestinationPortRange(portRange);
}
return sr;
}
use of com.microsoft.azure.management.network.SecurityRuleProtocol in project photon-model by vmware.
the class AzureLoadBalancerService method updateSecurityRules.
/**
* Build a list of Security group firewall rules to allow traffic through load balancer routes
*
* @param context Azure load balancer context
*/
private void updateSecurityRules(AzureLoadBalancerContext context) {
List<SecurityRuleInner> securityRuleInnerList = Lists.newArrayList();
final AtomicInteger priority = new AtomicInteger(2000);
context.loadBalancerAzure.loadBalancingRules().forEach(loadBalancingRuleInner -> {
SecurityRuleInner securityRuleInner = new SecurityRuleInner();
securityRuleInner.withName(String.format("%s-sg-rule", loadBalancingRuleInner.name()));
securityRuleInner.withDirection(SecurityRuleDirection.INBOUND);
securityRuleInner.withAccess(SecurityRuleAccess.ALLOW);
securityRuleInner.withPriority(priority.getAndIncrement());
securityRuleInner.withProtocol(new SecurityRuleProtocol(loadBalancingRuleInner.protocol().toString()));
securityRuleInner.withSourcePortRange(SecurityGroupService.ANY);
securityRuleInner.withSourceAddressPrefix(SecurityGroupService.ANY);
securityRuleInner.withDestinationPortRange(Integer.toString(loadBalancingRuleInner.backendPort()));
// Azure API expects destination address prefix to be set even if we are using
// destination address prefixes
securityRuleInner.withDestinationAddressPrefix(getDestinationAddressPrefix(context));
// TODO this should be fixed once Azure API version is updates
// securityRuleInner.withDestinationAddressPrefixes(getDestinationAddressPrefixes
// (context));
securityRuleInnerList.add(securityRuleInner);
});
// update rules
context.securityGroupInners.forEach(securityGroupInner -> {
if (securityGroupInner != null) {
securityGroupInner.securityRules().addAll(securityRuleInnerList);
securityGroupInner.withSecurityRules(securityGroupInner.securityRules());
}
});
}
Aggregations