Skip to content

Commit

Permalink
Merge branch 'allow-ipv6-ipranges' of github.com:abhattacharyaNS1/ama…
Browse files Browse the repository at this point in the history
…zon.aws into allow-ipv6-ipranges
  • Loading branch information
abhattacharyaNS1 committed Sep 10, 2021
2 parents 2174a21 + c303d6b commit dfc105a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions plugins/lookup/aws_service_ip_ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@
"""

import json
try:
import netaddr
except ImportError as imp_exc:
NETADDR_LIBRARY_IMPORT_ERROR = imp_exc
else:
NETADDR_LIBRARY_IMPORT_ERROR = None

from ansible.module_utils.six import raise_from
from ansible.errors import AnsibleError
from ansible.module_utils.six.moves.urllib.error import HTTPError
from ansible.module_utils.six.moves.urllib.error import URLError
Expand All @@ -54,6 +61,24 @@
from ansible.plugins.lookup import LookupBase


def valid_cidr(ip_address):
"""
Validate IP address
"""
if NETADDR_LIBRARY_IMPORT_ERROR:
raise_from(
AnsibleError('netaddr must be installed to use this plugin'),
NETADDR_LIBRARY_IMPORT_ERROR)
try:
netaddr.IPNetwork(ip_address)
except netaddr.core.AddrFormatError as e:
raise AnsibleError("Not a valid IP address: %s" % e)
cidr = ip_address.split('/')
if (len(cidr) <= 1 or cidr[1] == ''):
return False
return True


class LookupModule(LookupBase):
def run(self, terms, variables, **kwargs):
if "ipv6_prefixes" in kwargs and kwargs["ipv6_prefixes"]:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
boto>=2.49.0
botocore>=1.16.0
boto3>=1.13.0
netaddr>=0.8.0

0 comments on commit dfc105a

Please sign in to comment.