diff --git a/pddnsc/outputs/vscale.py b/pddnsc/outputs/vscale.py index bbfd8fb..e8863bc 100644 --- a/pddnsc/outputs/vscale.py +++ b/pddnsc/outputs/vscale.py @@ -8,13 +8,20 @@ from pddnsc.base import BaseOutputProvider class VscaleDomains(BaseOutputProvider): def post_init(self): - self.__token = self.get_api_token() - if not self.__token: + token = self.get_api_token() + if not token: raise KeyError("no api token, use env VSCALE_API_TOKEN") - target = self.config["target"] - self.domain = self.config["domain"] - self.target = f"{target}.{self.domain}" + self.__headers = {"X-Token": token} + self.api_base = self.config.get("api_base", "https://api.vscale.io/v1/") self.ttl = self.config.get("ttl", 300) + self.domain = self.config["domain"] + target = self.config["target"] + self.target = f"{target}.{self.domain}" + + self.save_ipv4 = self.config.get("ipv4", False) + self.save_ipv6 = self.config.get("ipv6", False) + if "ipv4" not in self.config and "ipv6" not in self.config: + self.save_ipv4 = self.save_ipv6 = True def get_api_token(self) -> str: token_env = self.config.get("api_token_env", "VSCALE_API_TOKEN") @@ -90,23 +97,19 @@ class VscaleDomains(BaseOutputProvider): ) async def set_addrs_imp(self, source_provider, addr_v4, addr_v6): - save_ipv4 = self.config.get("ipv4", False) - save_ipv6 = self.config.get("ipv6", False) - if "ipv4" not in self.config and "ipv6" not in self.config: - save_ipv4 = save_ipv6 = True - save_addrs = [] - if addr_v4 and save_ipv4: + if addr_v4 and self.save_ipv4: save_addrs.append(("A", addr_v4)) - if addr_v6 and save_ipv6: + if addr_v6 and self.save_ipv6: save_addrs.append(("AAAA", addr_v6)) transport = self.best_transport(addr_v4, addr_v6) - api_base = self.config.get("api_base", "https://api.vscale.io/v1/") - headers = {"X-Token": self.__token} async with httpx.AsyncClient( - transport=transport, base_url=api_base, headers=headers, http2=True + transport=transport, + base_url=self.api_base, + headers=self.__headers, + http2=True, ) as client: domain_id = await self.find_domain_id(client) for record_type, value in save_addrs: