Skip to content

Commit

Permalink
Generalized network selection for service configuration. Pylint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
raulikak committed May 29, 2024
1 parent 331650d commit 5284808
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tcsfw/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import enum
import ipaddress
from ipaddress import IPv4Address, IPv4Network, IPv6Address, IPv6Network
from typing import List, Union, Optional, Tuple, Iterable, Self
from typing import Union, Optional, Tuple, Iterable, Self


class Protocol(enum.Enum):
Expand Down
13 changes: 9 additions & 4 deletions tcsfw/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,14 @@ def where(self, handles: Dict[str, Union[NodeBuilder, NodeVisualBuilder]]) -> Se

class ProtocolConfigurer:
"""Protocol configurer base class"""
def __init__(self, name: str, networks: Optional[List[NetworkBuilder]] = None):
def __init__(self, name: str):
self.name = name
self.networks = networks or []
self.networks = []

def in_network(self, *network: NetworkBuilder) -> Self:
"""Specify networks for the service"""
self.networks.extend(network)
return self

def __repr__(self) -> str:
return self.name
Expand Down Expand Up @@ -346,8 +351,8 @@ def __init__(self, port=22):

class TCP(ProtocolConfigurer):
"""TCP configurer"""
def __init__(self, port: int, name="TCP", networks: List[NetworkBuilder] = None, administrative=False):
ProtocolConfigurer.__init__(self, name, networks)
def __init__(self, port: int, name="TCP", administrative=False):
ProtocolConfigurer.__init__(self, name)
self.port = port
self.name = name
self.administrative = administrative
Expand Down
2 changes: 1 addition & 1 deletion tcsfw/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import List, Set, Optional, Tuple, TypeVar, Callable, Dict, Any, Self, Iterable, Iterator, Union
from urllib.parse import urlparse

from tcsfw.address import AnyAddress, Addresses, EndpointAddress, EntityTag, Network, Networks, Protocol, IPAddress, \
from tcsfw.address import AnyAddress, Addresses, EndpointAddress, EntityTag, Network, Protocol, IPAddress, \
HWAddress, DNSName
from tcsfw.basics import ConnectionType, ExternalActivity, HostType, Status
from tcsfw.entity import Entity
Expand Down
2 changes: 1 addition & 1 deletion tcsfw/traffic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import datetime
from typing import Any, Callable, Tuple, Set, Optional, Self, Dict

from tcsfw.address import EntityTag, HWAddress, IPAddress, HWAddresses, IPAddresses, Protocol, EndpointAddress, \
from tcsfw.address import HWAddress, IPAddress, HWAddresses, IPAddresses, Protocol, EndpointAddress, \
AnyAddress, Addresses
from tcsfw.property import PropertyKey

Expand Down
2 changes: 1 addition & 1 deletion tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def test_unknown_service_in_subnet():
su = Setup()
net1 = su.system.network("VPN", "169.254.0.0/16")
dev1 = su.system.device().ip("192.168.4.5").in_networks(net1, su.system.network())
ser1_1 = dev1 / TCP(8686, networks=[net1])
ser1_1 = dev1 / TCP(8686).in_network(net1)
system = su.get_system()

# the known service with envelope address
Expand Down

0 comments on commit 5284808

Please sign in to comment.