Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 11 additions & 5 deletions airflow-ctl/src/airflowctl/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,17 @@ def load(self) -> Credentials:
debug_creds_path = os.path.join(
default_config_dir, f"debug_creds_{self.input_cli_config_file}"
)
with open(debug_creds_path) as df:
debug_credentials = json.load(df)
self.api_token = debug_credentials.get(
self.token_key_for_environment(self.api_environment)
)
try:
with open(debug_creds_path) as df:
debug_credentials = json.load(df)
self.api_token = debug_credentials.get(self.token_key_for_environment(self.api_environment))
except FileNotFoundError as e:
if self.client_kind == ClientKind.CLI:
raise AirflowCtlCredentialNotFoundException(
f"Debug credentials file not found: {debug_creds_path}. "
"Set AIRFLOW_CLI_DEBUG_MODE=false or log in with debug mode enabled first."
) from e
self.api_token = None
else:
try:
self.api_token = keyring.get_password(
Expand Down
18 changes: 17 additions & 1 deletion airflow-ctl/tests/airflow_ctl/api/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@

from airflowctl.api.client import Client, ClientKind, Credentials, _bounded_get_new_password
from airflowctl.api.operations import ServerResponseError
from airflowctl.exceptions import AirflowCtlCredentialNotFoundException, AirflowCtlKeyringException
from airflowctl.exceptions import (
AirflowCtlCredentialNotFoundException,
AirflowCtlKeyringException,
)


def make_client_w_responses(responses: list[httpx.Response]) -> Client:
Expand Down Expand Up @@ -376,3 +379,16 @@ def test_retry_handling_ok(self):
response = client.get("http://error")
assert response.status_code == 200
assert len(responses) == 1

def test_debug_mode_missing_debug_creds_reports_correct_error(self, monkeypatch, tmp_path):
monkeypatch.setenv("AIRFLOW_HOME", str(tmp_path))
monkeypatch.setenv("AIRFLOW_CLI_DEBUG_MODE", "true")
monkeypatch.setenv("AIRFLOW_CLI_ENVIRONMENT", "TEST_DEBUG")

config_path = tmp_path / "TEST_DEBUG.json"
config_path.write_text(json.dumps({"api_url": "http://localhost:8080"}), encoding="utf-8")
# Intentionally do not create debug_creds_TEST_DEBUG.json to simulate a missing file

creds = Credentials(client_kind=ClientKind.CLI, api_environment="TEST_DEBUG")
with pytest.raises(AirflowCtlCredentialNotFoundException, match="Debug credentials file not found"):
creds.load()
Loading