• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

astronomer / astro-cli / 9179bec0-e225-4e79-b8df-febc004cee17

05 Feb 2026 09:27PM UTC coverage: 34.998% (+1.8%) from 33.15%
9179bec0-e225-4e79-b8df-febc004cee17

Pull #2006

circleci

jeremybeard
Add `astro api` command for authenticated Airflow and Cloud API requests

Introduce the `astro api` top-level command with two subcommands:

  astro api airflow — make requests to the Airflow REST API (local or
  deployed), with automatic version detection (2.x, 3.0.x, 3.0.3+) and
  OpenAPI spec resolution.

  astro api cloud — make requests to the Astro Cloud platform API using
  the current context's bearer token.

Both subcommands support:
  - Endpoint discovery via `ls` and `describe` (parsed from OpenAPI specs)
  - Calling endpoints by operation ID or raw path
  - Pagination (per-page streaming or --slurp into a single array)
  - Response caching with TTL and automatic stale-entry cleanup
  - jq filters and Go-template output formatting
  - Colored JSON output
  - --curl flag to emit equivalent curl commands
  - Magic field syntax for request bodies (@file, :=json, =string)
  - Custom headers and path-parameter overrides

Supporting packages:
  - pkg/openapi: OpenAPI spec fetching, caching, endpoint indexing,
    Airflow version-range mapping, and schema introspection.

Includes unit tests for request handling, output formatting, field
parsing, OpenAPI version mapping, endpoint indexing, and caching.
Pull Request #2006: Add `astro api` command

1998 of 2386 new or added lines in 13 files covered. (83.74%)

22863 of 65327 relevant lines covered (35.0%)

8.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/cmd/api/api.go
1
// Package api provides the 'astro api' command for making authenticated API requests.
2
package api
3

4
import (
5
        "io"
6
        "os"
7

8
        "github.com/fatih/color"
9
        "github.com/spf13/cobra"
10
)
11

12
// NewAPICmd creates the parent 'astro api' command.
NEW
13
func NewAPICmd() *cobra.Command {
×
NEW
14
        return NewAPICmdWithOutput(os.Stdout)
×
NEW
15
}
×
16

17
// NewAPICmdWithOutput creates the parent 'astro api' command with a custom output writer.
NEW
18
func NewAPICmdWithOutput(out io.Writer) *cobra.Command {
×
NEW
19
        var noColor bool
×
NEW
20

×
NEW
21
        cmd := &cobra.Command{
×
NEW
22
                Use:           "api",
×
NEW
23
                Short:         "Make authenticated API requests to Astronomer services",
×
NEW
24
                SilenceErrors: true, // API commands print error bodies themselves; don't let cobra double-print
×
NEW
25
                SilenceUsage:  true,
×
NEW
26
                Long: `Make authenticated HTTP requests to Astronomer APIs and print responses.
×
NEW
27

×
NEW
28
The 'astro api' command provides direct access to Astronomer's REST APIs.
×
NEW
29

×
NEW
30
Available subcommands:
×
NEW
31
  airflow  Make requests to the Airflow REST API
×
NEW
32
  cloud    Make requests to the Astro Cloud API (api.astronomer.io)
×
NEW
33

×
NEW
34
Use "astro api [command] --help" for more information about a command.`,
×
NEW
35
                PersistentPreRun: func(cmd *cobra.Command, args []string) {
×
NEW
36
                        if noColor {
×
NEW
37
                                color.NoColor = true
×
NEW
38
                        }
×
39
                },
NEW
40
                Run: func(cmd *cobra.Command, args []string) {
×
NEW
41
                        _ = cmd.Help()
×
NEW
42
                },
×
43
        }
44

NEW
45
        cmd.PersistentFlags().BoolVar(&noColor, "no-color", false, "Disable colorized output")
×
NEW
46

×
NEW
47
        cmd.AddCommand(NewAirflowCmd(out))
×
NEW
48
        cmd.AddCommand(NewCloudCmd(out))
×
NEW
49

×
NEW
50
        return cmd
×
51
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc