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/Dockerfile b/notifier/Dockerfile index 024122ed2..c278f8e93 100644 --- a/notifier/Dockerfile +++ b/notifier/Dockerfile @@ -9,10 +9,11 @@ RUN dnf install -y @ruby && \ 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 bb4d6eabf..87892f25c 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 184f8406e..ac311b69f 100755 --- a/notifier/operator/operator.py +++ b/notifier/operator/operator.py @@ -718,6 +718,7 @@ 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) @@ -726,9 +727,16 @@ def send_notification_email( else: message_template = catalog_item.get_message_template(kebabToCamelCase(template)) if message_template: - email_body = j2env.from_string(message_template).render(**template_vars) + mjml_template = j2env.from_string(message_template).render(**template_vars) 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 9ab01245c..000000000 --- a/notifier/operator/templates/provision-started.html.j2 +++ /dev/null @@ -1,10 +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 }}. - -{% 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..027b28379 --- /dev/null +++ b/notifier/operator/templates/provision-started.mjml.j2 @@ -0,0 +1,20 @@ +{% 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 }}.

+ + {% 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 8701be7bc..000000000 --- a/notifier/operator/templates/service-ready.html.j2 +++ /dev/null @@ -1,44 +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 or provision_data is defined %} -

Here is some important information about your environment:

- -{% if provision_messages_html is defined %} -{{ provision_messages_html }} -{% endif %} - -{% if provision_data is defined %} -
-{% for k, v in provision_data.items() | sort %} -{% if k != 'users' %} -
{{ k | escape }}
-{% if v is string or v is not iterable %} -
{{ v | escape }}
-{% else %} -
{{ v | to_yaml | escape }}
-{% endif %} -{% endif %} -{% endfor %} -
-{% endif %} -{% 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..3150fc72b --- /dev/null +++ b/notifier/operator/templates/service-ready.mjml.j2 @@ -0,0 +1,62 @@ +{% 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.

+ +

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

+ +

+ NOTICE:
+

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

+ + {% if service_url %} +

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

+ {% endif %} + +
+ + {% if provision_messages is defined or provision_data is defined %} + + + Some important information about your environment + + + {% if provision_messages_html is defined %} + + {{ provision_messages_html }} + + {% endif %} + + {% if provision_data is defined %} + +
+ {% for k, v in provision_data.items() | sort %} + {% if k != 'users' %} +
{{ k | escape }}:
+ {% if v is string or v is not iterable %} +
{{ v | escape }}
+ {% else %} +
{{ v | to_yaml | escape }}
+ {% endif %} + {% endif %} + {% endfor %} +
+
+ {% endif %} + + + {% 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