You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/06/27 14:48:07 UTC
[GitHub] [airflow] Taragolis commented on a diff in pull request #24679: Warning for using listing conns & vars with secrets backend
Taragolis commented on code in PR #24679:
URL: https://github.com/apache/airflow/pull/24679#discussion_r907475480
##########
airflow/cli/commands/variable_command.py:
##########
@@ -21,23 +21,44 @@
from json import JSONDecodeError
from airflow.cli.simple_table import AirflowConsole
+from airflow.configuration import get_custom_secret_backend
from airflow.models import Variable
from airflow.utils import cli as cli_utils
from airflow.utils.cli import suppress_logs_and_warning
from airflow.utils.session import create_session
+CUSTOM_BACKEND: bool = True if get_custom_secret_backend() else False
+
@suppress_logs_and_warning
def variables_list(args):
"""Displays all of the variables"""
+ airflow_console = AirflowConsole()
+ if CUSTOM_BACKEND:
+ airflow_console.print(
+ (
+ "WARNING: The Airflow CLI will not return Connections or "
+ "Variables stored in an alternative secrets backend."
+ ),
+ style="magenta",
+ )
with create_session() as session:
variables = session.query(Variable)
- AirflowConsole().print_as(data=variables, output=args.output, mapper=lambda x: {"key": x.key})
+ airflow_console.print_as(data=variables, output=args.output, mapper=lambda x: {"key": x.key})
@suppress_logs_and_warning
def variables_get(args):
"""Displays variable by a given name"""
+ airflow_console = AirflowConsole()
+ if CUSTOM_BACKEND:
+ airflow_console.print(
+ (
+ "WARNING: The Airflow CLI will not return Connections or "
+ "Variables stored in an alternative secrets backend."
+ ),
+ style="magenta",
+ )
Review Comment:
Same as `connections_get`
##########
airflow/cli/commands/connection_command.py:
##########
@@ -59,11 +62,20 @@ def _connection_mapper(conn: Connection) -> Dict[str, Any]:
@suppress_logs_and_warning
def connections_get(args):
"""Get a connection."""
+ airflow_console = AirflowConsole()
+ if CUSTOM_BACKEND:
+ airflow_console.print(
+ (
+ "WARNING: The Airflow CLI will not return Connections or "
+ "Variables stored in an alternative secrets backend."
+ ),
+ style="magenta",
+ )
Review Comment:
cli `airflow connections get <connection>` will return connection from secrets backends if it exists because it use `BaseHook.get_connection(args.conn_id)` if it won't return but it should that mean you didn't configure cli to use alternative secrets backend.
##########
airflow/cli/commands/connection_command.py:
##########
@@ -73,13 +85,22 @@ def connections_get(args):
@suppress_logs_and_warning
def connections_list(args):
"""Lists all connections at the command line"""
+ airflow_console = AirflowConsole()
+ if CUSTOM_BACKEND:
+ airflow_console.print(
+ (
+ "WARNING: The Airflow CLI will not return Connections or "
+ "Variables stored in an alternative secrets backend."
+ ),
+ style="magenta",
+ )
Review Comment:
At that moment airflow grab credentials/variables from SomeAlternateSecretsBackend, EnvironmentVariablesBackend and MetastoreBackend.
And actually it return list only from MetastoreBackend, and ignore all other backends.
##########
airflow/cli/commands/variable_command.py:
##########
@@ -21,23 +21,44 @@
from json import JSONDecodeError
from airflow.cli.simple_table import AirflowConsole
+from airflow.configuration import get_custom_secret_backend
from airflow.models import Variable
from airflow.utils import cli as cli_utils
from airflow.utils.cli import suppress_logs_and_warning
from airflow.utils.session import create_session
+CUSTOM_BACKEND: bool = True if get_custom_secret_backend() else False
+
@suppress_logs_and_warning
def variables_list(args):
"""Displays all of the variables"""
+ airflow_console = AirflowConsole()
+ if CUSTOM_BACKEND:
+ airflow_console.print(
+ (
+ "WARNING: The Airflow CLI will not return Connections or "
+ "Variables stored in an alternative secrets backend."
+ ),
+ style="magenta",
+ )
Review Comment:
Same as `connections_list`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org