Skip to content

Commit

Permalink
chore: change typing
Browse files Browse the repository at this point in the history
  • Loading branch information
yanksyoon committed Jan 26, 2024
1 parent bcc9aa5 commit 4405ec5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src-docs/firewall.py.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The runner firewall manager.
## <kbd>class</kbd> `Firewall`
Represent a firewall and provides methods to refresh its configuration.

<a href="../src/firewall.py#L50"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/firewall.py#L52"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `__init__`

Expand All @@ -33,7 +33,7 @@ Initialize a new Firewall instance.

---

<a href="../src/firewall.py#L58"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/firewall.py#L60"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `get_host_ip`

Expand All @@ -50,7 +50,7 @@ Get the host IP address for the corresponding LXD network.

---

<a href="../src/firewall.py#L96"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/firewall.py#L98"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `refresh_firewall`

Expand Down Expand Up @@ -86,7 +86,7 @@ Represent an entry in the firewall.

---

<a href="../src/firewall.py#L25"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/firewall.py#L27"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>classmethod</kbd> `decode`

Expand Down
10 changes: 6 additions & 4 deletions src/firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

from utilities import execute_command

NetworkT = typing.TypeVar("NetworkT", ipaddress.IPv4Network, ipaddress.IPv6Network)


@dataclasses.dataclass
class FirewallEntry:
Expand Down Expand Up @@ -68,9 +70,9 @@ def get_host_ip(self) -> str:

def _exclude_network(
self,
networks: typing.List[ipaddress.IPv4Network],
excludes: typing.List[ipaddress.IPv4Network],
) -> typing.Set[ipaddress.IPv4Network]:
networks: typing.List[NetworkT],
excludes: typing.List[NetworkT],
) -> typing.Set[NetworkT]:
"""Excludes the network segment from a pool of networks.
Args:
Expand All @@ -83,7 +85,7 @@ def _exclude_network(
total_excluded_networks = set(networks)

for exclude in excludes:
scoped_excluded_networks: set[ipaddress.IPv4Network] = set()
scoped_excluded_networks: set[NetworkT] = set()
for net in total_excluded_networks:
if net.overlaps(exclude):
scoped_excluded_networks.update(net.address_exclude(exclude))
Expand Down

0 comments on commit 4405ec5

Please sign in to comment.