diff --git a/galaxykit/cli_functions.py b/galaxykit/cli_functions.py new file mode 100644 index 0000000..904a3c4 --- /dev/null +++ b/galaxykit/cli_functions.py @@ -0,0 +1,78 @@ +from client import GalaxyClient, GalaxyClientError +import containers +import collections +import groups +import namespaces +import users + + +def format_list(data, identifier): + buffer = [] + for datum in data: + line = [datum[identifier]] + for key, value in datum.items(): + if key != identifier and value: + s = f"{key}={value}" + line.append(s) + buffer.append(" ".join(line)) + return "\n".join(buffer) + + +def get_client(args): + ignore = args.ignore + https_verify = not args.ignore_certs + return GalaxyClient( + args.server, (args.username, args.password), https_verify=https_verify + ) + + +## users +def user_list(args): + client = get_client(args) + resp = users.get_user_list(client) + print(format_list(resp["data"], "username")) + return resp + + +def user_create(args): + client = get_client(args) + if args.group: + args.group = groups.get_group(client, args.group) + created, resp = users.get_or_create_user( + client, + args.new_user, + args.new_password, + args.group, + fname=args.first_name, + lname=args.last_name, + email=args.email, + superuser=args.is_superuser, + ) + if created: + print("Created user", args.username) + else: + print(f"User {args.username} already existed") + return resp + + +def user_delete(args): + client = get_client(args) + users.delete_user(client, args.user_to_delete) + # there's no response from the above call, so we need to explicitly + # add a return that indicates success or failure here. + try: + users.get_user(client, args.user_to_delete) + print(f"Unable to delete user {args.user_to_delete}") + return False + except: + print(f"Successfully deleted user {args.user_to_delete}") + return True + + +# containers + +##groups + +##collections + +##namespaces diff --git a/galaxykit/client.py b/galaxykit/client.py index 4772921..e5b73de 100644 --- a/galaxykit/client.py +++ b/galaxykit/client.py @@ -8,10 +8,10 @@ import requests -from . import containers -from . import containerutils -from . import groups -from . import users +import containers +import containerutils +import groups +import users class GalaxyClientError(Exception): diff --git a/galaxykit/command-old.py b/galaxykit/command-old.py new file mode 100644 index 0000000..89bfa7a --- /dev/null +++ b/galaxykit/command-old.py @@ -0,0 +1,251 @@ +import argparse +import sys +import json + +from .client import GalaxyClient, GalaxyClientError +from . import containers +from . import collections +from . import groups +from . import namespaces +from . import users + +EXIT_OK = 0 +EXIT_UNKNOWN_ERROR = 1 +EXIT_NOT_FOUND = 2 +EXIT_DUPLICATE = 4 + + +def print_unknown_error(args): + print(f"Unknown {args.kind} operation '{args.operation}'") + sys.exit(EXIT_UNKNOWN_ERROR) + + +def format_list(data, identifier): + buffer = [] + for datum in data: + line = [datum[identifier]] + for key, value in datum.items(): + if key != identifier and value: + s = f"{key}={value}" + line.append(s) + buffer.append(" ".join(line)) + return "\n".join(buffer) + + +def report_error(resp): + if "errors" in resp: + for error in resp["errors"]: + print( + f"API Failure: HTTP {error['status']} {error['code']}; {error['title']} ({error['detail']})" + ) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument( + "kind", + type=str, + action="store", + help="Kind of API content to operate against (user, group, namespace)", + ) + parser.add_argument("operation", type=str, action="store") + parser.add_argument("rest", type=str, action="store", nargs="*") + parser.add_argument("-i", "--ignore", default=False, action="store_true") + parser.add_argument("-u", "--username", type=str, action="store") + parser.add_argument("-p", "--password", type=str, action="store") + parser.add_argument( + "-c", + "--ignore-certs", + default=False, + action="store_true", + help="Ignore invalid SSL certificates", + ) + parser.add_argument( + "-s", + "--server", + type=str, + action="store", + default="http://localhost:8002/api/automation-hub/", + ) + + args = parser.parse_args() + ignore = args.ignore + https_verify = not args.ignore_certs + client = GalaxyClient( + args.server, (args.username, args.password), https_verify=https_verify + ) + resp = None + + try: + if args.kind == "user": + if args.operation == "list": + resp = users.get_user_list(client) + print(format_list(resp["data"], "username")) + elif args.operation == "create": + username, password = args.rest + created, resp = users.get_or_create_user( + client, username, password, None + ) + if created: + print("Created user", username) + else: + print(f"User {username} already existed") + elif args.operation == "delete": + (username,) = args.rest + try: + resp = users.delete_user(client, username) + except ValueError as e: + if not args.ignore: + print(e) + sys.exit(EXIT_NOT_FOUND) + elif args.operation == "group": + subop, *subopargs = args.rest + if subop == "add": + username, groupname = subopargs + user_data = users.get_user(client, username) + group_id = groups.get_group_id(client, groupname) + user_data["groups"].append( + { + "id": group_id, + "name": groupname, + "pulp_href": f"/pulp/api/v3/groups/{group_id}", + } + ) + resp = users.update_user(client, user_data) + else: + print_unknown_error(args) + + elif args.kind == "group": + if args.operation == "list": + resp = groups.get_group_list(client) + print(format_list(resp["data"], "name")) + elif args.operation == "create": + (name,) = args.rest + resp = groups.create_group(client, name) + elif args.operation == "delete": + (name,) = args.rest + try: + resp = groups.delete_group(client, name) + except ValueError as e: + if not args.ignore: + print(e) + sys.exit(EXIT_NOT_FOUND) + elif args.operation == "perm": + subop, *subopargs = args.rest + if subop == "list": + (groupname,) = subopargs + resp = groups.get_permissions(client, groupname) + print(format_list(resp["data"], "permission")) + elif subop == "add": + groupname, perm = subopargs + perms = [ + p["permission"] + for p in groups.get_permissions(client, groupname)["data"] + ] + perms = list(set(perms) | set([perm])) + resp = groups.set_permissions(client, groupname, perms) + elif subop == "remove": + groupname, perm = subopargs + resp = groups.delete_permission(client, groupname, perm) + else: + print(f"Unknown group perm operation '{subop}'") + sys.exit(EXIT_UNKNOWN_ERROR) + else: + print_unknown_error(args) + + elif args.kind == "namespace": + if args.operation == "get": + (name,) = args.rest + print(json.dumps(namespaces.get_namespace(client, name))) + elif args.operation == "list-collections": + (name,) = args.rest + print(json.dumps(namespaces.get_namespace_collections(client, name))) + elif args.operation == "create": + if len(args.rest) == 2: + name, group = args.rest + else: + (name,) = args.rest + group = None + resp = namespaces.create_namespace(client, name, group) + elif args.operation == "delete": + raise NotImplementedError + elif args.operation == "groups": + raise NotImplementedError + elif args.operation == "addgroup": + name, group = args.rest + resp = namespaces.add_group(client, name, group) + elif args.operation == "removegroup": + name, group = args.rest + resp = namespaces.remove_group(client, name, group) + elif args.operation == "addgroupperm": + raise NotImplementedError + elif args.operation == "removegroupperm": + raise NotImplementedError + else: + print_unknown_error(args) + + elif args.kind == "container": + if args.operation == "readme": + if len(args.rest) == 1: + (container,) = args.rest + resp = containers.get_readme(client, container) + print(resp["text"]) + elif len(args.rest) == 2: + container, readme = args.rest + resp = containers.set_readme(client, container, readme) + else: + print("container readme takes either 1 or 2 parameters.") + sys.exit(EXIT_UNKNOWN_ERROR) + else: + print_unknown_error(args) + + elif args.kind == "collection": + if args.operation == "upload": + if len(args.rest) == 0: + (namespace, collection_name) = (client.username, None) + else: + (namespace, collection_name) = args.rest + + resp = namespaces.create_namespace(client, namespace, None) + artifact = collections.upload_test_collection( + client, namespace=namespace, collection_name=collection_name + ) + print(json.dumps(artifact)) + elif args.operation == "move": + if len(args.rest) == 2: + (namespace, collection_name) = args.rest + # defaults to version = 1.0.0, source = staging, destination = published + collections.move_collection(client, namespace, collection_name) + else: + ( + namespace, + collection_name, + version, + source, + destination, + ) = args.rest + collections.move_collection( + client, namespace, collection_name, version, source, destination + ) + else: + print_unknown_error(args) + + elif args.kind == "url": + if args.operation == "get": + (url,) = args.rest + print(json.dumps(client.get(url))) + elif args.operation == "post": + raise NotImplementedError + else: + print_unknown_error(args) + + else: + print(f"Unknown resource type '{args.kind}'") + sys.exit(EXIT_UNKNOWN_ERROR) + + if resp and not ignore: + report_error(resp) + + except GalaxyClientError: + if not ignore: + raise diff --git a/galaxykit/command.py b/galaxykit/command.py index 89bfa7a..6c60325 100644 --- a/galaxykit/command.py +++ b/galaxykit/command.py @@ -1,251 +1,306 @@ import argparse import sys import json +from typing import Collection +import cli_functions -from .client import GalaxyClient, GalaxyClientError -from . import containers -from . import collections -from . import groups -from . import namespaces -from . import users -EXIT_OK = 0 -EXIT_UNKNOWN_ERROR = 1 -EXIT_NOT_FOUND = 2 -EXIT_DUPLICATE = 4 +def parse_url(subparsers): + url_parser = subparsers.add_parser( + "url", help="subcommand for directly requesting a given URL." + ) + url_subparser = url_parser.add_subparsers() + + # url get parser + # -def print_unknown_error(args): - print(f"Unknown {args.kind} operation '{args.operation}'") - sys.exit(EXIT_UNKNOWN_ERROR) +def parse_collections(subparsers): + collection_parser = subparsers.add_parser("collection", help="collection help") + collection_subparser = collection_parser.add_subparsers() + # collection upload subcommand + # takes NO positional arguments + # optional arguments namespace and collection_name + collection_upload_parser = collection_subparser.add_parser( + "upload", help="upload a collection" + ) + collection_upload_parser.set_defaults(function="collection-upload") -def format_list(data, identifier): - buffer = [] - for datum in data: - line = [datum[identifier]] - for key, value in datum.items(): - if key != identifier and value: - s = f"{key}={value}" - line.append(s) - buffer.append(" ".join(line)) - return "\n".join(buffer) + collection_upload_parser.add_argument("--namespace", type=str) + collection_upload_parser.add_argument("--collection-name", type=str) + collection_upload_parser.add_argument("--version", type=str, default="1.0.0") + # collection move subcommand + # takes 2 positional arguments, namespace and collection_name + optional args + collection_move_parser = collection_subparser.add_parser( + "move", help="move a collection." + ) + collection_move_parser.set_defaults(function="collection-move") + collection_move_parser.add_argument("namespace", type=str) + collection_move_parser.add_argument("collection-name", type=str) + collection_move_parser.add_argument("--version", type=str, default="1.0.0") + collection_move_parser.add_argument("--source", type=str, default="staging") + collection_move_parser.add_argument("--destination", type=str, default="published") -def report_error(resp): - if "errors" in resp: - for error in resp["errors"]: - print( - f"API Failure: HTTP {error['status']} {error['code']}; {error['title']} ({error['detail']})" - ) + # collection delete subcommand + # takes 2 positional arguments, namespace and collection_name + optional args + collection_delete_parser = collection_subparser.add_parser( + "delete", help="delete a collection." + ) + collection_delete_parser.set_defaults(function="collection-delete") + collection_delete_parser.add_argument("namespace", type=str) + collection_delete_parser.add_argument("collection-name", type=str) + collection_delete_parser.add_argument("--version", type=str, default="1.0.0") + collection_delete_parser.add_argument("--repository", type=str, default="published") -def main(): - parser = argparse.ArgumentParser() - parser.add_argument( - "kind", +def parse_containers(subparsers): + container_parser = subparsers.add_parser( + "container", help="subcommand for manipulating container metadata" + ) + container_subparser = container_parser.add_subparsers() + + # get-readme subcommand + # takes 1 positional argument, which is the name of the container + container_get_readme_parser = container_subparser.add_parser( + "get-readme", help="Returns the readme for the given container." + ) + container_get_readme_parser.add_argument( + "container_name", help="name of container." + ) + container_get_readme_parser.set_defaults(function="container-get-readme") + + # set-readme subcommand + # takes 2 positional arguments, which are the name of the container and the new readme (a string) + container_set_readme_parser = container_subparser.add_parser( + "set-readme", + help="Sets the readme for the given container to the passed string.", + ) + container_set_readme_parser.add_argument( + "container_name", type=str, help="Name of container." + ) + container_set_readme_parser.add_argument( + "new_readme", type=str, help="String that will be set as new readme." + ) + container_set_readme_parser.set_defaults(function="container-set-readme") + + # delete subcommand + # takes just the name of the container as an argument + container_delete_parser = container_subparser.add_parser( + "delete", + help="Deletes a container", + ) + container_delete_parser.add_argument( + "container_name", type=str, help="Name of the container to delete" + ) + container_delete_parser.add_argument("image", type=str, help="Image tag to delete") + container_set_readme_parser.set_defaults(function="container-delete") + + +def parse_container_registries(subparsers): + container_registry_parser = subparsers.add_parser( + "container_registry", help="subcommand for manipulating container registries" + ) + container_registry_subparser = container_parser.add_subparsers() + container_registry_delete_parser = container_registry_subparser.add_parser( + "delete", help="Delete a given container registry." + ) + + container_registry_delete_parser.add_argument( + "registry_name", help="Name of the registry to delete." + ) + container_registry_delete_parser.set_defaults(function="container-registry-delete") + + +def parse_groups(subparsers): + + group_parser = subparsers.add_parser( + "group", help="List, create, delete, edit permissions of groups." + ) + group_subparser = group_parser.add_subparsers() + + # group list subcommand + group_list_parser = group_subparser.add_parser("list", help="List all groups") + group_list_parser.set_defaults(function="group-list") + + # group create + group_create_parser = group_subparser.add_parser( + "create", help="create a group with given name" + ) + group_create_parser.add_argument( + "group_name", type=str, help="name of group to be created." + ) + group_create_parser.set_defaults(function="group-create") + + # group delete + group_delete_parser = group_subparser.add_parser( + "delete", help="delete a group with given name" + ) + group_delete_parser.add_argument( + "group_name", type=str, help="name of group to be deleted." + ) + group_delete_parser.set_defaults(function="group-delete") + + # permissions subcommands + + # group perm list + + group_perm_list_parser = subparsers.add_parser("perm-list") + + group_perm_list_parser.add_argument("group_name") + group_perm_list_parser.set_defaults(function="group-perm-list") + + # group perm add + group_perm_add_parser = subparsers.add_parser("perm-add") + group_perm_add_parser.add_argument("group_name") + group_perm_add_parser.add_argument("permission_name") + group_perm_add_parser.set_defaults(function="group-perm-add") + + # group perm remove + group_perm_remove_parser = subparsers.add_parser("perm-remove") + group_perm_remove_parser.add_argument("group_name") + group_perm_remove_parser.add_argument("permission_name") + group_perm_remove_parser.set_defaults(function="group-perm-remove") + + +def parse_namespaces(subparsers): + """ + # TODO: implement these down the line + "delete": + "groups": + "addgroupperm": + "removegroupperm": + """ + + namespace_parser = subparsers.add_parser("namespace", help="namespace help") + namespace_subparser = namespace_parser.add_subparsers() + + # 'namespace get' subcommand + namespace_get_parser = namespace_subparser.add_parser( + "get", help="Get namespace metadata." + ) + namespace_get_parser.set_defaults(function="namespace-get") + namespace_get_parser.add_argument( + "namespace", type=str, - action="store", - help="Kind of API content to operate against (user, group, namespace)", ) - parser.add_argument("operation", type=str, action="store") - parser.add_argument("rest", type=str, action="store", nargs="*") + + # list Collections subcommand + namespace_list_parser = namespace_subparser.add_parser( + "list-collections", help="Get namespace collections." + ) + namespace_list_parser.set_defaults(function="namespace-get-collections") + namespace_list_parser.add_argument( + "namespace", + type=str, + ) + + # create a namespace subcommand + namespace_create_parser = namespace_subparser.add_parser( + "create", help="Create a namespace" + ) + namespace_create_parser.set_defaults(function="namespace-create") + namespace_create_parser.add_argument( + "namespace", + type=str, + ) + + # add group to a namespace subcommand + namespace_add_group_parser = namespace_subparser.add_parser("add-group") + namespace_add_group_parser.set_defaults(function="namespace-add-group") + namespace_add_group_parser.add_argument( + "namespace", type=str, help="Namespace name." + ) + namespace_add_group_parser.add_argument("group", type=str, help="Namespace group.") + + # remove group from a namespace subcommand + namespace_remove_group_parser = namespace_subparser.add_parser("remove-group") + namespace_remove_group_parser.set_defaults(function="namespace-remove-group") + namespace_remove_group_parser.add_argument( + "namespace", type=str, help="Namespace name." + ) + + namespace_add_group_parser.add_argument("group", type=str, help="Namespace group.") + + +def parse_user(subparsers): + user_parser = subparsers.add_parser("user", help="user help") + user_subparser = user_parser.add_subparsers() + + # 'user list' subcommand + user_list_parser = user_subparser.add_parser("list") + user_list_parser.set_defaults(function=cli_functions.user_list) + + # 'user create' subcommand + user_create_parser = user_subparser.add_parser("create") + user_create_parser.add_argument( + "new_user", type=str, help="username of the user to be created." + ) + user_create_parser.add_argument( + "new_password", type=str, help="password of the user to be created." + ) + user_create_parser.add_argument( + "--email", type=str, help="email of the user to be created.", default="" + ) + user_create_parser.add_argument( + "--first-name", + type=str, + help="first name of the user to be created.", + default="", + ) + user_create_parser.add_argument( + "--last-name", type=str, help="last name of the user to be created.", default="" + ) + user_create_parser.add_argument( + "--is-superuser", + help="make a superuser.", + action="store_true", + default=False, + ) + user_create_parser.add_argument("--group", type=str, help="add user to a group.") + user_create_parser.set_defaults(function=cli_functions.user_create) + + # 'user delete' subcommand + user_delete_parser = user_subparser.add_parser("delete") + user_delete_parser.add_argument( + "user_to_delete", type=str, help="username of the user to be deleted." + ) + user_delete_parser.set_defaults(function=cli_functions.user_delete) + + +def test(command_to_test): + parser = argparse.ArgumentParser(prog="galaxykit") + subparsers = parser.add_subparsers() + parser.add_argument("-i", "--ignore", default=False, action="store_true") - parser.add_argument("-u", "--username", type=str, action="store") - parser.add_argument("-p", "--password", type=str, action="store") + parser.add_argument("-u", "--username", default="admin", type=str, action="store") + parser.add_argument("-p", "--password", default="admin", type=str, action="store") parser.add_argument( "-c", "--ignore-certs", - default=False, action="store_true", + default=False, help="Ignore invalid SSL certificates", ) parser.add_argument( "-s", "--server", - type=str, action="store", default="http://localhost:8002/api/automation-hub/", + type=str, ) - args = parser.parse_args() - ignore = args.ignore - https_verify = not args.ignore_certs - client = GalaxyClient( - args.server, (args.username, args.password), https_verify=https_verify - ) - resp = None - - try: - if args.kind == "user": - if args.operation == "list": - resp = users.get_user_list(client) - print(format_list(resp["data"], "username")) - elif args.operation == "create": - username, password = args.rest - created, resp = users.get_or_create_user( - client, username, password, None - ) - if created: - print("Created user", username) - else: - print(f"User {username} already existed") - elif args.operation == "delete": - (username,) = args.rest - try: - resp = users.delete_user(client, username) - except ValueError as e: - if not args.ignore: - print(e) - sys.exit(EXIT_NOT_FOUND) - elif args.operation == "group": - subop, *subopargs = args.rest - if subop == "add": - username, groupname = subopargs - user_data = users.get_user(client, username) - group_id = groups.get_group_id(client, groupname) - user_data["groups"].append( - { - "id": group_id, - "name": groupname, - "pulp_href": f"/pulp/api/v3/groups/{group_id}", - } - ) - resp = users.update_user(client, user_data) - else: - print_unknown_error(args) - - elif args.kind == "group": - if args.operation == "list": - resp = groups.get_group_list(client) - print(format_list(resp["data"], "name")) - elif args.operation == "create": - (name,) = args.rest - resp = groups.create_group(client, name) - elif args.operation == "delete": - (name,) = args.rest - try: - resp = groups.delete_group(client, name) - except ValueError as e: - if not args.ignore: - print(e) - sys.exit(EXIT_NOT_FOUND) - elif args.operation == "perm": - subop, *subopargs = args.rest - if subop == "list": - (groupname,) = subopargs - resp = groups.get_permissions(client, groupname) - print(format_list(resp["data"], "permission")) - elif subop == "add": - groupname, perm = subopargs - perms = [ - p["permission"] - for p in groups.get_permissions(client, groupname)["data"] - ] - perms = list(set(perms) | set([perm])) - resp = groups.set_permissions(client, groupname, perms) - elif subop == "remove": - groupname, perm = subopargs - resp = groups.delete_permission(client, groupname, perm) - else: - print(f"Unknown group perm operation '{subop}'") - sys.exit(EXIT_UNKNOWN_ERROR) - else: - print_unknown_error(args) - - elif args.kind == "namespace": - if args.operation == "get": - (name,) = args.rest - print(json.dumps(namespaces.get_namespace(client, name))) - elif args.operation == "list-collections": - (name,) = args.rest - print(json.dumps(namespaces.get_namespace_collections(client, name))) - elif args.operation == "create": - if len(args.rest) == 2: - name, group = args.rest - else: - (name,) = args.rest - group = None - resp = namespaces.create_namespace(client, name, group) - elif args.operation == "delete": - raise NotImplementedError - elif args.operation == "groups": - raise NotImplementedError - elif args.operation == "addgroup": - name, group = args.rest - resp = namespaces.add_group(client, name, group) - elif args.operation == "removegroup": - name, group = args.rest - resp = namespaces.remove_group(client, name, group) - elif args.operation == "addgroupperm": - raise NotImplementedError - elif args.operation == "removegroupperm": - raise NotImplementedError - else: - print_unknown_error(args) - - elif args.kind == "container": - if args.operation == "readme": - if len(args.rest) == 1: - (container,) = args.rest - resp = containers.get_readme(client, container) - print(resp["text"]) - elif len(args.rest) == 2: - container, readme = args.rest - resp = containers.set_readme(client, container, readme) - else: - print("container readme takes either 1 or 2 parameters.") - sys.exit(EXIT_UNKNOWN_ERROR) - else: - print_unknown_error(args) - - elif args.kind == "collection": - if args.operation == "upload": - if len(args.rest) == 0: - (namespace, collection_name) = (client.username, None) - else: - (namespace, collection_name) = args.rest - - resp = namespaces.create_namespace(client, namespace, None) - artifact = collections.upload_test_collection( - client, namespace=namespace, collection_name=collection_name - ) - print(json.dumps(artifact)) - elif args.operation == "move": - if len(args.rest) == 2: - (namespace, collection_name) = args.rest - # defaults to version = 1.0.0, source = staging, destination = published - collections.move_collection(client, namespace, collection_name) - else: - ( - namespace, - collection_name, - version, - source, - destination, - ) = args.rest - collections.move_collection( - client, namespace, collection_name, version, source, destination - ) - else: - print_unknown_error(args) - - elif args.kind == "url": - if args.operation == "get": - (url,) = args.rest - print(json.dumps(client.get(url))) - elif args.operation == "post": - raise NotImplementedError - else: - print_unknown_error(args) - - else: - print(f"Unknown resource type '{args.kind}'") - sys.exit(EXIT_UNKNOWN_ERROR) - - if resp and not ignore: - report_error(resp) - - except GalaxyClientError: - if not ignore: - raise + # parsing for subcommands + parse_collections(subparsers) + parse_containers(subparsers) + parse_groups(subparsers) + parse_namespaces(subparsers) + parse_user(subparsers) + + command_to_test = command_to_test.split(" ") + args = parser.parse_args(command_to_test) + args.function(args) + + +breakpoint() diff --git a/galaxykit/namespaces.py b/galaxykit/namespaces.py index dc16b9a..3942078 100644 --- a/galaxykit/namespaces.py +++ b/galaxykit/namespaces.py @@ -1,4 +1,4 @@ -from . import groups +import groups def create_namespace(client, name, group): diff --git a/galaxykit/users.py b/galaxykit/users.py index 129ca19..eca7886 100644 --- a/galaxykit/users.py +++ b/galaxykit/users.py @@ -23,7 +23,9 @@ def get_or_create_user( user_url = f"_ui/v1/users?username={username}" user_resp = client.get(user_url) if user_resp["meta"]["count"] == 0: - return True, create_user(client, username, password, group, fname, lname, email) + return True, create_user( + client, username, password, group, fname, lname, email, superuser + ) return False, user_resp["data"][0] @@ -90,11 +92,14 @@ def get_user_id(client, username): def get_user(client, username): """ - Returns the id for a given username + Returns user data for a given username """ user_url = f"_ui/v1/users/?username={username}" user_resp = client.get(user_url) - return user_resp["data"][0] + if user_resp["data"] is not []: + return user_resp["data"][0] + else: + return None def get_user_list(client):