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 5ed6f8f3217 Improve confirmation output when connections are added via
cli (#71215)
5ed6f8f3217 is described below
commit 5ed6f8f3217e71978fbe1f356fbb465fded2a7f4
Author: Amogh Desai <[email protected]>
AuthorDate: Fri Aug 7 21:16:05 2026 +0530
Improve confirmation output when connections are added via cli (#71215)
---
.../src/airflow/cli/commands/connection_command.py | 28 ++++++++++------------
.../unit/cli/commands/test_connection_command.py | 18 +++++++-------
2 files changed, 22 insertions(+), 24 deletions(-)
diff --git a/airflow-core/src/airflow/cli/commands/connection_command.py
b/airflow-core/src/airflow/cli/commands/connection_command.py
index bd5e736935b..48d90f15ad8 100644
--- a/airflow-core/src/airflow/cli/commands/connection_command.py
+++ b/airflow-core/src/airflow/cli/commands/connection_command.py
@@ -29,6 +29,7 @@ from urllib.parse import urlsplit, urlunsplit
from sqlalchemy import select
from sqlalchemy.orm import exc
+from airflow._shared.secrets_masker import redact
from airflow.cli.simple_table import AirflowConsole
from airflow.cli.utils import (
SENSITIVE_PLACEHOLDER,
@@ -365,22 +366,19 @@ def connections_add(args):
with create_session() as session:
if not session.scalar(select(Connection).where(Connection.conn_id ==
new_conn.conn_id).limit(1)):
session.add(new_conn)
- msg = "Successfully added `conn_id`={conn_id} : {uri}"
- msg = msg.format(
- conn_id=new_conn.conn_id,
- uri=args.conn_uri
- or urlunsplit(
- (
- new_conn.conn_type,
- f"{new_conn.login or ''}:{'******' if
new_conn.password else ''}"
- f"@{new_conn.host or ''}:{new_conn.port or ''}",
- new_conn.schema or "",
- "",
- "",
- )
- ),
+ print(f"Successfully added `conn_id`={new_conn.conn_id}")
+ AirflowConsole().print_as(
+ data=[new_conn],
+ output="table",
+ mapper=lambda conn: {
+ "conn_id": conn.conn_id,
+ "conn_type": conn.conn_type,
+ "host": conn.host,
+ "login": conn.login,
+ "port": conn.port,
+ "extra": redact(conn.extra_dejson),
+ },
)
- print(msg)
else:
msg = f"A connection with `conn_id`={new_conn.conn_id} already
exists."
raise SystemExit(msg)
diff --git a/airflow-core/tests/unit/cli/commands/test_connection_command.py
b/airflow-core/tests/unit/cli/commands/test_connection_command.py
index 2bb77b2db68..8f285d2db0b 100644
--- a/airflow-core/tests/unit/cli/commands/test_connection_command.py
+++ b/airflow-core/tests/unit/cli/commands/test_connection_command.py
@@ -481,7 +481,7 @@ class TestCliAddConnections:
"new0-json",
f"--conn-json={TEST_JSON}",
],
- "Successfully added `conn_id`=new0-json :
postgres://airflow:******@host:5432/airflow",
+ "Successfully added `conn_id`=new0-json",
{
"conn_type": "postgres",
"description": "new0-json description",
@@ -503,7 +503,7 @@ class TestCliAddConnections:
f"--conn-uri={TEST_URL}",
"--conn-description=new0 description",
],
- "Successfully added `conn_id`=new0 :
postgresql://airflow:airflow@host:5432/airflow",
+ "Successfully added `conn_id`=new0",
{
"conn_type": "postgres",
"description": "new0 description",
@@ -525,7 +525,7 @@ class TestCliAddConnections:
f"--conn-uri={TEST_URL}",
"--conn-description=new1 description",
],
- "Successfully added `conn_id`=new1 :
postgresql://airflow:airflow@host:5432/airflow",
+ "Successfully added `conn_id`=new1",
{
"conn_type": "postgres",
"description": "new1 description",
@@ -548,7 +548,7 @@ class TestCliAddConnections:
"--conn-extra",
'{"extra": "yes"}',
],
- "Successfully added `conn_id`=new2 :
postgresql://airflow:airflow@host:5432/airflow",
+ "Successfully added `conn_id`=new2",
{
"conn_type": "postgres",
"description": None,
@@ -573,7 +573,7 @@ class TestCliAddConnections:
"--conn-description",
"new3 description",
],
- "Successfully added `conn_id`=new3 :
postgresql://airflow:airflow@host:5432/airflow",
+ "Successfully added `conn_id`=new3",
{
"conn_type": "postgres",
"description": "new3 description",
@@ -600,7 +600,7 @@ class TestCliAddConnections:
"--conn-schema=airflow",
"--conn-description= new4 description ",
],
- "Successfully added `conn_id`=new4 :
hive_metastore://airflow:******@host:9083/airflow",
+ "Successfully added `conn_id`=new4",
{
"conn_type": "hive_metastore",
"description": " new4 description ",
@@ -626,7 +626,7 @@ class TestCliAddConnections:
'{"extra": "yes"}',
"--conn-description=new5 description",
],
- "Successfully added `conn_id`=new5 :
google_cloud_platform://:@:",
+ "Successfully added `conn_id`=new5",
{
"conn_type": "google_cloud_platform",
"description": "new5 description",
@@ -642,7 +642,7 @@ class TestCliAddConnections:
),
pytest.param(
["connections", "add", "new6", "--conn-uri",
"aws://?region_name=foo-bar-1"],
- "Successfully added `conn_id`=new6 :
aws://?region_name=foo-bar-1",
+ "Successfully added `conn_id`=new6",
{
"conn_type": "aws",
"description": None,
@@ -658,7 +658,7 @@ class TestCliAddConnections:
),
pytest.param(
["connections", "add", "new7", "--conn-uri",
"aws://@/?region_name=foo-bar-1"],
- "Successfully added `conn_id`=new7 :
aws://@/?region_name=foo-bar-1",
+ "Successfully added `conn_id`=new7",
{
"conn_type": "aws",
"description": None,