mirror of
https://platform.sunet.se/SUNET/knotctl.git
synced 2025-07-03 18:28:29 +02:00
Compare commits
No commits in common. "5b039dc8dac414d9ac27781222d9db575eb74816" and "665942653edd49d118cb4367a8b7d085aa3d02c9" have entirely different histories.
5b039dc8da
...
665942653e
1 changed files with 19 additions and 17 deletions
|
@ -42,8 +42,9 @@ def nested_out(input, tabs="") -> str:
|
||||||
string += "{}\n".format(input)
|
string += "{}\n".format(input)
|
||||||
elif isinstance(input, dict):
|
elif isinstance(input, dict):
|
||||||
for key, value in input.items():
|
for key, value in input.items():
|
||||||
string += "{}{}: {}".format(tabs, key,
|
string += "{}{}: {}".format(
|
||||||
nested_out(value, tabs + " "))
|
tabs, key, nested_out(value, tabs + " ")
|
||||||
|
)
|
||||||
elif isinstance(input, list):
|
elif isinstance(input, list):
|
||||||
for entry in input:
|
for entry in input:
|
||||||
string += "{}\n{}".format(tabs, nested_out(entry, tabs + " "))
|
string += "{}\n{}".format(tabs, nested_out(entry, tabs + " "))
|
||||||
|
@ -67,9 +68,11 @@ def run_add(url: str, jsonout: bool, headers: dict):
|
||||||
out = response.json()
|
out = response.json()
|
||||||
if isinstance(out, list):
|
if isinstance(out, list):
|
||||||
for record in out:
|
for record in out:
|
||||||
if (record["data"] == parsed["data"]
|
if (
|
||||||
and record["name"] == parsed["name"]
|
record["data"] == parsed["data"]
|
||||||
and record["rtype"] == parsed["rtype"]):
|
and record["name"] == parsed["name"]
|
||||||
|
and record["rtype"] == parsed["rtype"]
|
||||||
|
):
|
||||||
output(record, jsonout)
|
output(record, jsonout)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
@ -103,7 +106,8 @@ def run_config(
|
||||||
error(
|
error(
|
||||||
"Can not configure without {}".format(need),
|
"Can not configure without {}".format(need),
|
||||||
"No {}".format(need),
|
"No {}".format(need),
|
||||||
))
|
)
|
||||||
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
config[need] = input("Enter {}: ".format(need))
|
config[need] = input("Enter {}: ".format(need))
|
||||||
|
|
||||||
|
@ -127,10 +131,9 @@ def run_delete(url: str, jsonout: bool, headers: dict):
|
||||||
output(reply, jsonout)
|
output(reply, jsonout)
|
||||||
|
|
||||||
|
|
||||||
def run_list(url: str,
|
def run_list(
|
||||||
jsonout: bool,
|
url: str, jsonout: bool, headers: dict, ret=False
|
||||||
headers: dict,
|
) -> Union[None, str]:
|
||||||
ret=False) -> Union[None, str]:
|
|
||||||
response = requests.get(url, headers=headers)
|
response = requests.get(url, headers=headers)
|
||||||
string = response.json()
|
string = response.json()
|
||||||
if ret:
|
if ret:
|
||||||
|
@ -180,14 +183,16 @@ def setup_url(
|
||||||
error(
|
error(
|
||||||
"ttl only makes sense with rtype, name and zone",
|
"ttl only makes sense with rtype, name and zone",
|
||||||
"Missing parameter",
|
"Missing parameter",
|
||||||
))
|
)
|
||||||
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if rtype and (not name or not zone):
|
if rtype and (not name or not zone):
|
||||||
output(
|
output(
|
||||||
error(
|
error(
|
||||||
"rtype only makes sense with name and zone",
|
"rtype only makes sense with name and zone",
|
||||||
"Missing parameter",
|
"Missing parameter",
|
||||||
))
|
)
|
||||||
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if name and not zone:
|
if name and not zone:
|
||||||
output(error("name only makes sense with a zone", "Missing parameter"))
|
output(error("name only makes sense with a zone", "Missing parameter"))
|
||||||
|
@ -308,10 +313,6 @@ def main() -> int:
|
||||||
except KeyError:
|
except KeyError:
|
||||||
output(response.json())
|
output(response.json())
|
||||||
return 1
|
return 1
|
||||||
except json.JSONDecodeError:
|
|
||||||
output(
|
|
||||||
error("Could not decode api response as JSON", "Could not decode"))
|
|
||||||
return 1
|
|
||||||
headers = {"Authorization": "Bearer {}".format(token)}
|
headers = {"Authorization": "Bearer {}".format(token)}
|
||||||
|
|
||||||
# Route based on command
|
# Route based on command
|
||||||
|
@ -354,7 +355,8 @@ def main() -> int:
|
||||||
run_update(url, args.json, headers)
|
run_update(url, args.json, headers)
|
||||||
except (RequestsJSONDecodeError, SimplejsonJSONDecodeError):
|
except (RequestsJSONDecodeError, SimplejsonJSONDecodeError):
|
||||||
output(
|
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
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue