Refactors how notifications are generated. (#584)
This commit is contained in:
@ -28,7 +28,7 @@ def render_html(template_name, message):
|
||||
:return:
|
||||
"""
|
||||
template = env.get_template('{}.html'.format(template_name))
|
||||
return template.render(dict(messages=message, hostname=current_app.config.get('LEMUR_HOSTNAME')))
|
||||
return template.render(dict(message=message, hostname=current_app.config.get('LEMUR_HOSTNAME')))
|
||||
|
||||
|
||||
def send_via_smtp(subject, body, targets):
|
||||
@ -86,9 +86,11 @@ class EmailNotificationPlugin(ExpirationNotificationPlugin):
|
||||
|
||||
@staticmethod
|
||||
def send(notification_type, message, targets, options, **kwargs):
|
||||
|
||||
subject = 'Lemur: {0} Notification'.format(notification_type.capitalize())
|
||||
|
||||
body = render_html(notification_type, message)
|
||||
data = {'options': options, 'certificates': message}
|
||||
body = render_html(notification_type, data)
|
||||
|
||||
s_type = current_app.config.get("LEMUR_EMAIL_SENDER", 'ses').lower()
|
||||
|
||||
|
@ -2,6 +2,8 @@ import os
|
||||
import arrow
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
from lemur.plugins.utils import get_plugin_option
|
||||
|
||||
loader = FileSystemLoader(searchpath=os.path.dirname(os.path.realpath(__file__)))
|
||||
env = Environment(loader=loader)
|
||||
|
||||
@ -10,4 +12,14 @@ def human_time(time):
|
||||
return arrow.get(time).format('dddd, MMMM D, YYYY')
|
||||
|
||||
|
||||
def interval(options):
|
||||
return get_plugin_option('interval', options)
|
||||
|
||||
|
||||
def unit(options):
|
||||
return get_plugin_option('unit', options)
|
||||
|
||||
|
||||
env.filters['time'] = human_time
|
||||
env.filters['interval'] = interval
|
||||
env.filters['unit'] = unit
|
||||
|
@ -43,7 +43,7 @@
|
||||
<tr>
|
||||
<td width="32px"></td>
|
||||
<td style="font-family:Roboto-Regular,Helvetica,Arial,sans-serif;font-size:24px;color:#ffffff;line-height:1.25">
|
||||
Your certificate(s) are expiring!
|
||||
Your certificate(s) are expiring in {{ message.options | interval }} {{ message.options | unit }}!
|
||||
</td>
|
||||
<td width="32px"></td>
|
||||
</tr>
|
||||
@ -79,7 +79,7 @@
|
||||
<table border="0" cellspacing="0" cellpadding="0"
|
||||
style="margin-top:48px;margin-bottom:48px">
|
||||
<tbody>
|
||||
{% for certificate in certificates %}
|
||||
{% for certificate in message.certificates %}
|
||||
<tr valign="middle">
|
||||
<td width="32px"></td>
|
||||
<td width="16px"></td>
|
||||
|
@ -12,12 +12,15 @@ def test_render(certificate, endpoint):
|
||||
new_cert = CertificateFactory()
|
||||
new_cert.replaces.append(certificate)
|
||||
|
||||
certificates = [certificate_notification_output_schema.dump(certificate).data]
|
||||
data = {
|
||||
'certificates': [certificate_notification_output_schema.dump(certificate).data],
|
||||
'options': [{'name': 'interval', 'value': 10}, {'name': 'unit', 'value': 'days'}]
|
||||
}
|
||||
|
||||
template = env.get_template('{}.html'.format('expiration'))
|
||||
|
||||
with open(os.path.join(dir_path, 'expiration-rendered.html'), 'w') as f:
|
||||
body = template.render(dict(certificates=certificates, hostname='lemur.test.example.com'))
|
||||
body = template.render(dict(message=data, hostname='lemur.test.example.com'))
|
||||
f.write(body)
|
||||
|
||||
template = env.get_template('{}.html'.format('rotation'))
|
||||
|
Reference in New Issue
Block a user