Condense sending notifications

This commit is contained in:
Jasmine Schladen 2020-11-13 20:10:21 -08:00
parent 79094e782d
commit db11f0c1b7
1 changed files with 12 additions and 18 deletions

View File

@ -153,29 +153,23 @@ def send_expiration_notifications(exclude):
).data ).data
notification_data.append(cert_data) notification_data.append(cert_data)
email_recipients = security_email + [owner] email_recipients = notification.plugin.get_recipients(notification.options, security_email + [owner])
if notification.plugin.slug == "email-notification": # Plugin will ONLY use the provided recipients if it's email; any other notification plugin ignores them
email_recipients = notification.plugin.get_recipients(notification.options, email_recipients)
if send_plugin_notification( if send_plugin_notification(
"expiration", notification_data, email_recipients, notification "expiration", notification_data, email_recipients, notification
): ):
success += len(email_recipients) success += len(email_recipients)
else: else:
failure += len(email_recipients) failure += len(email_recipients)
else: # If we're using an email plugin, we're done;
# if not, we also need to send an email notification to the security team and owner
if notification.plugin.slug != "email-notification":
if send_default_notification( if send_default_notification(
"expiration", notification_data, email_recipients, notification.options "expiration", notification_data, email_recipients, notification.options
): ):
success += len(email_recipients) success = 1 + len(email_recipients)
else: else:
failure += len(email_recipients) failure = 1 + len(email_recipients)
if send_plugin_notification(
"expiration", notification_data, [], notification
):
success += 1
else:
failure += 1
return success, failure return success, failure