27 lines
693 B
Python
27 lines
693 B
Python
import yaml
|
|
from .models import GlobalConfig, Service
|
|
|
|
def load_services(path: str) -> list[Service]:
|
|
raw = yaml.safe_load(open(path))["services"]
|
|
|
|
services = []
|
|
for name, s in raw.items():
|
|
ip, port = s["endpoint"].split(":")
|
|
services.append(Service(
|
|
name=name,
|
|
internal_ip=ip,
|
|
internal_port=int(port),
|
|
public_port=int(s["public_port"]),
|
|
protocol=s["protocol"],
|
|
exposure=set(s.get("exposure", [])),
|
|
))
|
|
return(services)
|
|
|
|
def load_globals(path: str) -> GlobalConfig:
|
|
g = yaml.safe_load(open(path))["wan"]
|
|
return GlobalConfig(
|
|
wan_interface=g["wan_interface"],
|
|
public_ip=g["public_ip"],
|
|
lan_interface=g["lan_interface"],
|
|
internal_cidr=g["internal_cidr"],
|
|
)
|