use of com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil.SHARED_PROJECT_ID in project cloudbreak by hortonworks.
the class GcpPlatformResources method securityGroups.
@Override
public CloudSecurityGroups securityGroups(ExtendedCloudCredential cloudCredential, Region region, Map<String, String> filters) throws IOException {
Compute compute = gcpComputeFactory.buildCompute(cloudCredential);
String projectId = gcpStackUtil.getProjectId(cloudCredential);
Map<String, Set<CloudSecurityGroup>> result = new HashMap<>();
FirewallList firewallList = compute.firewalls().list(projectId).execute();
if (firewallList.getItems() != null) {
for (Firewall firewall : firewallList.getItems()) {
Map<String, Object> properties = new HashMap<>();
properties.put("network", getNetworkName(firewall));
CloudSecurityGroup cloudSecurityGroup = new CloudSecurityGroup(firewall.getName(), firewall.getName(), properties);
result.computeIfAbsent(region.value(), k -> new HashSet<>()).add(cloudSecurityGroup);
}
}
if (filters != null) {
String sharedProjectId = filters.get(SHARED_PROJECT_ID);
if (!Strings.isNullOrEmpty(sharedProjectId)) {
try {
FirewallList sharedProjectFirewalls = compute.firewalls().list(sharedProjectId).execute();
if (sharedProjectFirewalls.getItems() != null) {
for (Firewall firewall : sharedProjectFirewalls.getItems()) {
Map<String, Object> properties = new HashMap<>();
properties.put("network", getNetworkName(firewall));
CloudSecurityGroup cloudSecurityGroup = new CloudSecurityGroup(firewall.getName(), firewall.getName(), properties);
result.computeIfAbsent(region.value(), k -> new HashSet<>()).add(cloudSecurityGroup);
}
}
} catch (Exception ex) {
LOGGER.warn(String.format("We can not read the host project with id %s", sharedProjectId));
}
}
}
return new CloudSecurityGroups(result);
}
Aggregations