redact emails & only report OOB accounts that have an active vm

This commit is contained in:
forest 2022-04-11 15:12:32 -05:00
parent 1376525c9e
commit 7d113991a1

View File

@ -246,7 +246,7 @@ def notify_users_about_account_balance():
balance_now = get_account_balance(vms, payments, datetime.utcnow()) balance_now = get_account_balance(vms, payments, datetime.utcnow())
current_warning = account['account_balance_warning'] 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 out_of_bounds_accounts[account['email']] = balance_now
longterm_vms = list(filter(lambda vm: vm['shortterm'] == False, vms)) 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']) get_model().delete_vm(email=account["email"], id=vm['id'])
if len(out_of_bounds_accounts) > 0: 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:", ""] lines = ["The following accounts have out-of-bounds account balances:", ""]
for email, balance in out_of_bounds_accounts.items(): for email, balance in out_of_bounds_accounts.items():
lines.append(f"{email}: ${format(balance, '.2f')}") 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_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 ) )) 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( Message(
"Capsul Out Of Bounds Account Balance Notification", "Capsul Out Of Bounds Account Balance Notification",
sender=current_app.config["MAIL_DEFAULT_SENDER"], sender=current_app.config["MAIL_DEFAULT_SENDER"],
body="\n".join(lines), body="\n".join(lines_redacted),
recipients=email_addresses recipients=email_addresses
) )
) )