From 7b93ae4ce916eb07a1e405147b0e4a643831717a Mon Sep 17 00:00:00 2001 From: jihyungSong Date: Mon, 7 Aug 2023 16:32:45 +0900 Subject: [PATCH] fix: modify filter for describe vpc peering connection --- .../aws_rds_connector/schema/service_type.py | 3 +-- .../connector/aws_vpc_connector/connector.py | 22 ++++++++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/spaceone/inventory/connector/aws_rds_connector/schema/service_type.py b/src/spaceone/inventory/connector/aws_rds_connector/schema/service_type.py index 28f821d4..4ce6383b 100644 --- a/src/spaceone/inventory/connector/aws_rds_connector/schema/service_type.py +++ b/src/spaceone/inventory/connector/aws_rds_connector/schema/service_type.py @@ -1,8 +1,7 @@ import os from spaceone.inventory.libs.common_parser import * from spaceone.inventory.libs.schema.dynamic_widget import ChartWidget, CardWidget -from spaceone.inventory.libs.schema.dynamic_field import TextDyField, DateTimeDyField, EnumDyField, \ - BadgeDyField, SearchField, ListDyField +from spaceone.inventory.libs.schema.dynamic_field import TextDyField, DateTimeDyField, EnumDyField, SearchField, ListDyField from spaceone.inventory.libs.schema.resource import CloudServiceTypeResource, CloudServiceTypeResponse, CloudServiceTypeMeta from spaceone.inventory.conf.cloud_service_conf import * diff --git a/src/spaceone/inventory/connector/aws_vpc_connector/connector.py b/src/spaceone/inventory/connector/aws_vpc_connector/connector.py index 6983121a..4cb15948 100644 --- a/src/spaceone/inventory/connector/aws_vpc_connector/connector.py +++ b/src/spaceone/inventory/connector/aws_vpc_connector/connector.py @@ -240,16 +240,27 @@ def describe_vpc_attribute(self, vpc_id, attribute): def request_peering_connection_data(self, region_name): self.cloud_service_type = 'PeeringConnection' cloudtrail_resource_type = 'AWS::EC2::VPCPeeringConnection' + vpc_peering_connections = [] - response = {} if self.include_default: response = self.client.describe_vpc_peering_connections() + vpc_peering_connections = response.get('VpcPeeringConnections', []) elif len(self.vpc_ids) > 0: - _filters = [{'Name': 'accepter-vpc-info.vpc-id', 'Values': self.vpc_ids}, - {'Name': 'requester-vpc-info.vpc-id', 'Values': self.vpc_ids}] - response = self.client.describe_vpc_peering_connections(Filters=_filters) + accepter_response = self.client.describe_vpc_peering_connections( + Filters=[{'Name': 'accepter-vpc-info.vpc-id', 'Values': self.vpc_ids}]) + + vpc_peering_connections = accepter_response.get('VpcPeeringConnections', []) + peerx_ids = [_peerx.get('VpcPeeringConnectionId') for _peerx in + accepter_response.get('VpcPeeringConnections', []) ] + + requester_response = self.client.describe_vpc_peering_connections( + Filters=[{'Name': 'requester-vpc-info.vpc-id', 'Values': self.vpc_ids}]) - for peerx in response.get('VpcPeeringConnections', []): + for _peerx in requester_response.get('VpcPeeringConnections', []): + if _peerx.get('VpcPeeringConnectionId') not in peerx_ids: + vpc_peering_connections.append(_peerx) + + for peerx in vpc_peering_connections: try: peerx.update({ 'arn': self.generate_arn(service=self.service_name, region=region_name, account_id=self.account_id, @@ -682,7 +693,6 @@ def request_vpn_connection_data(self, region_name): cloudtrail_resource_type = 'AWS::EC2::VPNConnection' response = self.client.describe_vpn_connections() - for vpn_connection in response.get('VpnConnections', []): try: vpn_connection.update({