ReMe/reme/components/outbound_proxy/base.py
jinliyl 54fa3381d7
Some checks failed
CI and Release / Docker / Build and test / amd64 (push) Has been cancelled
CI and Release / Docker / Build and test / arm64 (push) Has been cancelled
Security / CodeQL / Analyze python (push) Has been cancelled
CI / Python quality / Pre-commit (push) Has been cancelled
CI / Python tests / Unit Tests - py3.12 (push) Has been cancelled
CI / Python tests / Unit Tests - py3.13 (push) Has been cancelled
CI / Python tests / Unit Tests - py3.14 (push) Has been cancelled
CI / Python packages / Build and verify distributions (push) Has been cancelled
CI / Python quality / GitHub Actions (push) Has been cancelled
CI / Python tests / Hermes embedded - ubuntu-latest (push) Has been cancelled
CI / Python tests / Hermes embedded - windows-latest (push) Has been cancelled
CI / Python tests / Unit Tests - py3.11 (push) Has been cancelled
CI / ReMe Studio / Studio checks (push) Has been cancelled
Deploy / Documentation / Build documentation (push) Has been cancelled
CI / Windows / CLI smoke - py3.11 (push) Has been cancelled
Security / CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI and Release / Docker / Publish multi-platform tags (push) Has been cancelled
Deploy / Documentation / deploy (push) Has been cancelled
refactor(core): reorganize the ReMe runtime and shared helpers (#769)
* refactor(core): reorganize the ReMe runtime and shared helpers

* test(status): import the base component from its canonical module

* test: remove redundant unit checks

* refactor(core): use canonical runtime imports and shared CLI discovery

Restore evolve behavior to the base branch and update its imports. Use Application as the runtime entry point and encode SSE in the HTTP service.

* fix(cli): honor caller config when service replay is incomplete

Use partial startup overrides for port probes and resolve named configs before requesting the service process working directory.
2026-11-20 22:06:46 +08:00

55 lines
1.8 KiB
Python

"""Public contract shared by outbound proxy backends."""
from collections.abc import Mapping
from dataclasses import dataclass
from ...constants import REME_IPV4_LOOPBACK_HOST, REME_IPV6_LOOPBACK_HOST
from ..base import BaseComponent
from ...enumeration import ComponentEnum
_LOCAL_BYPASS = f"{REME_IPV4_LOOPBACK_HOST},localhost,{REME_IPV6_LOOPBACK_HOST}"
_PROXY_VARIABLES = (
"HTTP_PROXY",
"HTTPS_PROXY",
"ALL_PROXY",
"http_proxy",
"https_proxy",
"all_proxy",
)
@dataclass(frozen=True, slots=True)
class OutboundProxyEndpoint:
"""Stable public endpoint exposed for the lifetime of a started proxy."""
http_url: str
class BaseOutboundProxy(BaseComponent):
"""Base component exposing one application-scoped HTTP proxy endpoint."""
component_type = ComponentEnum.OUTBOUND_PROXY
def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
self._endpoint: OutboundProxyEndpoint | None = None
@property
def endpoint(self) -> OutboundProxyEndpoint:
"""Return the ready endpoint, failing when the component is not started."""
if self._endpoint is None:
raise RuntimeError("Outbound proxy endpoint is unavailable; start the component first.")
return self._endpoint
@property
def http_url(self) -> str:
"""Return the public HTTP proxy URL."""
return self.endpoint.http_url
def merge_environment(self, base: Mapping[str, str] | None = None) -> dict[str, str]:
"""Return a proxy-aware environment without mutating the input or process environment."""
environment = dict(base or {})
environment.update(dict.fromkeys(_PROXY_VARIABLES, self.http_url))
environment["NO_PROXY"] = _LOCAL_BYPASS
environment["no_proxy"] = _LOCAL_BYPASS
return environment