-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plugin was attemtping SMTP connections regardless of if the plugin config was using defaults. Now checks on pre/post checks to stop attempted SMTP connections before the plugin was disabled. Signed-off-by: Harvey Lynden <[email protected]>
- Loading branch information
1 parent
4c590e2
commit 4450fd7
Showing
1 changed file
with
20 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ def initialize(self): | |
settings.register_option( | ||
section="plugins.mail", | ||
key="recipient", | ||
default="[email protected]", | ||
default=None, | ||
help_msg=help_msg, | ||
) | ||
|
||
|
@@ -38,31 +38,31 @@ def initialize(self): | |
settings.register_option( | ||
section="plugins.mail", | ||
key="sender", | ||
default="[email protected]", | ||
default=None, | ||
help_msg=help_msg, | ||
) | ||
|
||
help_msg = "Mail server." | ||
settings.register_option( | ||
section="plugins.mail", | ||
key="server", | ||
default="localhost", | ||
default=None, | ||
help_msg=help_msg, | ||
) | ||
|
||
help_msg = "Mail server port." | ||
settings.register_option( | ||
section="plugins.mail", | ||
key="port", | ||
default=587, | ||
default=None, | ||
help_msg=help_msg, | ||
) | ||
|
||
help_msg = "Mail server Application Password." | ||
settings.register_option( | ||
section="plugins.mail", | ||
key="password", | ||
default="", | ||
default=None, | ||
help_msg=help_msg, | ||
) | ||
|
||
|
@@ -160,6 +160,10 @@ def _send_email(smtp, sender, rcpt, msg): | |
|
||
@staticmethod | ||
def _smtp_login_and_send(job, msg): | ||
if not Mail._validate_email_config(job): | ||
job_log.error("Invalid email configuration. Plugin Disabled.") | ||
return False | ||
|
||
server, port, sender, password = Mail._get_smtp_config(job) | ||
smtp = Mail._create_smtp_connection(server, port) | ||
if smtp: | ||
|
@@ -257,6 +261,7 @@ def _get_test_summary(job): | |
|
||
def pre(self, job): | ||
if not self.enabled: | ||
job_log.info("Email plugin disabled, skipping start notification.") | ||
return | ||
|
||
phase = "Start" | ||
|
@@ -268,6 +273,9 @@ def pre(self, job): | |
|
||
def post(self, job): | ||
if not self.enabled or not self.start_email_sent: | ||
job_log.info( | ||
"Email plugin disabled or start email not sent, skipping end notification." | ||
) | ||
return | ||
|
||
phase = "Post" | ||
|
@@ -282,17 +290,13 @@ def post(self, job): | |
msg = self._build_message(job, time_content, phase, finishedtime, test_summary) | ||
self._smtp_login_and_send(job, msg) | ||
|
||
def _validate_email_config(self, job): | ||
required_keys = ["recipient", "sender", "server", "port"] | ||
for key in required_keys: | ||
if not job.config.get(f"plugins.mail.{key}"): | ||
job_log.error( | ||
f"Email configuration {key} is missing. Disabling Plugin." | ||
) | ||
return False | ||
@staticmethod | ||
def _validate_email_config(job): | ||
server, port, sender, password = Mail._get_smtp_config(job) | ||
|
||
if job.config.get("plugins.mail.sender") == "[email protected]": | ||
job_log.error("Email sender is still set to default. Disabling Plugin.") | ||
if not all([server, port, sender, password]): | ||
job_log.error( | ||
"Email configuration is missing or contains empty values. Disabling Plugin." | ||
) | ||
return False | ||
|
||
return True |