Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add af instance discover command for auto-discovering Astro deployments#63

Merged
schnie merged 25 commits intomainfrom
auto-discover-instances
Feb 4, 2026
Merged

Add af instance discover command for auto-discovering Astro deployments#63
schnie merged 25 commits intomainfrom
auto-discover-instances

Conversation

@schnie
Copy link
Member

@schnie schnie commented Jan 30, 2026

Summary

Adds a new af instance discover command that auto-discovers Airflow instances from multiple backends and populates the af config.

Discovery backends:

  • astro: Discovers Astro deployments via the Astro CLI, creates deployment tokens for authentication
  • local: Scans local ports for running Airflow instances (checks .astro/config.yaml first, then common ports)

Usage

# Discover from all backends
# This should cover most cases if using the CLI the way we expect
af instance discover

# Astro-specific discovery with options
af instance discover astro                  # Current workspace only
af instance discover astro --all-workspaces # All accessible workspaces

# Local-specific discovery with options
af instance discover local                  # Scan common Airflow ports
af instance discover local --scan           # Deep scan all ports 1024-65535

# Common options (work with all commands)
af instance discover --dry-run              # Preview without making changes
af instance discover --overwrite            # Overwrite existing instances
af instance discover astro --dry-run        # Can combine with subcommands

Other instance commands:

af instance list                # List all configured instances
af instance reset               # Reset config to default (localhost:8080)
af instance reset --force       # Skip confirmation prompt

Note: af inst and af instances work as aliases for af instance.

Example Output

Discovery backends: astro, local

Astro context: cloud.astronomer.io
Astro scope: current workspace

Discovering instances...

Found 2 instance(s):

NAME            SOURCE  URL                                      STATUS   ACTION
prod-app        astro   https://xyz.astronomer.run/...           HEALTHY  add
localhost:8080  local   http://localhost:8080                    -        add

Processing prod-app...
  Creating token 'af-cli-discover'...
  Added prod-app (auth: token)
Processing localhost:8080...
  Added localhost:8080 (auth: none)

Successfully added 2 instance(s).

Implementation Notes

  • Pluggable backend registry for discovery sources
  • Discover subcommands isolate backend-specific flags (--all-workspaces for astro, --scan for local)
  • Local backend checks .astro/config.yaml for configured port before scanning common ports
  • Scan mode uses async port scanning for wide port range discovery
  • Instance naming: localhost:{port} for local, {workspace}-{deployment} for Astro
  • Default config uses localhost:8080 to match local discovery naming
  • Stores source field to track where instances were discovered from
  • Token naming convention: af-cli-discover
  • Moved astro_cli.py under discovery/ module (only used for discovery)

Test plan

  • Unit tests pass
  • Manual test with real Astro account
  • Verify af instance list shows discovered instances with source
  • Verify discovered instances work with af dags list
  • Verify af instance reset restores default config

🤖 Generated with Claude Code

@schnie schnie force-pushed the auto-discover-instances branch 5 times, most recently from ebfb672 to a028213 Compare February 2, 2026 20:06
@schnie schnie marked this pull request as ready for review February 2, 2026 20:17
schnie and others added 20 commits February 2, 2026 15:48
- Use ternary operator for instance name generation
- Remove unused variable `pos`
- Combine nested `with` statements in tests

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add nosec comments for legitimate subprocess and token name usage
- Apply ruff formatting

Co-Authored-By: Claude Opus 4.5 <[email protected]>
The adapter adds /api/v2 or /api/v1 when making requests, so we
should store the base webserver URL, not the full API URL which
already includes /api/v2.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Existing instances are already skipped by default. The flag was
redundant since it had the same behavior as the default.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Co-Authored-By: Claude Opus 4.5 <[email protected]>
Simplify the discover command by removing the prefix option.
Instance names are now always generated as {workspace}-{deployment}.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Apply ruff format to instances.py and local.py
- Exclude skills/ from mypy to fix duplicate "tests" module error
- Fix bandit config path to astro-airflow-mcp/pyproject.toml

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Simplify AUTH_ERROR_KEYWORDS to match actual CLI output
- Extract _run_list_command helper to reduce repetitive code
- Use any() for cleaner auth error checking
- Improve token extraction comments

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Fix bandit config path from astro-airflow-mcp/pyproject.toml to
  pyproject.toml (prek runs from the directory containing the config)
- Remove skills/ from exclude patterns (no skills dir in this project)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Move astro/astro_cli.py to discovery/astro_cli.py (only used for discovery)
- Refactor instances.py to use AstroDiscoveryBackend for token operations
  instead of direct AstroCli usage (removes duplicate logic)
- Delete empty astro/ package
- Update all imports in tests

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Refactor discover command into subcommands:
  - `af instance discover` - all backends
  - `af instance discover astro --all-workspaces` - Astro-specific
  - `af instance discover local --scan` - Local-specific
- Add `af instance reset` command to restore default config
- Change default instance name to `localhost:8080` format to match
  local discovery naming convention
- Add `inst` as shorthand alias for `instance` command

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@schnie schnie force-pushed the auto-discover-instances branch from a028213 to 31dddc0 Compare February 2, 2026 20:48
@schnie schnie requested review from jlaneve, kaxil and milton-li February 2, 2026 20:54
@schnie schnie force-pushed the auto-discover-instances branch from 8af6c25 to ed774c6 Compare February 3, 2026 00:19
@schnie schnie force-pushed the auto-discover-instances branch from ed774c6 to 3b21c83 Compare February 3, 2026 00:47
@schnie schnie force-pushed the auto-discover-instances branch from ad233fd to cebffb2 Compare February 3, 2026 00:57
Copy link
Collaborator

@tayloramurphy tayloramurphy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving for docs and confirming I tested locally on an astro and privately hosted airflow instance.

| `--auth-token` | `AIRFLOW_AUTH_TOKEN` | `None` | Bearer token for authentication |
| `--username` | `AIRFLOW_USERNAME` | `None` | Username for authentication (Airflow 3.x uses OAuth2 token exchange) |
| `--password` | `AIRFLOW_PASSWORD` | `None` | Password for authentication |
| `--airflow-project-dir` | `AIRFLOW_PROJECT_DIR` | `$PWD` | Astro project directory for auto-discovering Airflow URL |
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jlaneve what do you think here? I kind of settled on env vars then the config file managed by af instance commands. I don't know if supporting the flags is worth it.

@schnie schnie merged commit e9e1a4d into main Feb 4, 2026
10 checks passed
@schnie schnie deleted the auto-discover-instances branch February 4, 2026 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants