Skip to content

Commit

Permalink
view-user: add --list-banks option
Browse files Browse the repository at this point in the history
Problem: There is no concise way to view the banks that a user belongs
to.

Add a --list-banks optional argument to view-user, which will just print
the banks that a user belongs to in the flux-accounting database.
  • Loading branch information
cmoussa1 committed Oct 4, 2024
1 parent eeefb0b commit 6bcd857
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/bindings/python/fluxacct/accounting/user_subcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions src/cmd/flux-account-service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
8 changes: 8 additions & 0 deletions src/cmd/flux-account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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":
Expand Down

0 comments on commit 6bcd857

Please sign in to comment.