From 958ea3c9e3b10c4ea76663c317a9c50bb70c685f Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Sun, 22 Dec 2024 04:59:55 +0100 Subject: [PATCH] libs/tools: add option to only add private ips if system has only private ips --- libs/tools.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/tools.py b/libs/tools.py index 7a984df..4f98677 100644 --- a/libs/tools.py +++ b/libs/tools.py @@ -5,7 +5,7 @@ from bundlewrap.utils.text import bold, red from bundlewrap.utils.ui import io -def resolve_identifier(repo, identifier, linklocal=False, only_physical=False): +def resolve_identifier(repo, identifier, linklocal=False, only_physical=False, allow_private=True): """ Try to resolve an identifier (group or node). Return a set of ip addresses valid for this identifier. @@ -62,10 +62,15 @@ def resolve_identifier(repo, identifier, linklocal=False, only_physical=False): 'ipv6': set(), } + has_public_ips = bool([ip for ip in found_ips if not ip.is_private]) + for ip in found_ips: if ip.is_link_local and not linklocal: continue + if ip.is_private and not allow_private and has_public_ips: + continue + if isinstance(ip, IPv4Address): ip_dict['ipv4'].add(ip) else: