diff --git a/notifier/.s2i/bin/assemble b/notifier/.s2i/bin/assemble new file mode 100755 index 000000000..4e989c84b --- /dev/null +++ b/notifier/.s2i/bin/assemble @@ -0,0 +1,6 @@ +#!/bin/bash + +npm install -g npm@8.19.3 +npm install -g mjml@4.13.0 + +exec /usr/libexec/s2i/assemble \ No newline at end of file diff --git a/notifier/Containerfile b/notifier/Containerfile index bf35962b0..2a8880de1 100644 --- a/notifier/Containerfile +++ b/notifier/Containerfile @@ -9,10 +9,11 @@ RUN dnf install -y ruby ruby-libs && \ rm -rf /tmp/src/.git* && \ chown -R 1001 /tmp/src && \ chgrp -R 0 /tmp/src && \ - chmod -R g+w /tmp/src + chmod -R g+w /tmp/src \ + cp -rp /tmp/src/.s2i/bin /tmp/scripts USER 1001 -RUN /usr/libexec/s2i/assemble +RUN /tmp/scripts/assemble CMD ["/usr/libexec/s2i/run"] diff --git a/notifier/devfile.yaml b/notifier/devfile.yaml index 248f79961..9b73ddb65 100644 --- a/notifier/devfile.yaml +++ b/notifier/devfile.yaml @@ -1,6 +1,7 @@ commands: - exec: - commandLine: /usr/libexec/s2i/assemble + commandLine: >- + rm -rf /tmp/src && cp /tmp/projects -r /tmp/src && /tmp/src/.s2i/bin/assemble component: s2i-builder group: isDefault: true diff --git a/notifier/operator/operator.py b/notifier/operator/operator.py index fb40d89bb..ab4ff6dc4 100755 --- a/notifier/operator/operator.py +++ b/notifier/operator/operator.py @@ -766,6 +766,7 @@ async def send_notification_email( ) ) template_vars['have_attachments'] = len(attachments) > 0 + template_vars['service_status'] = ' '.join(elem.capitalize() for elem in template.replace('-', ' ').split()) email_subject = j2env.from_string(subject).render(**template_vars) @@ -775,11 +776,11 @@ async def send_notification_email( message_template = catalog_item.get_message_template(kebabToCamelCase(template)) if message_template: try: - email_body = j2env.from_string(message_template).render(**template_vars) + mjml_template = j2env.from_string(message_template).render(**template_vars) except Exception as exception: logger.warning(f"Failed to render template: {exception}") - email_body = j2env.get_template(template + '.html.j2').render(**template_vars) - email_body += ( + mjml_template = j2env.get_template(template + '.html.j2').render(**template_vars) + mjml_template += ( "

Attention: " "A custom message template was configured for your service, " "but unfortunately, rendering failed with the following error:

" @@ -787,7 +788,14 @@ async def send_notification_email( "

The content shown above is the default message template.

" ) else: - email_body = j2env.get_template(template + '.html.j2').render(**template_vars) + mjml_template = j2env.get_template(template + '.mjml.j2').render(**template_vars) + + # Call for the MJML CLI to generate final HTML + email_body = subprocess.run( + ['mjml', '-i'], + stdout=subprocess.PIPE, + input=mjml_template, + encoding='ascii').stdout msg = MIMEMultipart('alternative') msg['Subject'] = email_subject diff --git a/notifier/operator/templates/base.mjml.j2 b/notifier/operator/templates/base.mjml.j2 new file mode 100644 index 000000000..f4c84ddec --- /dev/null +++ b/notifier/operator/templates/base.mjml.j2 @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + Status: {{ service_status }} + + + {{ service_display_name }} + + + from {{ catalog_namespace.display_name }} + + + + + + + + + + + + + {% block content %}{% endblock %} + + + + + + + RedHat + © Copyright 2022 - All rights reserved + + + + + + diff --git a/notifier/operator/templates/provision-failed.html.j2 b/notifier/operator/templates/provision-failed.html.j2 deleted file mode 100644 index 5d1afdb27..000000000 --- a/notifier/operator/templates/provision-failed.html.j2 +++ /dev/null @@ -1,10 +0,0 @@ -

Your {{ catalog_namespace.display_name }} service, {{ service_display_name }}, has failed to provision. -{% if have_attachments %} -Please see attached Ansible log. -{% endif %} -

- -{% if service_url %} -

You may manage your {{ catalog_namespace.display_name }} service at:
-{{ service_url }}.

-{% endif %} diff --git a/notifier/operator/templates/provision-failed.mjml.j2 b/notifier/operator/templates/provision-failed.mjml.j2 new file mode 100644 index 000000000..bfabc02bb --- /dev/null +++ b/notifier/operator/templates/provision-failed.mjml.j2 @@ -0,0 +1,21 @@ +{% extends "base.mjml.j2" %} +{% block content %} + + + + +

Your {{ catalog_namespace.display_name }} service, {{ service_display_name }}, has failed to provision. + {% if have_attachments %} + Please see attached Ansible log. + {% endif %} +

+ + {% if service_url %} +

You may manage your {{ catalog_namespace.display_name }} service at:
+ {{ service_url }}.

+ {% endif %} + +
+
+ +{% endblock content %} \ No newline at end of file diff --git a/notifier/operator/templates/provision-started.html.j2 b/notifier/operator/templates/provision-started.html.j2 deleted file mode 100644 index 47c44686a..000000000 --- a/notifier/operator/templates/provision-started.html.j2 +++ /dev/null @@ -1,14 +0,0 @@ -

Thank you for ordering {{ catalog_item.display_name }}.

- -

Provisioning has started on your {{ catalog_namespace.display_name }} service, {{ service_display_name }}.

- -

You will receive more information via email when the provisioning completes in about {{ provision_time_estimate }}.

- -

Please note that the environment is set to auto-stop at {{ stop_timestamp }} and auto-destroy at {{ retirement_timestamp }}.

- -

You can change the auto-stop and auto-destroy time in UI.

- -{% if service_url %} -

You may manage your {{ catalog_namespace.display_name }} service at:
-{{ service_url }}.

-{% endif %} diff --git a/notifier/operator/templates/provision-started.mjml.j2 b/notifier/operator/templates/provision-started.mjml.j2 new file mode 100644 index 000000000..fd87a72d7 --- /dev/null +++ b/notifier/operator/templates/provision-started.mjml.j2 @@ -0,0 +1,25 @@ +{% extends "base.mjml.j2" %} +{% block content %} + + + + +

Thank you for ordering {{ catalog_item.display_name }}.

+ +

Provisioning has started on your {{ catalog_namespace.display_name }} service, {{ service_display_name }}.

+ +

You will receive more information via email when the provisioning completes in about {{ provision_time_estimate }}.

+ +

Please note that the environment is set to auto-stop at {{ stop_timestamp }} and auto-destroy at {{ retirement_timestamp }}.

+ +

You can change the auto-stop and auto-destroy time in UI.

+ + {% if service_url %} +

You may manage your {{ catalog_namespace.display_name }} service at:
+ {{ service_url }}.

+ {% endif %} + +
+
+ +{% endblock content %} \ No newline at end of file diff --git a/notifier/operator/templates/retirement-scheduled.html.j2 b/notifier/operator/templates/retirement-scheduled.html.j2 deleted file mode 100644 index c527f4d8a..000000000 --- a/notifier/operator/templates/retirement-scheduled.html.j2 +++ /dev/null @@ -1,7 +0,0 @@ -

Reminder:
-Your environment will expire and be deleted in {{ retirement_timedelta_humanized }} at {{ retirement_timestamp }}.

- -{% if service_url %} -

You may manage your {{ catalog_namespace.display_name }} service at:
-{{ service_url }}.

