From 4f552cb636252c77054879cc736555321084ff8c Mon Sep 17 00:00:00 2001 From: Jasmine Schladen Date: Tue, 20 Oct 2020 12:02:36 -0700 Subject: [PATCH] Code cleanup --- docs/administration.rst | 2 +- lemur/notifications/messaging.py | 4 ++-- lemur/plugins/lemur_aws/sns.py | 2 +- lemur/plugins/lemur_email/plugin.py | 10 ++++------ lemur/plugins/lemur_email/tests/test_email.py | 14 +++++++------- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/docs/administration.rst b/docs/administration.rst index ee504865..ef3f8e38 100644 --- a/docs/administration.rst +++ b/docs/administration.rst @@ -1462,7 +1462,7 @@ AWS (Destination) Uses AWS IAM as a destination for Lemur generated certificates. Support a multi-account deployment. -AWS (Notification) +AWS (SNS Notification) ----- :Authors: diff --git a/lemur/notifications/messaging.py b/lemur/notifications/messaging.py index 51c9f18a..1fce7636 100644 --- a/lemur/notifications/messaging.py +++ b/lemur/notifications/messaging.py @@ -107,6 +107,7 @@ def send_plugin_notification(event_type, data, recipients, notification): } status = FAILURE_METRIC_STATUS try: + current_app.logger.debug(log_data) notification.plugin.send(event_type, data, recipients, notification.options) status = SUCCESS_METRIC_STATUS except Exception as e: @@ -203,6 +204,7 @@ def send_default_notification(notification_type, data, targets, notification_opt ) try: + current_app.logger.debug(log_data) # we need the notification.options here because the email templates utilize the interval/unit info notification_plugin.send(notification_type, data, targets, notification_options) status = SUCCESS_METRIC_STATUS @@ -288,8 +290,6 @@ def needs_notification(certificate): raise Exception( f"Invalid base unit for expiration interval: {unit}" ) - print(f"Does cert {certificate.name} need a notification {notification.label}? Actual: {days}, " - f"configured: {interval}") # TODO REMOVE if days == interval: notifications.append(notification) return notifications diff --git a/lemur/plugins/lemur_aws/sns.py b/lemur/plugins/lemur_aws/sns.py index 96c44f28..3aeb14da 100644 --- a/lemur/plugins/lemur_aws/sns.py +++ b/lemur/plugins/lemur_aws/sns.py @@ -3,7 +3,7 @@ :platform: Unix :copyright: (c) 2020 by Netflix Inc., see AUTHORS for more :license: Apache, see LICENSE for more details. -.. moduleauthor:: Kevin Glisson +.. moduleauthor:: Jasmine Schladen """ import json diff --git a/lemur/plugins/lemur_email/plugin.py b/lemur/plugins/lemur_email/plugin.py index 62e6b2d4..5b9c188e 100644 --- a/lemur/plugins/lemur_email/plugin.py +++ b/lemur/plugins/lemur_email/plugin.py @@ -107,13 +107,11 @@ class EmailNotificationPlugin(ExpirationNotificationPlugin): s_type = current_app.config.get("LEMUR_EMAIL_SENDER", "ses").lower() - print(f"Would send {s_type} email to {targets}: {subject}") + if s_type == "ses": + send_via_ses(subject, body, targets) -# if s_type == "ses": - # send_via_ses(subject, body, targets) - - # elif s_type == "smtp": - # send_via_smtp(subject, body, targets) + elif s_type == "smtp": + send_via_smtp(subject, body, targets) @staticmethod def filter_recipients(options, excluded_recipients, **kwargs): diff --git a/lemur/plugins/lemur_email/tests/test_email.py b/lemur/plugins/lemur_email/tests/test_email.py index d7f7a17d..fd4dc575 100644 --- a/lemur/plugins/lemur_email/tests/test_email.py +++ b/lemur/plugins/lemur_email/tests/test_email.py @@ -81,10 +81,10 @@ def test_send_pending_failure_notification(user, pending_certificate, async_issu def test_filter_recipients(certificate, endpoint): from lemur.plugins.lemur_email.plugin import EmailNotificationPlugin - options = [{"name": "recipients", "value": "security@netflix.com,bob@netflix.com,joe@netflix.com"}] - assert EmailNotificationPlugin.filter_recipients(options, []) == ["security@netflix.com", "bob@netflix.com", - "joe@netflix.com"] - assert EmailNotificationPlugin.filter_recipients(options, ["security@netflix.com"]) == ["bob@netflix.com", - "joe@netflix.com"] - assert EmailNotificationPlugin.filter_recipients(options, ["security@netflix.com", "bob@netflix.com", - "joe@netflix.com"]) == [] + options = [{"name": "recipients", "value": "security@example.com,bob@example.com,joe@example.com"}] + assert EmailNotificationPlugin.filter_recipients(options, []) == ["security@example.com", "bob@example.com", + "joe@example.com"] + assert EmailNotificationPlugin.filter_recipients(options, ["security@example.com"]) == ["bob@example.com", + "joe@example.com"] + assert EmailNotificationPlugin.filter_recipients(options, ["security@example.com", "bob@example.com", + "joe@example.com"]) == []