From 9e5c9a0f13fb531cbcb5f19511582d38f6892ba9 Mon Sep 17 00:00:00 2001 From: Ananda Bhattacharya Date: Mon, 2 Aug 2021 14:10:43 -0700 Subject: [PATCH] Add support for ipv6 addresses Remove formating changes --- plugins/lookup/aws_service_ip_ranges.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/lookup/aws_service_ip_ranges.py b/plugins/lookup/aws_service_ip_ranges.py index b8bfd4ee501..a96a6dc0012 100644 --- a/plugins/lookup/aws_service_ip_ranges.py +++ b/plugins/lookup/aws_service_ip_ranges.py @@ -19,6 +19,8 @@ description: 'The service to filter ranges by. Options: EC2, S3, CLOUDFRONT, CODEbUILD, ROUTE53, ROUTE53_HEALTHCHECKS' region: description: 'The AWS region to narrow the ranges to. Examples: us-east-1, eu-west-2, ap-southeast-1' + ipv6_prefix: + description: 'Return only ipv6 addresses. Option: ipv6_prefix=True' ''' EXAMPLES = """ @@ -55,9 +57,16 @@ class LookupModule(LookupBase): def run(self, terms, variables, **kwargs): + if "ipv6_prefix" in kwargs["ipv6_prefix"] is False: + prefixes_label = "prefixes" + ip_prefix_label = "ip_prefix" + else: + prefixes_label = "ipv6_prefixes" + ip_prefix_label = "ipv6_prefix" + try: resp = open_url('https://ip-ranges.amazonaws.com/ip-ranges.json') - amazon_response = json.load(resp)['prefixes'] + amazon_response = json.load(resp)[prefixes_label] except getattr(json.decoder, 'JSONDecodeError', ValueError) as e: # on Python 3+, json.decoder.JSONDecodeError is raised for bad # JSON. On 2.x it's a ValueError @@ -78,4 +87,4 @@ def run(self, terms, variables, **kwargs): service = str.upper(kwargs['service']) amazon_response = (item for item in amazon_response if item['service'] == service) - return [item['ip_prefix'] for item in amazon_response] + return [item[ip_prefix_label] for item in amazon_response]