Skip to content

Commit

Permalink
some linting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhi13man committed Jun 17, 2024
1 parent d032c80 commit 18f0045
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 52 deletions.
47 changes: 26 additions & 21 deletions src/models/vpn_config/abstract_vpn_config.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,61 @@
'''
"""
Abstract class for VPN data.
'''
"""

from abc import ABC

from src.enums.vpn_type import VpnType, VpnTypeVisitor, T


class AbstractVpnConfig(ABC):
'''
"""
Abstract class for VPN data.
'''
"""

_vpn_type_key: str = 'vpn_type'
_vpn_type_key: str = "vpn_type"
_vpn_type: VpnType = VpnType.NONE

def get_vpn_type(self) -> VpnType:
'''
"""
Get the type of the VPN.
Returns:
VpnType: Type of the VPN
'''
"""
return AbstractVpnConfig._vpn_type

def visit(self, visitor: 'VpnTypeVisitor[T]') -> T:
'''
def visit(self, visitor: "VpnTypeVisitor[T]") -> T:
"""
Visit the VPN with a VpnTypeVisitor.
Args:
visitor (VpnTypeVisitor): Visitor to visit the Pritunl VPN with
'''
"""
return visitor.visit_none()

def to_json(self) -> dict:
'''
Convert the VPN data to a JSON string.
"""
Convert the VPN data to a JSON representation.
Returns:
str: JSON string of the VPN data
'''
str: JSON representation of the VPN data
"""
return {AbstractVpnConfig._vpn_type_key: self.get_vpn_type().value}

@staticmethod
def from_json(json: dict) -> 'AbstractVpnConfig':
'''
Create a VPN data object from a JSON string.
def from_json(json: dict) -> "AbstractVpnConfig":
"""
Create a VPN data object from a JSON representation.
Args:
json (dict): JSON string of the VPN data
'''
vpn_type: VpnType = VpnType(json.get(AbstractVpnConfig._vpn_type_key, VpnType.NONE))
json (dict): JSON representation of the VPN data
Returns:
AbstractVpnConfig: VPN data object
"""
vpn_type: VpnType = VpnType(
json.get(AbstractVpnConfig._vpn_type_key, VpnType.NONE)
)
if vpn_type != AbstractVpnConfig._vpn_type:
raise ValueError(f'Invalid VPN type {vpn_type}')
raise ValueError(f"Invalid VPN type {vpn_type}")
return AbstractVpnConfig()
69 changes: 38 additions & 31 deletions src/models/vpn_model/abstract_vpn_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'''
"""
Abstract class for VPN data.
'''
"""

from subprocess import CompletedProcess
from abc import ABC, abstractmethod
Expand All @@ -10,98 +10,105 @@


class AbstractVpnModel(ABC):
'''
"""
Abstract class for VPN data.
Attributes:
vpn_id (str): ID of the VPN
'''
"""

_vpn_id_key: str = 'vpn_id'
vpn_type_key: str = 'vpn_type'
_vpn_id_key: str = "vpn_id"
vpn_type_key: str = "vpn_type"
_vpn_type: VpnType = VpnType.NONE

def __init__(self, vpn_id: str, config: AbstractVpnConfig) -> None:
self.vpn_id: str = vpn_id
self.config: AbstractVpnConfig = config

def get_vpn_id(self) -> str:
'''
"""
Get the ID of the VPN.
Returns:
str: ID of the VPN
'''
"""
return self.vpn_id

def get_vpn_type(self) -> VpnType:
'''
"""
Get the type of the VPN.
Returns:
VpnType: Type of the VPN
'''
"""
return AbstractVpnModel._vpn_type

@abstractmethod
def connect(self, verbose: bool) -> CompletedProcess:
'''
"""
Connect to the VPN.
Args:
verbose (bool): Whether to print the output of the connection process
'''
"""
raise NotImplementedError

@abstractmethod
def disconnect(self, verbose: bool) -> CompletedProcess:
'''
"""
Disconnect from the VPN.
Args:
verbose (bool): Whether to print the output of the disconnection process
'''
"""
raise NotImplementedError

def visit(self, visitor: 'VpnTypeVisitor[T]') -> T:
'''
def visit(self, visitor: "VpnTypeVisitor[T]") -> T:
"""
Visit the VPN with a VpnTypeVisitor.
Args:
visitor (VpnTypeVisitor): Visitor to visit the Pritunl VPN with
'''
"""
return visitor.visit_none()

def get_global_vpn_id(self) -> str:
'''
"""
Get the global ID of the VPN.
Returns:
str: Global ID of the VPN. This is the ID of the VPN prefixed with the type of the VPN.
'''
return f'{self.get_vpn_type().name}_{self.get_vpn_id()}'
"""
return f"{self.get_vpn_type().name}_{self.get_vpn_id()}"

def to_json(self) -> dict:
'''
"""
Convert the VPN data to a JSON string.
Returns:
str: JSON string of the VPN data
'''
dict: JSON representation of the VPN data
"""
return {
AbstractVpnModel._vpn_id_key: self.get_vpn_id(),
AbstractVpnModel.vpn_type_key: self.get_vpn_type().value
AbstractVpnModel.vpn_type_key: self.get_vpn_type().value,
}

@staticmethod
def from_json_with_config(json: dict, config: AbstractVpnConfig) -> 'AbstractVpnModel':
'''
Create a VPN data object from a JSON string.
def from_json_with_config(
json: dict, config: AbstractVpnConfig
) -> "AbstractVpnModel":
"""
Create a VPN data object from a JSON representation.
Args:
json (dict): JSON string of the VPN data
'''
json (dict): JSON representation of the VPN data
Returns:
AbstractVpnModel: VPN data object
"""
vpn_type: VpnType = VpnType(json.get(AbstractVpnModel.vpn_type_key))
if vpn_type != AbstractVpnModel._vpn_type:
raise ValueError(f'Invalid VPN type {vpn_type}')
return AbstractVpnModel(vpn_id=json.get(AbstractVpnModel._vpn_id_key), config=config)
raise ValueError(f"Invalid VPN type {vpn_type}")
return AbstractVpnModel(
vpn_id=json.get(AbstractVpnModel._vpn_id_key), config=config
)

0 comments on commit 18f0045

Please sign in to comment.