Skip to content

Commit

Permalink
better check
Browse files Browse the repository at this point in the history
  • Loading branch information
stavros-k committed Jan 10, 2025
1 parent 35bc7c8 commit c70463a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions library/2.1.9/ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,21 @@ def _get_opposite_wildcard(self, ip: str) -> str:
def _get_sort_key(self, p: dict) -> str:
return f"{p['published']}_{p['target']}_{p['protocol']}_{p.get('host_ip', '_')}"

def _is_ports_same(self, port1: dict, port2: dict) -> bool:
return (
port1["published"] == port2["published"]
and port1["target"] == port2["target"]
and port1["protocol"] == port2["protocol"]
and port1.get("host_ip", "_") == port2.get("host_ip", "_")
)

def _has_opposite_family_port(self, port_config: dict, wildcard_ports: dict) -> bool:
comparison_port = port_config.copy()
comparison_port["host_ip"] = self._get_opposite_wildcard(port_config["host_ip"])
return comparison_port in wildcard_ports.values()
for p in wildcard_ports.values():
if self._is_ports_same(comparison_port, p):
return True
return False

def _check_port_conflicts(self, port_config: dict, ip_family: int) -> None:
host_port = port_config["published"]
Expand Down Expand Up @@ -77,7 +88,7 @@ def _check_port_conflicts(self, port_config: dict, ip_family: int) -> None:
search_port["host_ip"] = wildcard_ip
# If the ports match, means that a port for specific IP is already added
# and we are trying to add it again with wildcard IP. Raise an error
if search_port == port_config:
if self._is_ports_same(search_port, port_config):
raise RenderError(
f"Cannot bind port [{host_port}/{proto}/ipv{ip_family}] to [{host_ip}], "
f"already bound to [{p['host_ip']}]"
Expand Down
2 changes: 1 addition & 1 deletion library/hashes.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
0.0.1: f074617a82a86d2a6cc78a4c8a4296fc9d168e456f12713e50c696557b302133
2.1.9: 77faa51215dbbbd5051ef9de39d0481d6862f26e04a1f8a3ed69620266db1ef7
2.1.9: ad57a9c3cdf34eaaceca16b73e43996e11dc1841afea0828934bb0ea0a5bbd0b

0 comments on commit c70463a

Please sign in to comment.