Skip to content

Commit

Permalink
Merge pull request #66 from TeskaLabs/Enhancement/Beautify-md-output
Browse files Browse the repository at this point in the history
Beautify markdown to html output
  • Loading branch information
mithunbharadwaj authored Apr 5, 2024
2 parents fac9cc9 + 8ee6cdd commit cf69adc
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@

- Kafka handler : Fallback solution

#### 04. 04. 2024

- Loading external templates for content wrapping in iris


### Bugfix

Expand Down
1 change: 1 addition & 0 deletions asabiris/handlers/webhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ async def send_email(self, request, *, json_data):
await self.App.SendEmailOrchestrator.send_email(
email_to=json_data["to"],
body_template=json_data["body"]["template"],
body_template_wrapper=json_data["body"].get("wrapper", None),
email_cc=json_data.get("cc", []), # Optional
email_bcc=json_data.get("bcc", []), # Optional
email_subject=json_data.get("subject", None), # Optional
Expand Down
16 changes: 11 additions & 5 deletions asabiris/orchestration/sendemail.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ async def send_email(
self,
email_to: List[str],
body_template: str,
body_template_wrapper=None,
body_params=None,
email_from=None,
email_cc=None,
Expand All @@ -68,7 +69,7 @@ async def send_email(
email_bcc = email_bcc or []

# Rendering the template
body_html, email_subject_body = await self._render_template(body_template, body_params)
body_html, email_subject_body = await self._render_template(body_template, body_params, body_template_wrapper)

# If email_subject is not provided or is empty use email_subject_body
if email_subject is None or email_subject == '':
Expand All @@ -90,8 +91,8 @@ async def send_email(
L.info("Email sent successfully to: {}".format(', '.join(email_to)))


async def _render_template(self, template: str, params: Dict) -> Tuple[str, str]:
if not template.startswith('/Templates/Email/'):
async def _render_template(self, template: str, params: Dict, body_template_wrapper=None) -> Tuple[str, str]:
if not template.startswith('/Templates/Email/') or (body_template_wrapper is not None and not template.startswith('/Templates/Email/')):
raise ASABIrisError(
ErrorCode.INVALID_PATH,
tech_message="Incorrect template path '{}'. Move templates to '/Templates/Email/'.".format(template),
Expand All @@ -109,8 +110,13 @@ async def _render_template(self, template: str, params: Dict) -> Tuple[str, str]

elif ext == '.md':
body, subject = find_subject_in_md(jinja_output)
body = self.MarkdownToHTMLService.format(body)
return body, subject
html_body = self.MarkdownToHTMLService.format(body)

if body_template_wrapper is not None:
html_body_param = {"content": html_body}
html_body = await self.JinjaService.format(body_template_wrapper, html_body_param)

return html_body, subject

else:
raise ASABIrisError(
Expand Down
49 changes: 49 additions & 0 deletions library/Templates/Email/body_wrapper.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>TeskaLabs LogMan.io</title>
<style>
body {
font-family: 'Arial', sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4; /* Background color of the entire page */
}
.content {
background-color: #ffffff; /* Background color of the content area */
color: #333333; /* Text color for the content */
padding: 20px;
margin: 20px;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
footer {
background-color: #f6f6f6; /* Light grey background for the footer */
color: #333333; /* Text color for the footer */
text-align: center;
padding: 20px;
font-size: 14px;
}
footer .footer-title {
font-size: 16px; /* Slightly larger font size for the title */
font-weight: normal; /* Normal font weight for the title */
}
footer p {
margin: 0; /* Remove margin from paragraphs in the footer for tighter spacing */
}
</style>
</head>
<body>
<div class="content">
<h1>TeskaLabs LogMan.io</h1> <!-- Displaying TeskaLabs LogMan.io as page content title -->
{{ content }}
</div>
<footer>
<p class="footer-title">TeskaLabs LogMan.io</p>
<p>Stay safe and secure,<br>
PS: TeskaLabs LogMan.io is proudly made with love and innovation by the TeskaLabs team.<br>
Thank you for choosing us as your trusted partner in cyber security.</p>
</footer>
</body>
</html>
112 changes: 111 additions & 1 deletion qa.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
1) Configure proper SMTP server for a test
2) Replace `[email protected]` by the valid email address that you have access into

## TSM001: Send an email using Markdown template(Subject should be taken from md file)
## TSM001A: Send an email using Markdown template(Subject should be taken from md file)

`PUT /send_mail`

Expand All @@ -21,6 +21,58 @@
}
```

## TSM001B: Send an email using Markdown template(Subject should be taken from md file) with html wrapper

`PUT /send_mail`

```
{
"to": ["[email protected]"],
"body": {
"template": "/Templates/Email/message.md",
"wrapper": "/Templates/Email/body_wrapper.html",
"params":{
"name":"Iris"
}
}
}
```

## TSM001C: Send an email using Markdown template with html wrapper from incorrect path.

`PUT /send_mail`

```
{
"to": ["[email protected]"],
"body": {
"template": "/Templates/Email/message.md",
"wrapper": "/Templates/Emails/body_wrapper.html",
"params":{
"name":"Iris"
}
}
}
```

## TSM001D: Send an email using Markdown template with html wrapper from a template that does not exist.

`PUT /send_mail`

```
{
"to": ["[email protected]"],
"body": {
"template": "/Templates/Email/message.md",
"wrapper": "/Templates/Email/body_wrapper.md",
"params":{
"name":"Iris"
}
}
}
```



## TSM002: Send an email using HTML template

Expand Down Expand Up @@ -1344,3 +1396,61 @@ EXPECTED RESPONSE:
}
}
```


## TSM033: Kakka handler

`EMAIL`

```
{"type":"email", "to": ["Shivashankar <[email protected]>"], "from": "[email protected]", "body":{"template":"/Templates/Email/message.md", "params":{"name": "I am testing a template", "error": "None" }}}
{"type":"email", "to": ["Shivashankar <[email protected]>"], "from": "[email protected]", "body":{"template":"/Templates/Export.md", "params":{"name": "I am testing a template", "error": "None" }}}
'Missing from'
{"type":"email", "to": ["Shivashankar <[email protected]>"], "body":{"template":"/Templates/Email/message.md", "params":{"name": "I am testing a template", "error": "None" }}}
'Bad template path'
{"type":"email", "to": ["Shivashankar <[email protected]>"], "body":{"template":"/Templates/Emails/message.md", "params":{"name": "I am testing a template", "error": "None" }}}
'Access non existant template'
{"type":"email", "to": ["Shivashankar <[email protected]>"], "body":{"template":"/Templates/Email/message22.md", "params":{"name": "I am testing a template", "error": "None" }}}
```

`SLACK`

```
{"type":"slack", "body":{"template":"/Templates/Slack/Slack example.txt", "params":{"name": "I am testing a template", "error": "None" }}}
{"type":"slack", "body":{"template":"/Templates/Slack/Slack example.txt", "params":{"name": "I am testing a template", "error": "None" }}}
'Bad template path'
{"type":"slack", "body":{"template":"/Templates/SlackS/message.md", "params":{"name": "I am testing a template", "error": "None" }}}
'Access non existant template'
{"type":"slack", "body":{"template":"/Templates/Slack/message.md2", "params":{"name": "I am testing a template", "error": "None" }}}
```

`MSTEAMS`

```
{"type":"msteams", "body":{"template":"/Templates/MSTeams/Slack example.txt", "params":{"name": "I am testing a template", "error": "None" }}}
{"type":"msteams", "body":{"template":"/Templates/MSTeams/Slack example.txt", "params":{"name": "I am testing a template", "error": "None" }}}
'Bad template path'
{"type":"msteams", "body":{"template":"/Templates/MSTeamss/message.md", "params":{"name": "I am testing a template", "error": "None" }}}
'Access non existant template'
{"type":"msteams", "body":{"template":"/Templates/MSTeams/message.md2", "params":{"name": "I am testing a template", "error": "None" }}}
```


`UNSUPPORTED-TYPE`

```
{"type":"sms", "body":{"template":"/Templates/MSTeams/Slack example.txt", "params":{"name": "I am testing a template", "error": "None" }}}
```

0 comments on commit cf69adc

Please sign in to comment.