This is an automated email from the ASF dual-hosted git repository.
vincbeck 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 73eb9bf5ab secrets backend deprecated methods removed (#41642)
73eb9bf5ab is described below
commit 73eb9bf5ab1544c4fd26de22725a03cb5a305185
Author: Gopal Dirisala <[email protected]>
AuthorDate: Thu Aug 22 19:02:17 2024 +0530
secrets backend deprecated methods removed (#41642)
---
airflow/secrets/base_secrets.py | 55 +-------------------------------
airflow/secrets/environment_variables.py | 18 -----------
airflow/secrets/metastore.py | 15 ---------
newsfragments/41642.significant.rst | 3 ++
4 files changed, 4 insertions(+), 87 deletions(-)
diff --git a/airflow/secrets/base_secrets.py b/airflow/secrets/base_secrets.py
index 3346d880f2..329eb95cb3 100644
--- a/airflow/secrets/base_secrets.py
+++ b/airflow/secrets/base_secrets.py
@@ -16,12 +16,9 @@
# under the License.
from __future__ import annotations
-import warnings
from abc import ABC
from typing import TYPE_CHECKING
-from airflow.exceptions import RemovedInAirflow3Warning
-
if TYPE_CHECKING:
from airflow.models.connection import Connection
@@ -69,17 +66,6 @@ class BaseSecretsBackend(ABC):
else:
return Connection(conn_id=conn_id, uri=value)
- def get_conn_uri(self, conn_id: str) -> str | None:
- """
- Get conn_uri from Secrets Backend.
-
- This method is deprecated and will be removed in a future release;
implement ``get_conn_value``
- instead.
-
- :param conn_id: connection id
- """
- raise NotImplementedError()
-
def get_connection(self, conn_id: str) -> Connection | None:
"""
Return connection object with a given ``conn_id``.
@@ -88,52 +74,13 @@ class BaseSecretsBackend(ABC):
:param conn_id: connection id
"""
- value = None
-
- not_implemented_get_conn_value = False
- # TODO: after removal of ``get_conn_uri`` we should not catch
NotImplementedError here
- try:
- value = self.get_conn_value(conn_id=conn_id)
- except NotImplementedError:
- not_implemented_get_conn_value = True
- warnings.warn(
- "Method `get_conn_uri` is deprecated. Please use
`get_conn_value`.",
- RemovedInAirflow3Warning,
- stacklevel=2,
- )
-
- if not_implemented_get_conn_value:
- try:
- value = self.get_conn_uri(conn_id=conn_id)
- except NotImplementedError:
- raise NotImplementedError(
- f"Secrets backend {self.__class__.__name__} neither
implements "
- "`get_conn_value` nor `get_conn_uri`. Method
`get_conn_uri` is "
- "deprecated and will be removed in a future release.
Please implement `get_conn_value`."
- )
+ value = self.get_conn_value(conn_id=conn_id)
if value:
return self.deserialize_connection(conn_id=conn_id, value=value)
else:
return None
- def get_connections(self, conn_id: str) -> list[Connection]:
- """
- Return connection object with a given ``conn_id``.
-
- :param conn_id: connection id
- """
- warnings.warn(
- "This method is deprecated. Please use "
-
"`airflow.secrets.base_secrets.BaseSecretsBackend.get_connection`.",
- RemovedInAirflow3Warning,
- stacklevel=2,
- )
- conn = self.get_connection(conn_id=conn_id)
- if conn:
- return [conn]
- return []
-
def get_variable(self, key: str) -> str | None:
"""
Return value for Airflow Variable.
diff --git a/airflow/secrets/environment_variables.py
b/airflow/secrets/environment_variables.py
index 69d3174b72..e6bd72d4e5 100644
--- a/airflow/secrets/environment_variables.py
+++ b/airflow/secrets/environment_variables.py
@@ -20,9 +20,7 @@
from __future__ import annotations
import os
-import warnings
-from airflow.exceptions import RemovedInAirflow3Warning
from airflow.secrets import BaseSecretsBackend
CONN_ENV_PREFIX = "AIRFLOW_CONN_"
@@ -32,22 +30,6 @@ VAR_ENV_PREFIX = "AIRFLOW_VAR_"
class EnvironmentVariablesBackend(BaseSecretsBackend):
"""Retrieves Connection object and Variable from environment variable."""
- def get_conn_uri(self, conn_id: str) -> str | None:
- """
- Return URI representation of Connection conn_id.
-
- :param conn_id: the connection id
-
- :return: deserialized Connection
- """
- warnings.warn(
- "This method is deprecated. Please use "
-
"`airflow.secrets.environment_variables.EnvironmentVariablesBackend.get_conn_value`.",
- RemovedInAirflow3Warning,
- stacklevel=2,
- )
- return self.get_conn_value(conn_id)
-
def get_conn_value(self, conn_id: str) -> str | None:
return os.environ.get(CONN_ENV_PREFIX + conn_id.upper())
diff --git a/airflow/secrets/metastore.py b/airflow/secrets/metastore.py
index 1c812cc0c5..ba59575132 100644
--- a/airflow/secrets/metastore.py
+++ b/airflow/secrets/metastore.py
@@ -19,13 +19,11 @@
from __future__ import annotations
-import warnings
from typing import TYPE_CHECKING
from sqlalchemy import select
from airflow.api_internal.internal_api_call import internal_api_call
-from airflow.exceptions import RemovedInAirflow3Warning
from airflow.secrets import BaseSecretsBackend
from airflow.utils.session import NEW_SESSION, provide_session
@@ -42,19 +40,6 @@ class MetastoreBackend(BaseSecretsBackend):
def get_connection(self, conn_id: str, session: Session = NEW_SESSION) ->
Connection | None:
return MetastoreBackend._fetch_connection(conn_id, session=session)
- @provide_session
- def get_connections(self, conn_id: str, session: Session = NEW_SESSION) ->
list[Connection]:
- warnings.warn(
- "This method is deprecated. Please use "
- "`airflow.secrets.metastore.MetastoreBackend.get_connection`.",
- RemovedInAirflow3Warning,
- stacklevel=3,
- )
- conn = self.get_connection(conn_id=conn_id, session=session)
- if conn:
- return [conn]
- return []
-
@provide_session
def get_variable(self, key: str, session: Session = NEW_SESSION) -> str |
None:
"""
diff --git a/newsfragments/41642.significant.rst
b/newsfragments/41642.significant.rst
new file mode 100644
index 0000000000..566061d0d8
--- /dev/null
+++ b/newsfragments/41642.significant.rst
@@ -0,0 +1,3 @@
+Removed deprecated secrets backend methods ``get_conn_uri`` and
``get_connections``.
+
+Please use ``get_conn_value`` and ``get_connection`` instead.