Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

secrets backend deprecated methods removed #41642

Merged
merged 4 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 1 addition & 54 deletions airflow/secrets/base_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -69,17 +66,6 @@ def deserialize_connection(self, conn_id: str, value: str) -> Connection:
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``.
Expand All @@ -88,52 +74,13 @@ def get_connection(self, conn_id: str) -> Connection | None:

: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.
Expand Down
18 changes: 0 additions & 18 deletions airflow/secrets/environment_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_"
Expand All @@ -32,22 +30,6 @@
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())

Expand Down
15 changes: 0 additions & 15 deletions airflow/secrets/metastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
"""
Expand Down
1 change: 1 addition & 0 deletions newsfragments/41642.significant.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed deprecated ``get_conn_uri`` and ``get_connections`` methods from secrets backend. Please use ``get_conn_value`` and ``get_connection`` mehtods.
Loading