-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
64 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters