mirror of
https://platform.sunet.se/SUNET/knotctl.git
synced 2025-05-12 11:48:29 +02:00
Compare commits
No commits in common. "5eeca61e099bd1f4ca02ce24dbdf8217e278dd9f" and "7b9d05f5a8122d7e0c469ca8beccaeb01e2c5950" have entirely different histories.
5eeca61e09
...
7b9d05f5a8
1 changed files with 22 additions and 38 deletions
|
@ -41,9 +41,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 + " "))
|
||||
|
@ -91,11 +90,8 @@ def run_config(
|
|||
for need in needed:
|
||||
if need == "":
|
||||
output(
|
||||
error(
|
||||
"Can not configure without {}".format(need),
|
||||
"No {}".format(need),
|
||||
)
|
||||
)
|
||||
error("Can not configure without {}".format(need),
|
||||
"No {}".format(need)))
|
||||
sys.exit(1)
|
||||
config[need] = input("Enter {}:".format(need))
|
||||
|
||||
|
@ -119,9 +115,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:
|
||||
|
@ -168,19 +165,13 @@ def setup_url(
|
|||
|
||||
if ttl and (not rtype or not name or not zone):
|
||||
output(
|
||||
error(
|
||||
"ttl only makes sense with rtype, name and zone",
|
||||
"Missing parameter",
|
||||
)
|
||||
)
|
||||
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",
|
||||
)
|
||||
)
|
||||
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"))
|
||||
|
@ -249,7 +240,7 @@ def main() -> int:
|
|||
mkdir(config_basepath)
|
||||
|
||||
if args.command == "config":
|
||||
run_config(config_filename, args.baseurl, args.username, args.password)
|
||||
run_config(args.baseurl, args.username, args.password)
|
||||
return 0
|
||||
|
||||
if not isfile(config_filename):
|
||||
|
@ -273,29 +264,23 @@ def main() -> int:
|
|||
|
||||
# Route based on command
|
||||
ttl = None
|
||||
if "ttl" in args:
|
||||
if 'ttl' in args:
|
||||
ttl = args.ttl
|
||||
if args.command != "update":
|
||||
args.argument = None
|
||||
if args.command == "add" and not ttl:
|
||||
if args.zone.endswith("."):
|
||||
if args.zone.endswith('.'):
|
||||
zname = args.zone
|
||||
else:
|
||||
zname = args.zone + "."
|
||||
soa_url = setup_url(baseurl, None, None, zname, "SOA", None, args.zone)
|
||||
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:
|
||||
url = setup_url(
|
||||
baseurl,
|
||||
args.argument,
|
||||
args.data,
|
||||
args.name,
|
||||
args.rtype,
|
||||
ttl,
|
||||
args.zone,
|
||||
)
|
||||
url = setup_url(baseurl, args.argument, args.data, args.name,
|
||||
args.rtype, ttl, args.zone)
|
||||
except AttributeError:
|
||||
parser.print_help(sys.stderr)
|
||||
return 1
|
||||
|
@ -311,8 +296,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…
Add table
Reference in a new issue