in filter_aws.py [0:0]
def execute(self, listing, response):
"""Apply filter.
Args:
listing: data returned from aws api.
response: relevant data returned to caller.
"""
if listing.service == 'ec2' and listing.operation == 'DescribeInternetGateways':
vpcs_file = '{}_{}_{}_{}.json'.format(listing.service, 'DescribeVpcs',
listing.region, listing.profile)
vpcs_file = self.directory + vpcs_file
vpcs_listing = listing.from_json(json.load(open(vpcs_file, 'rb')))
describe_vpcs = vpcs_listing.response
vpcs = {v['VpcId']: v for v in describe_vpcs.get('Vpcs', [])}
internet_gateways = []
for ig in response['InternetGateways']:
attachments = ig.get('Attachments', [])
if len(attachments) != 1:
continue
vpc = attachments[0].get('VpcId')
if not vpcs.get(vpc, {}).get('IsDefault', False):
internet_gateways.append(ig)
response['InternetGateways'] = internet_gateways