From 6d94325367740e9badd660af228c31c12dc187b4 Mon Sep 17 00:00:00 2001 From: Karel van Klink <karel.vanklink@geant.org> Date: Tue, 13 Feb 2024 16:12:08 +0100 Subject: [PATCH] update oss-params examples and config unit test --- gso/oss-params-example.json | 8 ++++++++ gso/services/mailer.py | 10 +++++----- gso/settings.py | 4 ++-- test/conftest.py | 8 ++++++++ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/gso/oss-params-example.json b/gso/oss-params-example.json index 931367ea..007b899b 100644 --- a/gso/oss-params-example.json +++ b/gso/oss-params-example.json @@ -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" } } diff --git a/gso/services/mailer.py b/gso/services/mailer.py index ee4d7dd9..3cd85b73 100644 --- a/gso/services/mailer.py +++ b/gso/services/mailer.py @@ -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) diff --git a/gso/settings.py b/gso/settings.py index de222238..0189986d 100644 --- a/gso/settings.py +++ b/gso/settings.py @@ -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): diff --git a/test/conftest.py b/test/conftest.py index dd6e9d6d..895b4798 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -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", + }, } -- GitLab