diff --git a/airflow-ctl/docs/images/command_hashes.txt b/airflow-ctl/docs/images/command_hashes.txt index 935d3d7dfb787..8865ab3e19827 100644 --- a/airflow-ctl/docs/images/command_hashes.txt +++ b/airflow-ctl/docs/images/command_hashes.txt @@ -3,7 +3,7 @@ assets:b3ae2b933e54528bf486ff28e887804d auth:f396d4bce90215599dde6ad0a8f30f29 backfills:725109470cd2613de8cc8af022fb54bc config:cb175bedf29e8a2c2c6a2ebd13d770a7 -connections:44e4da38aa214ccab4a1414a0c8967bb +connections:a16225e1c7d28488d0da612752669b4b dag:0c06fff60c0cc6618c8de05915506605 dagrun:ec1b6098822419967e621687bd7e5e4b jobs:7f8680afff230eb9940bc7fca727bd52 diff --git a/airflow-ctl/docs/images/output_connections.svg b/airflow-ctl/docs/images/output_connections.svg index 2fc625d01088a..85341bc74ea62 100644 --- a/airflow-ctl/docs/images/output_connections.svg +++ b/airflow-ctl/docs/images/output_connections.svg @@ -1,4 +1,4 @@ - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + - Command: connections + Command: connections - + - - Usage: airflowctl connections [-h] COMMAND ... - -Perform Connections operations - -Positional Arguments: -  COMMAND -    create         Perform create operation -    create-defaults -                   Perform create_defaults operation -    delete         Perform delete operation -    export         Export all connections -    get            Perform get operation -    import         Import connections -    list           Perform list operation -    test           Perform test operation -    update         Perform update operation - -Options: -  -h, --help       show this help message and exit + + Usage: airflowctl connections [-h] COMMAND ... + +Perform Connections operations + +Positional Arguments: +  COMMAND +    create         Perform create operation +    create-defaults +                   Perform create_defaults operation +    delete         Perform delete operation +    get            Perform get operation +    import         Import connections from a file. This feature is compatible  +with airflow CLI `airflow connections export a.json` command. Export it from  +`airflow CLI` and import it securely via this command. +    list           Perform list operation +    test           Perform test operation +    update         Perform update operation + +Options: +  -h, --help       show this help message and exit diff --git a/airflow-ctl/src/airflowctl/ctl/cli_config.py b/airflow-ctl/src/airflowctl/ctl/cli_config.py index 04cbee3d27f21..085fe5abec473 100644 --- a/airflow-ctl/src/airflowctl/ctl/cli_config.py +++ b/airflow-ctl/src/airflowctl/ctl/cli_config.py @@ -777,16 +777,12 @@ def merge_commands( CONNECTION_COMMANDS = ( ActionCommand( name="import", - help="Import connections", + help="Import connections from a file. " + "This feature is compatible with airflow CLI `airflow connections export a.json` command. " + "Export it from `airflow CLI` and import it securely via this command.", func=lazy_load_command("airflowctl.ctl.commands.connection_command.import_"), args=(Arg(flags=("file",), metavar="FILEPATH", help="Connections JSON file"),), ), - ActionCommand( - name="export", - help="Export all connections", - func=lazy_load_command("airflowctl.ctl.commands.connection_command.export"), - args=(ARG_FILE,), - ), ) POOL_COMMANDS = ( diff --git a/airflow-ctl/src/airflowctl/ctl/commands/connection_command.py b/airflow-ctl/src/airflowctl/ctl/commands/connection_command.py index d659571e8d6b0..8a894202206d8 100644 --- a/airflow-ctl/src/airflowctl/ctl/commands/connection_command.py +++ b/airflow-ctl/src/airflowctl/ctl/commands/connection_command.py @@ -72,22 +72,3 @@ def import_(args, api_client=NEW_API_CLIENT) -> None: except Exception as e: rich.print(f"[red]Failed to import connections: {e}[/red]") raise SystemExit - - -@provide_api_client(kind=ClientKind.CLI) -def export(args, api_client=NEW_API_CLIENT) -> None: - """Export connections to a file.""" - filepath = args.file - try: - connections = api_client.connections.list() - connection_dict = {} - for conn in connections.connections: - connection_dict[conn.connection_id] = conn.model_dump() - with open(Path(args.file), "w") as var_file: - json.dump(connection_dict, var_file, sort_keys=True, indent=4) - rich.print( - f"[green]Export successful! {connections.total_entries} connections(s) to {filepath}[/green]" - ) - except Exception as e: - rich.print(f"[red]Failed to export connections: {e}[/red]") - raise SystemExit(1) diff --git a/airflow-ctl/tests/airflow_ctl/ctl/commands/test_connections_command.py b/airflow-ctl/tests/airflow_ctl/ctl/commands/test_connections_command.py index 062e333a2e343..a63a4b4fa6aa6 100644 --- a/airflow-ctl/tests/airflow_ctl/ctl/commands/test_connections_command.py +++ b/airflow-ctl/tests/airflow_ctl/ctl/commands/test_connections_command.py @@ -17,7 +17,6 @@ from __future__ import annotations import json -import os import pytest @@ -126,35 +125,3 @@ def test_import_error(self, api_client_maker, tmp_path, monkeypatch): self.parser.parse_args(["connections", "import", expected_json_path.as_posix()]), api_client=api_client, ) - - def test_export(self, api_client_maker, tmp_path, monkeypatch): - api_client = api_client_maker( - path="/api/v2/connections", - response_json=self.connection_collection_response.model_dump(), - expected_http_status_code=200, - kind=ClientKind.CLI, - ) - - monkeypatch.chdir(tmp_path) - expected_json_path = (tmp_path / self.export_file_name).as_posix() - connection_command.export( - self.parser.parse_args(["connections", "export", expected_json_path]), - api_client=api_client, - ) - assert os.path.exists(tmp_path / self.export_file_name) - - connection_file = { - self.connection_id: { - "conn_type": "test_type", - "host": "test_host", - "login": "test_login", - "password": "test_password", - "port": 1234, - "extra": "{}", - "description": "Test connection description", - "connection_id": self.connection_id, - "schema_": None, - } - } - with open(expected_json_path) as f: - assert json.load(f) == connection_file