diff --git a/src/bindings/python/fluxacct/accounting/user_subcommands.py b/src/bindings/python/fluxacct/accounting/user_subcommands.py index ee43e3a0..9b45f92f 100755 --- a/src/bindings/python/fluxacct/accounting/user_subcommands.py +++ b/src/bindings/python/fluxacct/accounting/user_subcommands.py @@ -286,9 +286,19 @@ def clear_queues(conn, username, bank=None): # Subcommand Functions # # # ############################################################### -def view_user(conn, user, parseable=False, json_fmt=False): +def view_user(conn, user, parseable=False, json_fmt=False, list_banks=False): cur = conn.cursor() try: + if list_banks: + # just return the list of banks a user belongs to + cur.execute("SELECT bank FROM association_table WHERE username=?", (user,)) + result = cur.fetchall() + banks = "" + for bank in result: + banks += f"{str(bank[0])}\n" + + return banks + # get the information pertaining to a user in the DB cur.execute("SELECT * FROM association_table where username=?", (user,)) result = cur.fetchall() diff --git a/src/cmd/flux-account-service.py b/src/cmd/flux-account-service.py index e448354e..2a2fe04e 100755 --- a/src/cmd/flux-account-service.py +++ b/src/cmd/flux-account-service.py @@ -149,6 +149,7 @@ def view_user(self, handle, watcher, msg, arg): msg.payload["username"], msg.payload["parseable"], msg.payload["json"], + msg.payload["list_banks"], ) payload = {"view_user": val} diff --git a/src/cmd/flux-account.py b/src/cmd/flux-account.py index 63a5ef9a..0a010e86 100755 --- a/src/cmd/flux-account.py +++ b/src/cmd/flux-account.py @@ -53,6 +53,13 @@ def add_view_user_arg(subparsers): help="print all information of an association in JSON format", metavar="JSON", ) + subparser_view_user.add_argument( + "--list-banks", + action="store_const", + const=True, + help="list all of the banks a user belongs to", + metavar="LIST_BANKS", + ) def add_add_user_arg(subparsers): @@ -654,6 +661,7 @@ def select_accounting_function(args, output_file, parser): "username": args.username, "parseable": args.parseable, "json": args.json, + "list_banks": args.list_banks, } return_val = flux.Flux().rpc("accounting.view_user", data).get() elif args.func == "add_user":