if (api.getFirewallApiForProject(userProject.get()).list(options).concat().anyMatch(providesIpPermission(ipPermission))) {
// Permission already exists.
return group;
}
FirewallOptions fwOptions = new FirewallOptions();
String uniqueFwName = namingConvention.createWithoutPrefix().uniqueNameForGroup(group.getName());
fwOptions.name(uniqueFwName);
fwOptions.network(group.getUri());
if (!ipPermission.getGroupIds().isEmpty()) {
fwOptions.sourceTags(ipPermission.getGroupIds());
}
if (!ipPermission.getCidrBlocks().isEmpty()) {
fwOptions.sourceRanges(ipPermission.getCidrBlocks());
}
Firewall.Rule.Builder ruleBuilder = Firewall.Rule.builder();
ruleBuilder.IpProtocol(ipPermission.getIpProtocol());
if (ipPermission.getToPort() > 0) {
ruleBuilder.addPortRange(ipPermission.getFromPort(), ipPermission.getToPort());
}
fwOptions.addAllowedRule(ruleBuilder.build());
AtomicReference<Operation> operation = Atomics.newReference(api.getFirewallApiForProject(userProject
.get()).createInNetwork(
uniqueFwName,
group.getUri(),