This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 865220965f smtp email user and password deprecated config removal 
(#41539)
865220965f is described below

commit 865220965f6d337b1bc8d40b69ba91da1422c5d6
Author: Gopal Dirisala <[email protected]>
AuthorDate: Mon Aug 19 02:57:05 2024 +0530

    smtp email user and password deprecated config removal (#41539)
    
    * smtp email user and password deprecated config removal
    
    * smtp email user and password deprecated config removal
    
    * news fragment added
    
    * smtp email user and password deprecated config removal
---
 airflow/config_templates/config.yml        | 15 ---------------
 airflow/config_templates/unit_tests.cfg    |  2 --
 airflow/utils/email.py                     | 15 ++-------------
 docs/apache-airflow/howto/email-config.rst |  4 ----
 newsfragments/41539.significant.rst        |  1 +
 tests/core/test_configuration.py           |  1 -
 tests/utils/test_email.py                  | 11 +----------
 7 files changed, 4 insertions(+), 45 deletions(-)

diff --git a/airflow/config_templates/config.yml 
b/airflow/config_templates/config.yml
index 0aab7181f3..007ceadd67 100644
--- a/airflow/config_templates/config.yml
+++ b/airflow/config_templates/config.yml
@@ -2174,21 +2174,6 @@ smtp:
       type: string
       example: ~
       default: "False"
-    smtp_user:
-      description: |
-        Username to authenticate when connecting to smtp server.
-      version_added: ~
-      type: string
-      example: "airflow"
-      default: ~
-    smtp_password:
-      description: |
-        Password to authenticate when connecting to smtp server.
-      version_added: ~
-      type: string
-      sensitive: true
-      example: "airflow"
-      default: ~
     smtp_port:
       description: |
         Defines the port number on which Airflow connects to the SMTP server 
to send email notifications.
diff --git a/airflow/config_templates/unit_tests.cfg 
b/airflow/config_templates/unit_tests.cfg
index 42055b9d9c..af32b79f4b 100644
--- a/airflow/config_templates/unit_tests.cfg
+++ b/airflow/config_templates/unit_tests.cfg
@@ -68,8 +68,6 @@ celery_logging_level = INFO
 
 [smtp]
 # Used as default values for SMTP unit tests
-smtp_user = airflow
-smtp_password = airflow
 smtp_mail_from = [email protected]
 
 [api]
diff --git a/airflow/utils/email.py b/airflow/utils/email.py
index 31a33337f9..3a63b41804 100644
--- a/airflow/utils/email.py
+++ b/airflow/utils/email.py
@@ -22,7 +22,6 @@ import logging
 import os
 import smtplib
 import ssl
-import warnings
 from email.mime.application import MIMEApplication
 from email.mime.multipart import MIMEMultipart
 from email.mime.text import MIMEText
@@ -32,7 +31,7 @@ from typing import Any, Iterable
 import re2
 
 from airflow.configuration import conf
-from airflow.exceptions import AirflowConfigException, AirflowException, 
RemovedInAirflow3Warning
+from airflow.exceptions import AirflowException
 
 log = logging.getLogger(__name__)
 
@@ -255,17 +254,7 @@ def send_mime_email(
         except AirflowException:
             pass
     if smtp_user is None or smtp_password is None:
-        warnings.warn(
-            "Fetching SMTP credentials from configuration variables will be 
deprecated in a future "
-            "release. Please set credentials using a connection instead.",
-            RemovedInAirflow3Warning,
-            stacklevel=2,
-        )
-        try:
-            smtp_user = conf.get("smtp", "SMTP_USER")
-            smtp_password = conf.get("smtp", "SMTP_PASSWORD")
-        except AirflowConfigException:
-            log.debug("No user/password found for SMTP, so logging in with no 
authentication.")
+        log.debug("No user/password found for SMTP, so logging in with no 
authentication.")
 
     if not dryrun:
         for attempt in range(1, smtp_retry_limit + 1):
diff --git a/docs/apache-airflow/howto/email-config.rst 
b/docs/apache-airflow/howto/email-config.rst
index c00d959d3b..bc7ea9a1f9 100644
--- a/docs/apache-airflow/howto/email-config.rst
+++ b/docs/apache-airflow/howto/email-config.rst
@@ -96,8 +96,6 @@ You can use the default airflow SMTP backend to send email 
with SendGrid
      smtp_host=smtp.sendgrid.net
      smtp_starttls=False
      smtp_ssl=False
-     smtp_user=apikey
-     smtp_password=<generated-api-key>
      smtp_port=587
      smtp_mail_from=<your-from-email>
 
@@ -108,8 +106,6 @@ Equivalent environment variables looks like
      AIRFLOW__SMTP__SMTP_HOST=smtp.sendgrid.net
      AIRFLOW__SMTP__SMTP_STARTTLS=False
      AIRFLOW__SMTP__SMTP_SSL=False
-     AIRFLOW__SMTP__SMTP_USER=apikey
-     AIRFLOW__SMTP__SMTP_PASSWORD=<generated-api-key>
      AIRFLOW__SMTP__SMTP_PORT=587
      AIRFLOW__SMTP__SMTP_MAIL_FROM=<your-from-email>
 
diff --git a/newsfragments/41539.significant.rst 
b/newsfragments/41539.significant.rst
new file mode 100644
index 0000000000..31a497f458
--- /dev/null
+++ b/newsfragments/41539.significant.rst
@@ -0,0 +1 @@
+Removed deprecated ``smtp_user`` and ``smtp_password`` configuration 
parameters from ``smtp`` section. Please use smtp connection (``smtp_default``).
diff --git a/tests/core/test_configuration.py b/tests/core/test_configuration.py
index 62548a3f26..94f5bc4c26 100644
--- a/tests/core/test_configuration.py
+++ b/tests/core/test_configuration.py
@@ -1624,7 +1624,6 @@ def test_sensitive_values():
         ("database", "sql_alchemy_conn"),
         ("core", "fernet_key"),
         ("core", "internal_api_secret_key"),
-        ("smtp", "smtp_password"),
         ("webserver", "secret_key"),
         ("secrets", "backend_kwargs"),
         ("sentry", "sentry_dsn"),
diff --git a/tests/utils/test_email.py b/tests/utils/test_email.py
index ea85f635aa..bf5f3fc0a1 100644
--- a/tests/utils/test_email.py
+++ b/tests/utils/test_email.py
@@ -28,7 +28,6 @@ from unittest import mock
 import pytest
 
 from airflow.configuration import conf
-from airflow.exceptions import RemovedInAirflow3Warning
 from airflow.utils import email
 from tests.test_utils.config import conf_vars
 
@@ -217,11 +216,7 @@ class TestEmailSmtp:
         monkeypatch.delenv("AIRFLOW_CONN_SMTP_DEFAULT", raising=False)
         mock_smtp.return_value = mock.Mock()
         msg = MIMEMultipart()
-        with pytest.warns(
-            RemovedInAirflow3Warning,
-            match="Fetching SMTP credentials from configuration 
variables.*deprecated",
-        ):
-            email.send_mime_email("from", "to", msg, dryrun=False)
+        email.send_mime_email("from", "to", msg, dryrun=False)
         mock_smtp.assert_called_once_with(
             host=conf.get("smtp", "SMTP_HOST"),
             port=conf.getint("smtp", "SMTP_PORT"),
@@ -229,10 +224,6 @@ class TestEmailSmtp:
         )
         assert not mock_smtp_ssl.called
         assert mock_smtp.return_value.starttls.called
-        mock_smtp.return_value.login.assert_called_once_with(
-            conf.get("smtp", "SMTP_USER"),
-            conf.get("smtp", "SMTP_PASSWORD"),
-        )
         mock_smtp.return_value.sendmail.assert_called_once_with("from", "to", 
msg.as_string())
         assert mock_smtp.return_value.quit.called
 

Reply via email to