-{% endif %} diff --git a/notifier/operator/templates/retirement-scheduled.mjml.j2 b/notifier/operator/templates/retirement-scheduled.mjml.j2 new file mode 100644 index 000000000..f7eda84bf --- /dev/null +++ b/notifier/operator/templates/retirement-scheduled.mjml.j2 @@ -0,0 +1,18 @@ +{% extends "base.mjml.j2" %} +{% block content %} + + + + +

Reminder:
+ Your environment will expire and be deleted in {{ retirement_timedelta_humanized }} at {{ retirement_timestamp }}.

+ + {% if service_url %} +

You may manage your {{ catalog_namespace.display_name }} service at:
+ {{ service_url }}.

+ {% endif %} + +
+
+ +{% endblock content %} \ No newline at end of file diff --git a/notifier/operator/templates/service-deleted.html.j2 b/notifier/operator/templates/service-deleted.html.j2 deleted file mode 100644 index 70878bcaa..000000000 --- a/notifier/operator/templates/service-deleted.html.j2 +++ /dev/null @@ -1,9 +0,0 @@ -

Your {{ catalog_namespace.display_name }} service {{ service_display_name }} has been deleted.

- -

To conserve resources data on these systems is not archived and cannot be retrieved. -We apologize for any inconvenience this may cause. -Thank you for using {{ catalog_namespace.display_name }}.

- -{% if survey_link %} -

We would love your feedback on your demo/lab, please fill out our short Survey (click here) to help us improve your experience.

-{% endif %} diff --git a/notifier/operator/templates/service-deleted.mjml.j2 b/notifier/operator/templates/service-deleted.mjml.j2 new file mode 100644 index 000000000..fe4ed5e4c --- /dev/null +++ b/notifier/operator/templates/service-deleted.mjml.j2 @@ -0,0 +1,21 @@ +{% extends "base.mjml.j2" %} +{% block content %} + + + + +

Your {{ catalog_namespace.display_name }} service {{ service_display_name }} has been deleted.

+ +

To conserve resources data on these systems is not archived and cannot be retrieved. + We apologize for any inconvenience this may cause.

+ +

Thank you for using {{ catalog_namespace.display_name }}.

+ + {% if survey_link %} +

We would love your feedback on your demo/lab, please fill out our short Survey (click here) to help us improve your experience.

+ {% endif %} + +
+
+ +{% endblock content %} \ No newline at end of file diff --git a/notifier/operator/templates/service-ready.html.j2 b/notifier/operator/templates/service-ready.html.j2 deleted file mode 100644 index fbe45e02c..000000000 --- a/notifier/operator/templates/service-ready.html.j2 +++ /dev/null @@ -1,26 +0,0 @@ -

Thank you for ordering {{ catalog_item.display_name }}.

- -

Your {{ catalog_namespace.display_name }} service {{ service_display_name }} is ready.

- -

Please refer to the instructions for next steps and how to access your environment.

- -

Troubleshooting and Access issues:

- -

Always refer to the instructions to understand how to properly access and navigate your environment.

- -

NOTICE:
-Your environment will be stopped in {{ stop_timedelta_humanized }} at {{ stop_timestamp }}.
-Your environment will expire and be deleted in {{ retirement_timedelta_humanized }} at {{ retirement_timestamp }}.

- -

In order to conserve resources, we cannot archive or restore any data in this environment. -All data will be lost upon expiration.

- -{% if provision_messages is defined %} -

Here is some important information about your environment:

-{{ provision_messages_html }} -{% endif %} - -{% if service_url %} -

You may manage your {{ catalog_namespace.display_name }} service at:
-{{ service_url }}.

-{% endif %} diff --git a/notifier/operator/templates/service-ready.mjml.j2 b/notifier/operator/templates/service-ready.mjml.j2 new file mode 100644 index 000000000..5914d0916 --- /dev/null +++ b/notifier/operator/templates/service-ready.mjml.j2 @@ -0,0 +1,36 @@ +{% extends "base.mjml.j2" %} +{% block content %} + + + +

