libs/tools: fix output of resolve_identifier() for bare ip addresses
All checks were successful
bundlewrap/pipeline/head This commit looks good

This commit is contained in:
Franzi 2021-02-14 17:04:52 +01:00
parent 358a1869f4
commit 12d47ea0bc
Signed by: kunsi
GPG key ID: 12E3D2136B818350

View file

@ -1,6 +1,9 @@
from bundlewrap.exceptions import NoSuchGroup, NoSuchNode
from ipaddress import ip_address, IPv4Address from ipaddress import ip_address, IPv4Address
from bundlewrap.exceptions import NoSuchGroup, NoSuchNode
from bundlewrap.utils.text import bold, red
from bundlewrap.utils.ui import io
def resolve_identifier(repo, identifier): def resolve_identifier(repo, identifier):
""" """
Try to resolve an identifier (group or node). Return a set of ip Try to resolve an identifier (group or node). Return a set of ip
@ -13,9 +16,20 @@ def resolve_identifier(repo, identifier):
nodes = repo.nodes_in_group(identifier) nodes = repo.nodes_in_group(identifier)
except NoSuchGroup: except NoSuchGroup:
try: try:
return {ip_address(identifier)} ip = ip_address(identifier)
except:
return set() if isinstance(ip, IPv4Address):
return {'ipv4': {ip}, 'ipv6': set()}
else:
return {'ipv4': set(), 'ipv6': {ip}}
except Exception as e:
io.stderr('{x} {t} Exception while resolving "{i}": {e}'.format(
x=red(''),
t=bold('libs.tools.resolve_identifier'),
i=identifier,
e=str(e),
))
return {'ipv4': set(), 'ipv6': set()}
found_ips = set() found_ips = set()
for node in nodes: for node in nodes: