Skip to content
Open
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
15 changes: 13 additions & 2 deletions airflow-ctl/src/airflowctl/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ def plugins(self):
def get_client(
kind: Literal[ClientKind.CLI, ClientKind.AUTH, ClientKind.NO_AUTH] = ClientKind.CLI,
api_token: str | None = None,
api_environment: str | None = None,
):
"""
Get CLI API client.
Expand All @@ -487,13 +488,18 @@ def get_client(
"""
api_client = None
api_token = api_token or os.getenv("AIRFLOW_CLI_TOKEN", None)
api_environment = api_environment or "production"
Comment thread
ASk1 marked this conversation as resolved.
try:
# API URL always loaded from the config file, please save with it if you are using other than ClientKind.CLI
if kind == ClientKind.NO_AUTH:
credentials = Credentials(client_kind=kind).load()
resolved_token = None
else:
credentials = Credentials(client_kind=kind, api_token=api_token).load()
credentials = Credentials(
client_kind=kind,
api_token=api_token,
api_environment=api_environment,
).load()
resolved_token = api_token or credentials.api_token
api_client = Client(
base_url=credentials.api_url or "http://localhost:8080",
Expand Down Expand Up @@ -527,7 +533,12 @@ def decorator(func: Callable[PS, RT]) -> Callable[PS, RT]:
def wrapper(*args, **kwargs) -> RT:
if "api_client" not in kwargs:
api_token = getattr(args[0], "api_token", None) if args else None
with get_client(kind=kind, api_token=api_token) as api_client:
api_environment = getattr(args[0], "env", None) if args else None
with get_client(
kind=kind,
api_token=api_token,
api_environment=api_environment,
) as api_client:
return func(*args, api_client=api_client, **kwargs)
# The CLI API Client should be only passed for Mocking and Testing
return func(*args, **kwargs)
Expand Down
Loading