Skip to content
Snippets Groups Projects
Verified Commit 6d943253 authored by Karel van Klink's avatar Karel van Klink :smiley_cat:
Browse files

update oss-params examples and config unit test

parent b4d08a21
No related branches found
No related tags found
1 merge request!161Feature/add mailer service
Pipeline #85722 failed
......@@ -77,5 +77,13 @@
"THIRD_PARTY_API_KEYS": {
"AnsibleDynamicInventoryGenerator": "REALLY_random_AND_secure_T0keN",
"Application_2": "another_REALY_random_AND_3cure_T0keN"
},
"EMAIL": {
"from_address": "noreply@nren.local",
"smtp_host": "smtp.nren.local",
"smtp_port": 487,
"starttls_enabled": true,
"smtp_username": "username",
"smtp_password": "password"
}
}
......@@ -7,14 +7,14 @@ from ssl import create_default_context
from gso.settings import load_oss_params
def send_mail(recipient, subject, body) -> None:
def send_mail(recipient: str, subject: str, body: str) -> None:
"""Send an email message to the given address.
Only supports STARTTLS, not SSL.
:param recipient: The destination address.
:param subject: The email subject.
:param body: The contents of the email message.
:param str recipient: The destination address.
:param str subject: The email subject.
:param str body: The contents of the email message.
"""
email_params = load_oss_params().EMAIL
msg = EmailMessage()
......@@ -27,6 +27,6 @@ def send_mail(recipient, subject, body) -> None:
if email_params.starttls_enabled:
tls_context = create_default_context()
s.starttls(context=tls_context)
if email_params.smtp_username or email_params.smtp_password:
if email_params.smtp_username and email_params.smtp_password:
s.login(email_params.smtp_username, email_params.smtp_password)
s.send_message(msg)
......@@ -160,8 +160,8 @@ class EmailParams(BaseSettings):
smtp_host: str
smtp_port: int
starttls_enabled: bool
smtp_username: str | None = ""
smtp_password: str | None = ""
smtp_username: str | None
smtp_password: str | None
class OSSParams(BaseSettings):
......
......@@ -208,6 +208,14 @@ def configuration_data() -> dict:
"AnsibleDynamicInventoryGenerator": "REALY_random_AND_3cure_T0keN",
"Application_2": "another_REALY_random_AND_3cure_T0keN",
},
"EMAIL": {
"from_address": "noreply@nren.local",
"smtp_host": "smtp.nren.local",
"smtp_port": 487,
"starttls_enabled": True,
"smtp_username": "username",
"smtp_password": "password",
},
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment