From 7d113991a19cdd84b176dea757d29425186b5180 Mon Sep 17 00:00:00 2001 From: forest Date: Mon, 11 Apr 2022 15:12:32 -0500 Subject: [PATCH] redact emails & only report OOB accounts that have an active vm --- capsulflask/cli.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/capsulflask/cli.py b/capsulflask/cli.py index cd2dcc7..1db086c 100644 --- a/capsulflask/cli.py +++ b/capsulflask/cli.py @@ -246,7 +246,7 @@ def notify_users_about_account_balance(): balance_now = get_account_balance(vms, payments, datetime.utcnow()) current_warning = account['account_balance_warning'] - if balance_now < -11: + if balance_now < -11 and len(list(filter(lambda vm: vm['deleted'], vms))) > 0: out_of_bounds_accounts[account['email']] = balance_now longterm_vms = list(filter(lambda vm: vm['shortterm'] == False, vms)) @@ -288,10 +288,12 @@ def notify_users_about_account_balance(): get_model().delete_vm(email=account["email"], id=vm['id']) if len(out_of_bounds_accounts) > 0: + lines_redacted = ["The following accounts have out-of-bounds account balances: (Un-redacted email addresses avaliable in the logs)", ""] lines = ["The following accounts have out-of-bounds account balances:", ""] for email, balance in out_of_bounds_accounts.items(): lines.append(f"{email}: ${format(balance, '.2f')}") + lines_redacted.append(f"*******: ${format(balance, '.2f')}") email_addresses_raw = current_app.config['ADMIN_EMAIL_ADDRESSES'].split(",") email_addresses = list(filter(lambda x: len(x) > 6, map(lambda x: x.strip(), email_addresses_raw ) )) @@ -304,7 +306,7 @@ def notify_users_about_account_balance(): Message( "Capsul Out Of Bounds Account Balance Notification", sender=current_app.config["MAIL_DEFAULT_SENDER"], - body="\n".join(lines), + body="\n".join(lines_redacted), recipients=email_addresses ) )