Make ttl optional for add

main v0.0.5
Micke Nordin 2 years ago
parent 33a21cb7cb
commit 7817cb43b8
Signed by untrusted user: micke
GPG Key ID: 0DA0A7A5708FE257

@ -50,7 +50,7 @@ options:
``` ```
### ADD ### ADD
``` ```
usage: knotctl add [-h] -d DATA -n NAME -r RTYPE -t TTL -z ZONE usage: knotctl add [-h] -d DATA -n NAME -r RTYPE [-t TTL] -z ZONE
options: options:
-h, --help show this help message and exit -h, --help show this help message and exit

@ -115,9 +115,16 @@ def run_delete(url: str, jsonout: bool, headers: dict):
output(reply, jsonout) output(reply, jsonout)
def run_list(url: str, jsonout: bool, headers: dict): def run_list(url: str,
jsonout: bool,
headers: dict,
ret=False) -> Union[None, str]:
response = requests.get(url, headers=headers) response = requests.get(url, headers=headers)
output(response.json(), jsonout) string = response.json()
if ret:
return string
else:
output(string, jsonout)
def run_update(url: str, jsonout: bool, headers: dict): def run_update(url: str, jsonout: bool, headers: dict):
@ -182,7 +189,7 @@ def main() -> int:
addcmd.add_argument("-d", "--data", required=True) addcmd.add_argument("-d", "--data", required=True)
addcmd.add_argument("-n", "--name", required=True) addcmd.add_argument("-n", "--name", required=True)
addcmd.add_argument("-r", "--rtype", required=True) addcmd.add_argument("-r", "--rtype", required=True)
addcmd.add_argument("-t", "--ttl", required=True) addcmd.add_argument("-t", "--ttl")
addcmd.add_argument("-z", "--zone", required=True) addcmd.add_argument("-z", "--zone", required=True)
completecmd = subparsers.add_parser("completion") completecmd = subparsers.add_parser("completion")
@ -261,6 +268,16 @@ def main() -> int:
ttl = args.ttl ttl = args.ttl
if args.command != "update": if args.command != "update":
args.argument = None args.argument = None
if args.command == "add" and not ttl:
if args.zone.endswith('.'):
zname = args.zone
else:
zname = args.zone + '.'
soa_url = setup_url(baseurl, None, None, zname, "SOA", None,
args.zone)
soa_json = run_list(soa_url, True, headers, ret=True)
ttl = soa_json[0]["ttl"]
try: try:
url = setup_url(baseurl, args.argument, args.data, args.name, url = setup_url(baseurl, args.argument, args.data, args.name,
args.rtype, ttl, args.zone) args.rtype, ttl, args.zone)

@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
setuptools.setup( setuptools.setup(
name="knotctl", name="knotctl",
version="0.0.4", version="0.0.5",
packages = setuptools.find_packages(), packages = setuptools.find_packages(),
author="Micke Nordin", author="Micke Nordin",
author_email="hej@mic.ke", author_email="hej@mic.ke",

Loading…
Cancel
Save