Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update multiple subdomains from python CLI #20

Merged
merged 2 commits into from
Oct 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions porkbun_ddns/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import sys
import os
import traceback
import logging
from porkbun_ddns import PorkbunDDNS, PorkbunDDNS_Error
Expand All @@ -21,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='*',
Expand Down Expand Up @@ -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]):
Expand All @@ -63,12 +79,15 @@ 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:
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:
Expand Down
Loading