Move Verizon endpoint config into plugin
This commit is contained in:
@@ -100,7 +100,6 @@ class AppConfig:
|
||||
source_name: str
|
||||
provider_name: str
|
||||
npm_endpoints: tuple[Endpoint, ...]
|
||||
verizon_endpoints: tuple[Endpoint, ...]
|
||||
proxy_ip: str
|
||||
proxy_api_port: int
|
||||
proxy_api_scheme: str
|
||||
@@ -122,12 +121,6 @@ class AppConfig:
|
||||
source_name = os.getenv("PROXY", "npm").strip().lower()
|
||||
provider_name = os.getenv("DNS_PROVIDER", "verizon").strip().lower()
|
||||
|
||||
verizon_endpoints = parse_endpoint_list(
|
||||
"verizon",
|
||||
os.getenv("VERIZON_ENDPOINTS", "192.168.1.1"),
|
||||
443,
|
||||
)
|
||||
|
||||
try:
|
||||
port = int(os.getenv("PROXY_API_PORT", "81"))
|
||||
except ValueError as exc:
|
||||
@@ -195,7 +188,6 @@ class AppConfig:
|
||||
source_name=source_name,
|
||||
provider_name=provider_name,
|
||||
npm_endpoints=npm_endpoints,
|
||||
verizon_endpoints=verizon_endpoints,
|
||||
proxy_ip=proxy_ip,
|
||||
proxy_api_port=port,
|
||||
proxy_api_scheme=scheme,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import os
|
||||
|
||||
from dns_sync.adapters import (
|
||||
DNS_RECORDS,
|
||||
ApplyResult,
|
||||
@@ -13,12 +15,20 @@ from dns_sync.adapter_support import (
|
||||
require_desired,
|
||||
require_endpoint_plugin,
|
||||
)
|
||||
from dns_sync.config import parse_endpoint_list
|
||||
from dns_sync.models import DesiredRecord
|
||||
from .provider import Plugin as VerizonProvider
|
||||
|
||||
|
||||
def configured_endpoints(config):
|
||||
return config.verizon_endpoints
|
||||
return parse_endpoint_list(
|
||||
"verizon",
|
||||
os.getenv(
|
||||
"VERIZON_ENDPOINTS",
|
||||
"192.168.1.1",
|
||||
),
|
||||
443,
|
||||
)
|
||||
|
||||
|
||||
class Plugin:
|
||||
|
||||
@@ -115,48 +115,6 @@ class AppConfigEndpointTests(unittest.TestCase):
|
||||
):
|
||||
AppConfig.from_env()
|
||||
|
||||
def test_verizon_endpoint_list_is_plugin_specific(self):
|
||||
with patch.dict(
|
||||
os.environ,
|
||||
{
|
||||
"NPM_ENDPOINTS": "192.168.1.3",
|
||||
"VERIZON_ENDPOINTS": (
|
||||
"192.168.1.1,192.168.1.254:8443"
|
||||
),
|
||||
},
|
||||
clear=True,
|
||||
):
|
||||
config = AppConfig.from_env()
|
||||
|
||||
self.assertEqual(
|
||||
tuple(
|
||||
endpoint.identity
|
||||
for endpoint in config.verizon_endpoints
|
||||
),
|
||||
(
|
||||
"verizon://192.168.1.1:443",
|
||||
"verizon://192.168.1.254:8443",
|
||||
),
|
||||
)
|
||||
|
||||
def test_router_url_does_not_configure_generic_endpoint(self):
|
||||
with patch.dict(
|
||||
os.environ,
|
||||
{
|
||||
"NPM_ENDPOINTS": "192.168.1.3",
|
||||
"ROUTER_URL": "https://192.168.1.254",
|
||||
},
|
||||
clear=True,
|
||||
):
|
||||
config = AppConfig.from_env()
|
||||
|
||||
self.assertEqual(
|
||||
tuple(
|
||||
endpoint.identity
|
||||
for endpoint in config.verizon_endpoints
|
||||
),
|
||||
("verizon://192.168.1.1:443",),
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -13,7 +13,10 @@ from dns_sync.adapters import (
|
||||
)
|
||||
from dns_sync.config import AppConfig
|
||||
from dns_sync.models import ProviderRecord
|
||||
from dns_sync.registry import load_adapter
|
||||
from dns_sync.registry import (
|
||||
configured_adapter_endpoints,
|
||||
load_adapter,
|
||||
)
|
||||
|
||||
|
||||
class VerizonAdapterTests(unittest.TestCase):
|
||||
@@ -57,10 +60,15 @@ class VerizonAdapterTests(unittest.TestCase):
|
||||
"VerizonProvider",
|
||||
return_value=provider,
|
||||
):
|
||||
endpoint = configured_adapter_endpoints(
|
||||
"verizon",
|
||||
config,
|
||||
)[0]
|
||||
|
||||
return load_adapter(
|
||||
"verizon",
|
||||
config,
|
||||
config.verizon_endpoints[0],
|
||||
endpoint,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
@@ -143,10 +151,15 @@ class VerizonAdapterTests(unittest.TestCase):
|
||||
clear=True,
|
||||
):
|
||||
config = AppConfig.from_env()
|
||||
endpoint = configured_adapter_endpoints(
|
||||
"verizon",
|
||||
config,
|
||||
)[0]
|
||||
|
||||
adapter = load_adapter(
|
||||
"verizon",
|
||||
config,
|
||||
config.verizon_endpoints[0],
|
||||
endpoint,
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
|
||||
Reference in New Issue
Block a user