cli: add `entire api` authenticated passthrough (core + cell) · Entire
cli: add entire api authenticated passthrough (core + cell)
a7e9795→main· Soph·2w ago·4 files·+579 added/-0 removed
A gh api-style escape hatch: make an authenticated request to an Entire API and print the JSON response, with the CLI attaching the right bearer and dialing the right host.
API Commands
entire api /api/v1/clusters# control planeentire api --to cell /api/v1/me/activity# home entire-api cellentire api --to cell "/api/v1/me/recap?repo={repo_id}"--to core (default)reuses the same bearer resolution asauth token(honorsENTIRE_TOKEN, else the active context);--to cellmints the jurisdictional token viaNewEntireAPICellClient. Data API is omitted deliberately — it's being retired.Placeholders filled from the origin remote:
{owner},{repo}, and{repo_id}(the repo's ULID, resolved from its mirror) — the last is what cell endpoints key on.Method defaults to
GET, orPOSTwhen-f/-Ffields or--inputis given;-Xoverrides.GET + fieldsgo on the query string.-Hadds headers,-iprints status + headers, and JSON responses are pretty-printed.Adds
api.Client.Requestas the general method/header escape hatch behind it.
Sessions
e7709d561284View transcript
Changes
4
- cmd/entire/cli
148 unmodified lines
return c.do(ctx, http.MethodDelete, path, nil, nil)
}
// Request sends an authenticated request with an explicit method, optional
// extra headers, and an optional raw body. It’s the general-purpose escape
// hatch behind `entire api`; prefer the typed verbs (Get/Post/…) for normal
// use. The bearer, User-Agent, and default Accept are still attached by the
// transport; a body still gets Content-Type: application/json.
func (c *Client) Request(ctx context.Context, method, path string, headers http.Header, body io.Reader) (*http.Response, error) {
return c.do(ctx, method, path, body, headers)
}
func (c *Client) do(ctx context.Context, method, path string, body io.Reader, headers http.Header) (*http.Response, error) {
endpoint, err := ResolveURLFromBase(c.baseURL, path)
if err != nil {
Additional Code
package cli
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"net/url"
"os"
"sort"
"strconv"
"strings"
"github.com/spf13/cobra"
"github.com/entireio/cli/cmd/entire/cli/api"
"github.com/entireio/cli/cmd/entire/cli/auth"
"github.com/entireio/cli/cmd/entire/cli/gitremote"
"github.com/entireio/cli/internal/coreapi"
)
// Function Definitions
// ...
const apiMaxResponseBytes = 32 << 20 // 32 MiB cap on a printed response body.
// Functions related to API handling, Context resolution, and request handling
// ...
// Test functions
// ...