use of com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup in project cloudbreak by hortonworks.
the class AwsPlatformResources method securityGroups.
@Override
public CloudSecurityGroups securityGroups(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
Map<String, Set<CloudSecurityGroup>> result = new HashMap<>();
Set<CloudSecurityGroup> cloudSecurityGroups = new HashSet<>();
AmazonEC2Client ec2Client = awsClient.createAccess(new AwsCredentialView(cloudCredential), region.value());
// create securitygroup filter view
PlatformResourceSecurityGroupFilterView filter = new PlatformResourceSecurityGroupFilterView(filters);
DescribeSecurityGroupsRequest describeSecurityGroupsRequest = new DescribeSecurityGroupsRequest();
// If the filtervalue is provided then we should filter only for those securitygroups
if (!Strings.isNullOrEmpty(filter.getVpcId())) {
describeSecurityGroupsRequest.withFilters(new Filter("vpc-id", singletonList(filter.getVpcId())));
}
if (!Strings.isNullOrEmpty(filter.getGroupId())) {
describeSecurityGroupsRequest.withGroupIds(filter.getGroupId());
}
if (!Strings.isNullOrEmpty(filter.getGroupName())) {
describeSecurityGroupsRequest.withGroupNames(filter.getGroupName());
}
for (SecurityGroup securityGroup : ec2Client.describeSecurityGroups(describeSecurityGroupsRequest).getSecurityGroups()) {
Map<String, Object> properties = new HashMap<>();
properties.put("vpcId", securityGroup.getVpcId());
properties.put("description", securityGroup.getDescription());
properties.put("ipPermissions", securityGroup.getIpPermissions());
properties.put("ipPermissionsEgress", securityGroup.getIpPermissionsEgress());
cloudSecurityGroups.add(new CloudSecurityGroup(securityGroup.getGroupName(), securityGroup.getGroupId(), properties));
}
result.put(region.value(), cloudSecurityGroups);
return new CloudSecurityGroups(result);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup in project cloudbreak by hortonworks.
the class CloudSecurityGroupsToPlatformSecurityGroupsResponseConverter method convert.
@Override
public PlatformSecurityGroupsResponse convert(CloudSecurityGroups source) {
Map<String, Set<PlatformSecurityGroupResponse>> result = new HashMap<>();
for (Entry<String, Set<CloudSecurityGroup>> entry : source.getCloudSecurityGroupsResponses().entrySet()) {
Set<PlatformSecurityGroupResponse> securityGroupResponses = new HashSet<>();
for (CloudSecurityGroup securityGroup : entry.getValue()) {
PlatformSecurityGroupResponse actual = new PlatformSecurityGroupResponse(securityGroup.getGroupName(), securityGroup.getGroupId(), securityGroup.getProperties());
securityGroupResponses.add(actual);
}
result.put(entry.getKey(), securityGroupResponses);
}
return new PlatformSecurityGroupsResponse(result);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup in project cloudbreak by hortonworks.
the class GcpPlatformResources method securityGroups.
@Override
public CloudSecurityGroups securityGroups(CloudCredential cloudCredential, Region region, Map<String, String> filters) throws IOException {
Compute compute = GcpStackUtil.buildCompute(cloudCredential);
String projectId = GcpStackUtil.getProjectId(cloudCredential);
Map<String, Set<CloudSecurityGroup>> result = new HashMap<>();
if (compute != null) {
FirewallList firewallList = compute.firewalls().list(projectId).execute();
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);
}
}
return new CloudSecurityGroups(result);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup in project cloudbreak by hortonworks.
the class OpenStackPlatformResources method securityGroups.
@Override
public CloudSecurityGroups securityGroups(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
OSClient<?> osClient = openStackClient.createOSClient(cloudCredential);
KeystoneCredentialView osCredential = openStackClient.createKeystoneCredential(cloudCredential);
Set<CloudSecurityGroup> cloudSecurityGroups = new HashSet<>();
List<? extends SecGroupExtension> osSecurityGroups = osClient.compute().securityGroups().list();
LOGGER.info("security groups from openstack: {}", osSecurityGroups);
for (SecGroupExtension secGroup : osSecurityGroups) {
Map<String, Object> properties = new HashMap<>();
properties.put("tenantId", secGroup.getTenantId());
properties.put("rules", secGroup.getRules());
CloudSecurityGroup cloudSecurityGroup = new CloudSecurityGroup(secGroup.getName(), secGroup.getId(), properties);
cloudSecurityGroups.add(cloudSecurityGroup);
}
Map<String, Set<CloudSecurityGroup>> result = new HashMap<>();
result.put(region.value() == null ? osCredential.getTenantName() : region.value(), cloudSecurityGroups);
LOGGER.info("openstack security groups result: {}", result);
return new CloudSecurityGroups(result);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup in project cloudbreak by hortonworks.
the class AzurePlatformResources method securityGroups.
@Override
public CloudSecurityGroups securityGroups(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
AzureClient client = azureClientService.getClient(cloudCredential);
Map<String, Set<CloudSecurityGroup>> result = new HashMap<>();
for (NetworkSecurityGroup securityGroup : client.getSecurityGroups().list()) {
String actualRegion = securityGroup.region().label();
if (regionMatch(actualRegion, region)) {
Map<String, Object> properties = new HashMap<>();
properties.put("resourceGroupName", securityGroup.resourceGroupName());
properties.put("networkInterfaceIds", securityGroup.networkInterfaceIds());
CloudSecurityGroup cloudSecurityGroup = new CloudSecurityGroup(securityGroup.name(), securityGroup.id(), properties);
result.computeIfAbsent(actualRegion, s -> new HashSet<>()).add(cloudSecurityGroup);
}
}
if (result.isEmpty() && Objects.nonNull(region)) {
result.put(region.value(), new HashSet<>());
}
return new CloudSecurityGroups(result);
}
Aggregations