Thank you for ordering {{ catalog_item.display_name }}.

+ +

Your {{ catalog_namespace.display_name }} service {{ service_display_name }} is ready.

+ +

Please refer to the instructions for next steps and how to access your environment.

+ +

Troubleshooting and Access issues:

+ +

Always refer to the instructions to understand how to properly access and navigate your environment.

+ +

NOTICE:
+ Your environment will be stopped in {{ stop_timedelta_humanized }} at {{ stop_timestamp }}.
+ Your environment will expire and be deleted in {{ retirement_timedelta_humanized }} at {{ retirement_timestamp }}.

+ +

In order to conserve resources, we cannot archive or restore any data in this environment. + All data will be lost upon expiration.

+ + {% if provision_messages is defined %} +

Here is some important information about your environment:

+ {{ provision_messages_html }} + {% endif %} + + {% if service_url %} +

You may manage your {{ catalog_namespace.display_name }} service at:
+ {{ service_url }}.

+ {% endif %} + +
+
+ +{% endblock content %} \ No newline at end of file diff --git a/notifier/operator/templates/start-complete.html.j2 b/notifier/operator/templates/start-complete.html.j2 deleted file mode 100644 index c08b6e191..000000000 --- a/notifier/operator/templates/start-complete.html.j2 +++ /dev/null @@ -1,10 +0,0 @@ -

Your {{ catalog_namespace.display_name }} service {{ service_display_name }} has started.

- -

NOTICE:
-Your environment will be stopped in {{ stop_timedelta_humanized }} at {{ stop_timestamp }}.
-Your environment will expire and be deleted in {{ retirement_timedelta_humanized }} at {{ retirement_timestamp }}.

- -{% if service_url %} -

You may manage your {{ catalog_namespace.display_name }} service at:
-{{ service_url }}.

-{% endif %} diff --git a/notifier/operator/templates/start-complete.mjml.j2 b/notifier/operator/templates/start-complete.mjml.j2 new file mode 100644 index 000000000..7166929b8 --- /dev/null +++ b/notifier/operator/templates/start-complete.mjml.j2 @@ -0,0 +1,25 @@ +{% extends "base.mjml.j2" %} +{% block content %} + + + + +

Your {{ catalog_namespace.display_name }} service {{ service_display_name }} has started.

+ +

+ NOTICE:
+

+

+ + {% if service_url %} +

You may manage your {{ catalog_namespace.display_name }} service at:
+ {{ service_url }}.

+ {% endif %} + +
+
+ +{% endblock content %} \ No newline at end of file diff --git a/notifier/operator/templates/start-failed.html.j2 b/notifier/operator/templates/start-failed.html.j2 deleted file mode 100644 index 5371acfe9..000000000 --- a/notifier/operator/templates/start-failed.html.j2 +++ /dev/null @@ -1,10 +0,0 @@ -

Your {{ catalog_namespace.display_name }} service {{ service_display_name }} failed to start. -{% if have_attachments %} -Please see attached Ansible log. -{% endif %} -

- -{% if service_url %} -

You may manage your {{ catalog_namespace.display_name }} service at:
-{{ service_url }}.

-{% endif %} diff --git a/notifier/operator/templates/start-failed.mjml.j2 b/notifier/operator/templates/start-failed.mjml.j2 new file mode 100644 index 000000000..204de93c0 --- /dev/null +++ b/notifier/operator/templates/start-failed.mjml.j2 @@ -0,0 +1,21 @@ +{% extends "base.mjml.j2" %} +{% block content %} + + + + +

Your {{ catalog_namespace.display_name }} service {{ service_display_name }} failed to start. + {% if have_attachments %} + Please see attached Ansible log. + {% endif %} +

+ + {% if service_url %} +

You may manage your {{ catalog_namespace.display_name }} service at:
+ {{ service_url }}.

+ {% endif %} + +
+
+ +{% endblock content %} \ No newline at end of file diff --git a/notifier/operator/templates/stop-complete.html.j2 b/notifier/operator/templates/stop-complete.html.j2 deleted file mode 100644 index cd57cdfc0..000000000 --- a/notifier/operator/templates/stop-complete.html.j2 +++ /dev/null @@ -1,6 +0,0 @@ -

Your {{ catalog_namespace.display_name }} service {{ service_display_name }} has stopped.

- -{% if service_url %} -

You may manage your {{ catalog_namespace.display_name }} service at:
-{{ service_url }}.

-{% endif %} diff --git a/notifier/operator/templates/stop-complete.mjml.j2 b/notifier/operator/templates/stop-complete.mjml.j2 new file mode 100644 index 000000000..1ee35a8d3 --- /dev/null +++ b/notifier/operator/templates/stop-complete.mjml.j2 @@ -0,0 +1,17 @@ +{% extends "base.mjml.j2" %} +{% block content %} + + + + +

Your {{ catalog_namespace.display_name }} service {{ service_display_name }} has stopped.

+ + {% if service_url %} +

You may manage your {{ catalog_namespace.display_name }} service at:
+ {{ service_url }}.

+ {% endif %} + +
+
+ +{% endblock content %} \ No newline at end of file diff --git a/notifier/operator/templates/stop-failed.html.j2 b/notifier/operator/templates/stop-failed.html.j2 deleted file mode 100644 index 7782d0492..000000000 --- a/notifier/operator/templates/stop-failed.html.j2 +++ /dev/null @@ -1,10 +0,0 @@ -

Your {{ catalog_namespace.display_name }} service {{ service_display_name }} failed to stop. -{% if have_attachments %} -Please see attached Ansible log. -{% endif %} -

- -{% if service_url %} -

You may manage your {{ catalog_namespace.display_name }} service at:
-{{ service_url }}.

-{% endif %} diff --git a/notifier/operator/templates/stop-failed.mjml.j2 b/notifier/operator/templates/stop-failed.mjml.j2 new file mode 100644 index 000000000..d335b7119 --- /dev/null +++ b/notifier/operator/templates/stop-failed.mjml.j2 @@ -0,0 +1,21 @@ +{% extends "base.mjml.j2" %} +{% block content %} + + + + +

Your {{ catalog_namespace.display_name }} service {{ service_display_name }} failed to stop. + {% if have_attachments %} + Please see attached Ansible log. + {% endif %} +

+ + {% if service_url %} +

You may manage your {{ catalog_namespace.display_name }} service at:
+ {{ service_url }}.

+ {% endif %} + +
+
+ +{% endblock content %} \ No newline at end of file diff --git a/notifier/operator/templates/stop-scheduled.html.j2 b/notifier/operator/templates/stop-scheduled.html.j2 deleted file mode 100644 index 41fc6d0cc..000000000 --- a/notifier/operator/templates/stop-scheduled.html.j2 +++ /dev/null @@ -1,7 +0,0 @@ -

Reminder:
-Your environment will be stopped in {{ stop_timedelta_humanized }} at {{ stop_timestamp }}.

- -{% if service_url %} -

You may manage your {{ catalog_namespace.display_name }} service at:
-{{ service_url }}.

-{% endif %} diff --git a/notifier/operator/templates/stop-scheduled.mjml.j2 b/notifier/operator/templates/stop-scheduled.mjml.j2 new file mode 100644 index 000000000..15a8ec410 --- /dev/null +++ b/notifier/operator/templates/stop-scheduled.mjml.j2 @@ -0,0 +1,18 @@ +{% extends "base.mjml.j2" %} +{% block content %} + + + + +

Reminder:
+ Your environment will be stopped in {{ stop_timedelta_humanized }} at {{ stop_timestamp }}.

+ + {% if service_url %} +

You may manage your {{ catalog_namespace.display_name }} service at:
+ {{ service_url }}.

+ {% endif %} + +
+
+ +{% endblock content %} \ No newline at end of file