From 12e2e2381a9f94a7c286a4116299aeed366ab951 Mon Sep 17 00:00:00 2001 From: Kyle Thorne Date: Wed, 21 Jul 2021 21:04:23 +1000 Subject: [PATCH 1/2] Added workaround for https://github.com/boto/boto3/issues/2498 --- lib/services/vpn_tunnels.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/services/vpn_tunnels.py b/lib/services/vpn_tunnels.py index 7fc624a..0e6cac3 100644 --- a/lib/services/vpn_tunnels.py +++ b/lib/services/vpn_tunnels.py @@ -20,11 +20,21 @@ def get_resources(self): if 'VpnConnections' in page: connections = [item for item in page['VpnConnections']] for connection in connections: - for tunnel in connection['Options']['TunnelOptions']: + try: + for tunnel in connection['Options']['TunnelOptions']: - self.identifiers.extend([{ - 'id': tunnel['OutsideIpAddress'], - 'tags': connection['Tags'] + self.identifiers.extend([{ + 'id': tunnel['OutsideIpAddress'], + 'tags': str(connection['Tags']) + }]) + except KeyError: + import xml.etree.ElementTree as ET + tree = ET.ElementTree(ET.fromstring(connection['CustomerGatewayConfiguration'])) + root = tree.getroot() + ips = root.findall("tunnel_outside_address") + for i in ips: + self.identifiers.extend([{ + 'id': i }]) except Exception as e: From 903a780e8b805f50b944d3086fc358b330180f3f Mon Sep 17 00:00:00 2001 From: Kyle Thorne Date: Wed, 21 Jul 2021 21:04:54 +1000 Subject: [PATCH 2/2] Added fix for ECS services without tags --- lib/services/ecs_services.py | 47 +++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/lib/services/ecs_services.py b/lib/services/ecs_services.py index a0f64c4..d934b8b 100644 --- a/lib/services/ecs_services.py +++ b/lib/services/ecs_services.py @@ -38,21 +38,40 @@ def get_resources(self): split = lambda lst, sz: [lst[i:i+sz] for i in range(0, len(lst), sz)] splitServiceArns = split(serviceArns, 10) for array in splitServiceArns: - self.identifiers.extend({ - 'id': { - 'ServiceName': item['serviceName'], - 'Cluster': clusterName - }, - 'tags': item['tags'] - } for item in client.describe_services(cluster=clusterName, services=array, include=['TAGS'])['services']) + try: + self.identifiers.extend({ + 'id': { + 'ServiceName': item['serviceName'], + 'Cluster': clusterName + }, + 'tags': item['tags'] + } for item in client.describe_services(cluster=clusterName, services=array, include=['TAGS'])['services']) + except KeyError: + self.identifiers.extend({ + 'id': { + 'ServiceName': item['serviceName'], + 'Cluster': clusterName + }, + 'tags': '' + } for item in client.describe_services(cluster=clusterName, services=array)['services']) else: - self.identifiers.extend({ - 'id': { - 'ServiceName': item['serviceName'], - 'Cluster': clusterName - }, - 'tags': item['tags'] - } for item in client.describe_services(cluster=clusterName, services=serviceArns, include=['TAGS'])['services']) + try: + self.identifiers.extend({ + 'id': { + 'ServiceName': item['serviceName'], + 'Cluster': clusterName + }, + 'tags': item['tags'] + } for item in client.describe_services(cluster=clusterName, services=serviceArns, include=['TAGS'])['services']) + except KeyError: + self.identifiers.extend({ + 'id': { + 'ServiceName': item['serviceName'], + 'Cluster': clusterName + }, + 'tags': '' + } for item in client.describe_services(cluster=clusterName, services=serviceArns)['services']) + except Exception as e: print('ERROR'.ljust(7) + self.region.ljust(16) + self.name.ljust(19) + str(e), flush=True)