main
Micke Nordin 10 months ago
parent f16eb88eab
commit 5b039dc8da
Signed by: micke
GPG Key ID: 0DA0A7A5708FE257

@ -42,9 +42,8 @@ def nested_out(input, tabs="") -> str:
string += "{}\n".format(input)
elif isinstance(input, dict):
for key, value in input.items():
string += "{}{}: {}".format(
tabs, key, nested_out(value, tabs + " ")
)
string += "{}{}: {}".format(tabs, key,
nested_out(value, tabs + " "))
elif isinstance(input, list):
for entry in input:
string += "{}\n{}".format(tabs, nested_out(entry, tabs + " "))
@ -68,11 +67,9 @@ def run_add(url: str, jsonout: bool, headers: dict):
out = response.json()
if isinstance(out, list):
for record in out:
if (
record["data"] == parsed["data"]
and record["name"] == parsed["name"]
and record["rtype"] == parsed["rtype"]
):
if (record["data"] == parsed["data"]
and record["name"] == parsed["name"]
and record["rtype"] == parsed["rtype"]):
output(record, jsonout)
break
else:
@ -106,8 +103,7 @@ def run_config(
error(
"Can not configure without {}".format(need),
"No {}".format(need),
)
)
))
sys.exit(1)
config[need] = input("Enter {}: ".format(need))
@ -131,9 +127,10 @@ def run_delete(url: str, jsonout: bool, headers: dict):
output(reply, jsonout)
def run_list(
url: str, jsonout: bool, headers: dict, ret=False
) -> Union[None, str]:
def run_list(url: str,
jsonout: bool,
headers: dict,
ret=False) -> Union[None, str]:
response = requests.get(url, headers=headers)
string = response.json()
if ret:
@ -183,16 +180,14 @@ def setup_url(
error(
"ttl only makes sense with rtype, name and zone",
"Missing parameter",
)
)
))
sys.exit(1)
if rtype and (not name or not zone):
output(
error(
"rtype only makes sense with name and zone",
"Missing parameter",
)
)
))
sys.exit(1)
if name and not zone:
output(error("name only makes sense with a zone", "Missing parameter"))
@ -359,8 +354,7 @@ def main() -> int:
run_update(url, args.json, headers)
except (RequestsJSONDecodeError, SimplejsonJSONDecodeError):
output(
error("Could not decode api response as JSON", "Could not decode")
)
error("Could not decode api response as JSON", "Could not decode"))
return 0

Loading…
Cancel
Save