From 9a68048f5b6e6c5cce0c9ea452925dfb51c52a86 Mon Sep 17 00:00:00 2001 From: LunarEclipse Date: Sun, 13 Aug 2023 21:21:28 +0200 Subject: [PATCH 1/2] Added the ability to replace the config file with environment variables --- porkbun_ddns/cli.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/porkbun_ddns/cli.py b/porkbun_ddns/cli.py index f4f6bf5..b96702a 100644 --- a/porkbun_ddns/cli.py +++ b/porkbun_ddns/cli.py @@ -1,5 +1,6 @@ import argparse import sys +import os import traceback import logging from porkbun_ddns import PorkbunDDNS, PorkbunDDNS_Error @@ -52,6 +53,21 @@ def main(argv=sys.argv[1:]): args = parser.parse_args(argv) + if args.config == "-": + try: + config = { + "apikey": os.environ["PORKBUN_APIKEY"], + "secretapikey": os.environ["PORKBUN_SECRETAPIKEY"], + } + endpoint = os.environ.get("PORKBUN_DDNS_ENDPOINT"), + if endpoint is not None: + config["endpoint"] = endpoint # type: ignore + except KeyError as e: + print("Invalid config environment variables.") + raise e + else: + config = args.config + ipv4 = args.ipv4_only ipv6 = args.ipv6_only if not any([ipv4, ipv6]): @@ -63,7 +79,7 @@ def main(argv=sys.argv[1:]): handler.setLevel(logging.DEBUG) try: - porkbun_ddns = PorkbunDDNS(config=args.config, domain=args.domain, + porkbun_ddns = PorkbunDDNS(config=config, domain=args.domain, public_ips=args.public_ips, fritzbox_ip=args.fritzbox, ipv4=ipv4, ipv6=ipv6) if args.subdomain: From b7a480482ddb320446125a6a43079e908962db33 Mon Sep 17 00:00:00 2001 From: LunarEclipse Date: Sun, 13 Aug 2023 22:08:40 +0200 Subject: [PATCH 2/2] support for multiple subdomains --- porkbun_ddns/cli.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/porkbun_ddns/cli.py b/porkbun_ddns/cli.py index b96702a..6667ff2 100644 --- a/porkbun_ddns/cli.py +++ b/porkbun_ddns/cli.py @@ -22,9 +22,9 @@ def main(argv=sys.argv[1:]): parser.add_argument("config", help="Path to config file") parser.add_argument("domain", help="Domain to be updated") - subdomain = parser.add_mutually_exclusive_group() - subdomain.add_argument('subdomain', nargs='?', - default=None, help="Subdomain") + subdomains = parser.add_mutually_exclusive_group() + subdomains.add_argument('subdomains', nargs='*', + default=None, help="Subdomain(s)") public_ips = parser.add_mutually_exclusive_group() public_ips.add_argument('-i', '--public-ips', nargs='*', @@ -82,9 +82,12 @@ def main(argv=sys.argv[1:]): porkbun_ddns = PorkbunDDNS(config=config, domain=args.domain, public_ips=args.public_ips, fritzbox_ip=args.fritzbox, ipv4=ipv4, ipv6=ipv6) - if args.subdomain: - porkbun_ddns.set_subdomain(args.subdomain) - porkbun_ddns.update_records() + if args.subdomains: + for s in args.subdomains: + porkbun_ddns.set_subdomain(s) + porkbun_ddns.update_records() + else: + porkbun_ddns.update_records() except PorkbunDDNS_Error as e: logger.error("Error: " + str(e)) except Exception as e: