Skip to content

Commit

Permalink
update with main changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aleixhub committed Oct 14, 2024
2 parents bef3a7a + 164ccd9 commit 6e9323a
Show file tree
Hide file tree
Showing 25 changed files with 300 additions and 116 deletions.
6 changes: 6 additions & 0 deletions notifier/.s2i/bin/assemble
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

npm install -g [email protected]
npm install -g [email protected]

exec /usr/libexec/s2i/assemble
5 changes: 3 additions & 2 deletions notifier/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
3 changes: 2 additions & 1 deletion notifier/devfile.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 12 additions & 4 deletions notifier/operator/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -775,19 +776,26 @@ 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 += (
"<p><b>Attention:</b> "
"A custom message template was configured for your service, "
"but unfortunately, rendering failed with the following error:</p> "
f"<p>{exception}</p>"
"<p>The content shown above is the default message template.</p>"
)
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
Expand Down
54 changes: 54 additions & 0 deletions notifier/operator/templates/base.mjml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<mjml>
<mj-body>
<!-- Company Header -->
<mj-section full-width="full-width" background-color="#151515" padding-top="8px" padding-bottom="8px" padding-left="12px" padding-right="12px">
<mj-group>
<mj-column vertical-align="middle">
<mj-image href="https://demo.redhat.com/" title="RedHat" alt="RedHat" width="185px" src="https://public-assets-email.s3.us-east-2.amazonaws.com/Logo-Red_Hat-A-Reverse-RGB.png" />
</mj-column>
</mj-group>
</mj-section>
<!-- spacer -->
<mj-section padding-top="0" padding-bottom="0" padding-left="0" padding-right="0">
<mj-column>
<mj-spacer height="25px" />
</mj-column>
</mj-section>
<!-- Title -->
<mj-section padding-top="21px" padding-bottom="12px" padding-left="12px" padding-right="12px">
<mj-column>
<mj-text font-family="Red Hat Text" font-weight="regular" align="center" font-size="16px" color="#000" line-height="1.2">
Status: {{ service_status }}
</mj-text>
<mj-text font-family="Red Hat Display" font-weight="regular" align="center" font-size="35px" color="#000" line-height="1.2">
{{ service_display_name }}
</mj-text>
<mj-text font-family="Red Hat Text" font-weight="regular" align="center" font-size="16px" color="#000" line-height="1.2">
from {{ catalog_namespace.display_name }}
</mj-text>
</mj-column>
</mj-section>

<!-- spacer -->
<mj-section padding-top="0" padding-bottom="0" padding-left="0" padding-right="0">
<mj-column>
<mj-spacer height="25px" />
</mj-column>
</mj-section>
<!-- Text -->
<mj-section padding-top="12px" padding-bottom="12px" padding-left="12px" padding-right="12px" background-color="#f0f0f0">
{% block content %}{% endblock %}
</mj-section>

<!-- Footer -->
<mj-section padding-top="12px" padding-bottom="12px" padding-left="12px" padding-right="12px">
<mj-column>
<mj-text align="center" font-size="12px" color="#4a5557" font-family="Red Hat Text" line-height="1.5">
<b>RedHat
</b> &copy; Copyright 2022 - All rights reserved
</mj-text>
</mj-column>
</mj-section>
<!-- Footer -->
</mj-body>
</mjml>
10 changes: 0 additions & 10 deletions notifier/operator/templates/provision-failed.html.j2

This file was deleted.

21 changes: 21 additions & 0 deletions notifier/operator/templates/provision-failed.mjml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends "base.mjml.j2" %}
{% block content %}

<mj-column>
<mj-text font-family="Red Hat Text" color="#4a5557" font-size="16px" line-height="1.5" padding-bottom="12px">

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

{% if service_url %}
<p>You may manage your {{ catalog_namespace.display_name }} service at:<br>
<a href="{{ service_url }}">{{ service_url }}</a>.</p>
{% endif %}

</mj-text>
</mj-column>

{% endblock content %}
14 changes: 0 additions & 14 deletions notifier/operator/templates/provision-started.html.j2

This file was deleted.

25 changes: 25 additions & 0 deletions notifier/operator/templates/provision-started.mjml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% extends "base.mjml.j2" %}
{% block content %}

<mj-column>
<mj-text font-family="Red Hat Text" color="#4a5557" font-size="16px" line-height="1.5" padding-bottom="12px">

<p>Thank you for ordering {{ catalog_item.display_name }}.</p>

<p>Provisioning has started on your {{ catalog_namespace.display_name }} service, {{ service_display_name }}.</p>

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

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

<p>You can change the auto-stop and auto-destroy time in UI.</p>

{% if service_url %}
<p>You may manage your {{ catalog_namespace.display_name }} service at:<br>
<a href="{{ service_url }}">{{ service_url }}</a>.</p>
{% endif %}

</mj-text>
</mj-column>

{% endblock content %}
7 changes: 0 additions & 7 deletions notifier/operator/templates/retirement-scheduled.html.j2

This file was deleted.

18 changes: 18 additions & 0 deletions notifier/operator/templates/retirement-scheduled.mjml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% extends "base.mjml.j2" %}
{% block content %}

<mj-column>
<mj-text font-family="Red Hat Text" color="#4a5557" font-size="16px" line-height="1.5" padding-bottom="12px">

<p><b>Reminder:</b><br>
Your environment will expire and be deleted in {{ retirement_timedelta_humanized }} at {{ retirement_timestamp }}.</p>

{% if service_url %}
<p>You may manage your {{ catalog_namespace.display_name }} service at:<br>
<a href="{{ service_url }}">{{ service_url }}</a>.</p>
{% endif %}

</mj-text>
</mj-column>

{% endblock content %}
9 changes: 0 additions & 9 deletions notifier/operator/templates/service-deleted.html.j2

This file was deleted.

21 changes: 21 additions & 0 deletions notifier/operator/templates/service-deleted.mjml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends "base.mjml.j2" %}
{% block content %}

<mj-column>
<mj-text font-family="Red Hat Text" color="#4a5557" font-size="16px" line-height="1.5" padding-bottom="12px">

<p>Your {{ catalog_namespace.display_name }} service {{ service_display_name }} has been deleted.</p>

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

<p>Thank you for using {{ catalog_namespace.display_name }}.</p>

{% if survey_link %}
<p>We would love your feedback on your demo/lab, please fill out our short Survey (<a href="{{ survey_link | escape }}">click here</a>) to help us improve your experience.</p>
{% endif %}

</mj-text>
</mj-column>

{% endblock content %}
26 changes: 0 additions & 26 deletions notifier/operator/templates/service-ready.html.j2

This file was deleted.

36 changes: 36 additions & 0 deletions notifier/operator/templates/service-ready.mjml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{% extends "base.mjml.j2" %}
{% block content %}

<mj-column>
<mj-text font-family="Red Hat Text" color="#4a5557" font-size="16px" line-height="1.5" padding-bottom="12px">
<p>Thank you for ordering {{ catalog_item.display_name }}.</p>

<p>Your {{ catalog_namespace.display_name }} service {{ service_display_name }} is ready.</p>

<p>Please refer to the instructions for next steps and how to access your environment.</p>

<p>Troubleshooting and Access issues:</p>

<p>Always refer to the instructions to understand how to properly access and navigate your environment.</p>

<p>NOTICE:<br>
Your environment will be stopped in {{ stop_timedelta_humanized }} at {{ stop_timestamp }}.<br>
Your environment will expire and be deleted in {{ retirement_timedelta_humanized }} at {{ retirement_timestamp }}.</p>

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

{% if provision_messages is defined %}
<p>Here is some important information about your environment:</p>
{{ provision_messages_html }}
{% endif %}

{% if service_url %}
<p>You may manage your {{ catalog_namespace.display_name }} service at:<br>
<a href="{{ service_url }}">{{ service_url }}</a>.</p>
{% endif %}

</mj-text>
</mj-column>

{% endblock content %}
10 changes: 0 additions & 10 deletions notifier/operator/templates/start-complete.html.j2

This file was deleted.

25 changes: 25 additions & 0 deletions notifier/operator/templates/start-complete.mjml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% extends "base.mjml.j2" %}
{% block content %}

<mj-column>
<mj-text font-family="Red Hat Text" color="#4a5557" font-size="16px" line-height="1.5" padding-bottom="12px">

<p>Your {{ catalog_namespace.display_name }} service {{ service_display_name }} has started.</p>

<p>
<b>NOTICE:</b><br>
<ul>
<li>Your environment will be stopped in {{ stop_timedelta_humanized }} at {{ stop_timestamp }}.</li>
<li>Your environment will expire and be deleted in {{ retirement_timedelta_humanized }} at {{ retirement_timestamp }}.</li>
</ul>
</p>

{% if service_url %}
<p>You may manage your {{ catalog_namespace.display_name }} service at:<br>
<a href="{{ service_url }}">{{ service_url }}</a>.</p>
{% endif %}

</mj-text>
</mj-column>

{% endblock content %}
10 changes: 0 additions & 10 deletions notifier/operator/templates/start-failed.html.j2

This file was deleted.

21 changes: 21 additions & 0 deletions notifier/operator/templates/start-failed.mjml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends "base.mjml.j2" %}
{% block content %}

<mj-column>
<mj-text font-family="Red Hat Text" color="#4a5557" font-size="16px" line-height="1.5" padding-bottom="12px">

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

{% if service_url %}
<p>You may manage your {{ catalog_namespace.display_name }} service at:<br>
<a href="{{ service_url }}">{{ service_url }}</a>.</p>
{% endif %}

</mj-text>
</mj-column>

{% endblock content %}
Loading

0 comments on commit 6e9323a

Please sign in to comment.