57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
from core.models.BaseConnection import BaseConnection
|
|
from dataclasses import dataclass
|
|
from enum import Enum
|
|
|
|
@dataclass
|
|
class SessionConnection(BaseConnection):
|
|
masked: bool = False
|
|
|
|
def __post_init__(self):
|
|
|
|
if self.code not in ('system', 'tor', 'wireguard'):
|
|
raise ValueError('Invalid connection code.')
|
|
|
|
|
|
# Called by: ConnectionController
|
|
# doesn't even make sense, it's checking if the Session is code system. this will always be false.
|
|
def is_unprotected(self):
|
|
return self.code == 'system' and self.masked is False
|
|
|
|
# Called by: SessionProfile.determine_timezone
|
|
def needs_proxy_configuration(self):
|
|
return self.masked is True
|
|
|
|
|
|
# Potential refactor
|
|
|
|
# from dataclasses import dataclass, field
|
|
# from dataclasses_json import dataclass_json, config
|
|
|
|
# class SessionConnectionTypes(str, Enum):
|
|
# WIREGUARD = "wireguard"
|
|
# TOR = "tor"
|
|
|
|
# @dataclass_json
|
|
# @dataclass
|
|
# class SessionConnection:
|
|
# code: SessionConnectionTypes = field(
|
|
# metadata=config(
|
|
# encoder=lambda x: x.value, # Convert enum to string on save
|
|
# decoder=lambda x: SessionConnectionTypes(x) # Convert string to enum on load
|
|
# )
|
|
# )
|
|
# masked: bool = False
|
|
|
|
# def __post_init__(self):
|
|
# # Convert string to enum for deserialization
|
|
# if isinstance(self.code, str):
|
|
# self.code = SessionConnectionTypes(self.code)
|
|
|
|
# # Validation
|
|
# if self.code not in SessionConnectionTypes:
|
|
# raise ValueError(f'Invalid code: {self.code}')
|
|
|
|
# @dataclass
|
|
# class SessionConnection(BaseConnection):
|
|
# code: SessionConnectionTypes
|
|
# masked: bool
|