-
Notifications
You must be signed in to change notification settings - Fork 71
feat(cli): add agent-first Airbyte CLI for Cloud operations #1010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Aaron ("AJ") Steers (aaronsteers)
wants to merge
11
commits into
main
Choose a base branch
from
devin/1775171846-airbyte-cli
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
26c1f6a
feat(cli): add agent-first Airbyte CLI for Cloud operations
devin-ai-integration[bot] 3b13032
fix(cli): resolve pyrefly type errors in create_connection args
devin-ai-integration[bot] 30b016e
fix(cli): lazy auth resolution, YAML error handling, --force flag, st…
devin-ai-integration[bot] d155f0a
fix(cli): optional workspace_id, ID-only reads, Click standalone_mode…
devin-ai-integration[bot] 52b758a
fix(cli): add return after _error_json for pyrefly type narrowing
devin-ai-integration[bot] 64a950e
fix(cli): remove broad except Exception, use guard statements per cod…
devin-ai-integration[bot] 50a05cc
fix(cli): allow --describe to work without required options
devin-ai-integration[bot] afd3645
refactor(cli): replace --describe with --help --format=json
devin-ai-integration[bot] 2f2ded6
fix(cli): NoReturn annotation, workspace_id fallback, catch-all handler
devin-ai-integration[bot] 5f09e58
fix(cli): remove broad except Exception per coding standards
devin-ai-integration[bot] f090fa8
fix(cli): add return after _error_json for pyrefly type narrowing
devin-ai-integration[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| # Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
| """Credential resolution for the Airbyte CLI. | ||
|
|
||
| Resolution order: | ||
| 1. Explicit CLI flags (`--client-id`, `--client-secret`) | ||
| 2. Short env vars: `AIRBYTE_CLIENT_ID` / `AIRBYTE_CLIENT_SECRET` | ||
| 3. Long env vars: `AIRBYTE_CLOUD_CLIENT_ID` / `AIRBYTE_CLOUD_CLIENT_SECRET` | ||
| 4. Credentials file: `~/.airbyte/credentials` (YAML with `client_id` / `client_secret`) | ||
| 5. Error if none found | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| from pathlib import Path | ||
| from typing import Any | ||
|
|
||
| import yaml | ||
|
|
||
| from airbyte.constants import ( | ||
| CLOUD_API_ROOT, | ||
| CLOUD_CLIENT_ID_ENV_VAR, | ||
| CLOUD_CLIENT_SECRET_ENV_VAR, | ||
| CLOUD_WORKSPACE_ID_ENV_VAR, | ||
| ) | ||
| from airbyte.exceptions import PyAirbyteInputError | ||
|
|
||
|
|
||
| # Short-form env var names (preferred for CLI usage) | ||
| CLI_CLIENT_ID_ENV_VAR = "AIRBYTE_CLIENT_ID" | ||
| CLI_CLIENT_SECRET_ENV_VAR = "AIRBYTE_CLIENT_SECRET" | ||
| CLI_WORKSPACE_ID_ENV_VAR = "AIRBYTE_WORKSPACE_ID" | ||
| CLI_API_URL_ENV_VAR = "AIRBYTE_API_URL" | ||
|
|
||
| CREDENTIALS_FILE_PATH = Path("~/.airbyte/credentials").expanduser() | ||
|
|
||
|
|
||
| def _read_credentials_file() -> dict[str, Any]: | ||
| """Read credentials from `~/.airbyte/credentials` if the file exists. | ||
|
|
||
| The file is expected to be YAML with `client_id` and `client_secret` keys. | ||
|
|
||
| Returns an empty dict if the file does not exist or cannot be parsed. | ||
| """ | ||
| if not CREDENTIALS_FILE_PATH.exists(): | ||
| return {} | ||
|
|
||
| content = CREDENTIALS_FILE_PATH.read_text(encoding="utf-8").strip() | ||
| if not content: | ||
| return {} | ||
|
|
||
| parsed = yaml.safe_load(content) | ||
| if not isinstance(parsed, dict): | ||
| return {} | ||
|
|
||
| return parsed | ||
|
|
||
|
|
||
| def resolve_client_id(explicit: str | None = None) -> str: | ||
| """Resolve the Airbyte client ID. | ||
|
|
||
| Resolution order: explicit arg, short env var, long env var, credentials file. | ||
| """ | ||
| if explicit: | ||
| return explicit | ||
|
|
||
| from_short_env = os.environ.get(CLI_CLIENT_ID_ENV_VAR) | ||
| if from_short_env: | ||
| return from_short_env | ||
|
|
||
| from_long_env = os.environ.get(CLOUD_CLIENT_ID_ENV_VAR) | ||
| if from_long_env: | ||
| return from_long_env | ||
|
|
||
| creds = _read_credentials_file() | ||
| from_file = creds.get("client_id") | ||
| if from_file: | ||
| return str(from_file) | ||
|
|
||
| raise PyAirbyteInputError( | ||
| message="No Airbyte client ID found.", | ||
| guidance=( | ||
| f"Set the `{CLI_CLIENT_ID_ENV_VAR}` environment variable, " | ||
| f"or create a credentials file at {CREDENTIALS_FILE_PATH} " | ||
| "with a `client_id` key." | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| def resolve_client_secret(explicit: str | None = None) -> str: | ||
| """Resolve the Airbyte client secret. | ||
|
|
||
| Resolution order: explicit arg, short env var, long env var, credentials file. | ||
| """ | ||
| if explicit: | ||
| return explicit | ||
|
|
||
| from_short_env = os.environ.get(CLI_CLIENT_SECRET_ENV_VAR) | ||
| if from_short_env: | ||
| return from_short_env | ||
|
|
||
| from_long_env = os.environ.get(CLOUD_CLIENT_SECRET_ENV_VAR) | ||
| if from_long_env: | ||
| return from_long_env | ||
|
|
||
| creds = _read_credentials_file() | ||
| from_file = creds.get("client_secret") | ||
| if from_file: | ||
| return str(from_file) | ||
|
|
||
| raise PyAirbyteInputError( | ||
| message="No Airbyte client secret found.", | ||
| guidance=( | ||
| f"Set the `{CLI_CLIENT_SECRET_ENV_VAR}` environment variable, " | ||
| f"or create a credentials file at {CREDENTIALS_FILE_PATH} " | ||
| "with a `client_secret` key." | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| def resolve_workspace_id(explicit: str | None = None) -> str: | ||
| """Resolve the Airbyte workspace ID. | ||
|
|
||
| Resolution order: explicit arg, short env var, long env var, credentials file. | ||
| """ | ||
| if explicit: | ||
| return explicit | ||
|
|
||
| from_short_env = os.environ.get(CLI_WORKSPACE_ID_ENV_VAR) | ||
| if from_short_env: | ||
| return from_short_env | ||
|
|
||
| from_long_env = os.environ.get(CLOUD_WORKSPACE_ID_ENV_VAR) | ||
| if from_long_env: | ||
| return from_long_env | ||
|
|
||
| creds = _read_credentials_file() | ||
| from_file = creds.get("workspace_id") | ||
| if from_file: | ||
| return str(from_file) | ||
|
|
||
| raise PyAirbyteInputError( | ||
| message="No Airbyte workspace ID found.", | ||
| guidance=( | ||
| f"Set the `{CLI_WORKSPACE_ID_ENV_VAR}` environment variable, " | ||
| f"or create a credentials file at {CREDENTIALS_FILE_PATH} " | ||
| "with a `workspace_id` key." | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| def resolve_api_url(explicit: str | None = None) -> str: | ||
| """Resolve the Airbyte API URL. | ||
|
|
||
| Resolution order: explicit arg, short env var, long env var, default. | ||
| """ | ||
| if explicit: | ||
| return explicit | ||
|
|
||
| from_short_env = os.environ.get(CLI_API_URL_ENV_VAR) | ||
| if from_short_env: | ||
| return from_short_env | ||
|
|
||
| from_long_env = os.environ.get("AIRBYTE_CLOUD_API_URL") | ||
| if from_long_env: | ||
| return from_long_env | ||
|
|
||
| creds = _read_credentials_file() | ||
| from_file = creds.get("api_url") | ||
| if from_file: | ||
| return str(from_file) | ||
|
|
||
| return CLOUD_API_ROOT | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.