mirror of
https://codeberg.org/privacy1st/netcup-dns
synced 2024-12-22 23:36:04 +01:00
feat: argparse
This commit is contained in:
parent
699d909e2d
commit
93b20ba4dc
@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import argparse
|
||||
import ipaddress
|
||||
import json
|
||||
import sys
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
from typing import Type
|
||||
@ -17,13 +17,8 @@ def main():
|
||||
"""
|
||||
The main effort is done by https://github.com/nbuchwitz/nc_dnsapi
|
||||
"""
|
||||
if len(sys.argv) > 1:
|
||||
cfg_dir = Path(sys.argv[1])
|
||||
else:
|
||||
cfg_dir = Path('/etc/netcup-dns')
|
||||
|
||||
if not cfg_dir.exists():
|
||||
raise Exception(f'The config directory is missing: {cfg_dir}')
|
||||
args = parse_args()
|
||||
cfg_dir: Path = args.cfg_dir
|
||||
|
||||
cfg_files = [file for file in cfg_dir.iterdir() if file.name.endswith('.json') and file.is_file()]
|
||||
for cfg_file in cfg_files:
|
||||
@ -59,6 +54,19 @@ def main():
|
||||
print(f'The {hostname}.{domain} {type_} record points already to {destination}')
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(description='Update DNS A/AAAA records with your current external IP address'
|
||||
' using the netcup DNS API.')
|
||||
parser.add_argument('--config-directory',
|
||||
help='Path to directory where `.json` config files reside.',
|
||||
dest='cfg_dir',
|
||||
default=Path('/etc/netcup-dns'),
|
||||
type=Path)
|
||||
args = parser.parse_args()
|
||||
|
||||
if not args.cfg_dir.exists():
|
||||
raise Exception(f'The given config directory does not exist: {args.cfg_dir}')
|
||||
|
||||
def update_record_destination(api: Client, domain: str, hostname: str, type_: str, destination: str) -> bool:
|
||||
"""
|
||||
Updates the `destination` of the DNS record identified by `domain`, `hostname` and `type`.
|
||||
|
Loading…
Reference in New Issue
Block a user