Instead of building all arguments for a request at the same time as the request itself is prepared, build them beforehand and then pass them to the corresponding function. This makes the code more readable, especially when complex params or long endpoints are involved. Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx> --- guests/quayadmin | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/guests/quayadmin b/guests/quayadmin index ed10bfc..e2b34e0 100755 --- a/guests/quayadmin +++ b/guests/quayadmin @@ -66,18 +66,26 @@ def has_error(quiet, res, expected, message): def run_list_repos(args): - res = get("/repository", params={"namespace": args.namespace}) + endpoint = "/repository" + params = { + "namespace": args.namespace, + } + + res = get(endpoint, params=params) if has_error(args.quiet, res, 200, "Cannot list repositories"): return 1 info = res.json() + for repo in info["repositories"]: print ("{}".format(repo["name"])) def run_show_repo(args): - res = get("/repository/{}/{}".format(args.namespace, args.repo)) + endpoint = "/repository/{}/{}".format(args.namespace, args.repo) + + res = get(endpoint) if has_error(args.quiet, res, 200, "Cannot query repository {}/{}" .format(args.namespace, args.repo)): @@ -92,13 +100,16 @@ def run_show_repo(args): def run_create_repo(args): - res = post("/repository", payload={ + endpoint = "/repository" + payload = { "repo_kind": "image", "namespace": args.namespace, "visibility": "public", "repository": args.repo, "description": args.desc, - }) + } + + res = post(endpoint, payload=payload) if has_error(args.quiet, res, 201, "Cannot create repository {}/{}" .format(args.namespace, args.repo)): @@ -109,7 +120,9 @@ def run_create_repo(args): def run_delete_repo(args): - res = delete("/repository/{}/{}".format(args.namespace, args.repo)) + endpoint = "/repository/{}/{}".format(args.namespace, args.repo) + + res = delete(endpoint) if has_error(args.quiet, res, 204, "Cannot delete repository {}/{}" .format(args.namespace, args.repo)): -- 2.21.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list