refactor: перенос логики работы с конфигурациями Xray из класса XrayConfig в классы Outbound и OutboundFactory
This commit is contained in:
@@ -60,6 +60,7 @@ class OutboundFactory:
|
|||||||
outbound_cls = cls._scheme_registry[scheme]
|
outbound_cls = cls._scheme_registry[scheme]
|
||||||
return outbound_cls.from_link(target_storage, link)
|
return outbound_cls.from_link(target_storage, link)
|
||||||
|
|
||||||
|
# устаревший метод, удалить после рефакторинга
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_inbound(
|
def from_inbound(
|
||||||
cls,
|
cls,
|
||||||
@@ -79,6 +80,19 @@ class OutboundFactory:
|
|||||||
)
|
)
|
||||||
return username, outbound
|
return username, outbound
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_xray_inbound(
|
||||||
|
cls, ts: TargetStorage, client: dict, inbound: dict
|
||||||
|
) -> Outbound:
|
||||||
|
protocol = inbound.get("protocol")
|
||||||
|
|
||||||
|
if protocol not in cls._registry:
|
||||||
|
raise ValueError(f"Unsupported protocol: {protocol}")
|
||||||
|
|
||||||
|
outbound_cls = cls._registry[protocol]
|
||||||
|
outbound = outbound_cls.from_xray_inbound(ts, client, inbound)
|
||||||
|
return outbound
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_spec(
|
def from_spec(
|
||||||
cls,
|
cls,
|
||||||
@@ -121,6 +135,12 @@ class Outbound(ABC):
|
|||||||
inbound: dict,
|
inbound: dict,
|
||||||
) -> tuple[str, Outbound]: ...
|
) -> tuple[str, Outbound]: ...
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
@abstractmethod
|
||||||
|
def from_xray_inbound(
|
||||||
|
cls, ts: TargetStorage, client: dict, inbound: dict
|
||||||
|
) -> Outbound: ...
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def from_scratch(
|
def from_scratch(
|
||||||
@@ -145,8 +165,8 @@ class Outbound(ABC):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def split_client_email(email: str) -> tuple[str, str]:
|
def split_client_email(email: str) -> tuple[str, str]:
|
||||||
username, target = email.rsplit("-", 1)
|
username, target_id = email.rsplit("-", 1)
|
||||||
return username, target
|
return username, target_id
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def __hash__(self) -> int: ...
|
def __hash__(self) -> int: ...
|
||||||
|
|||||||
Reference in New Issue
Block a user