api

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package api wraps HTTP calls to the DBGorilla backend.

v0.1.0 surface is minimal -- only the endpoints needed for login, identity lookup, and MCP API key management. All requests carry a Bearer token from the keychain when one is present; refresh-on-401 happens automatically via the refresh token if available.

Security notes:

  • When the client is not in insecure mode, the redirect policy refuses to follow a redirect that would downgrade to a non-https URL. This prevents a malicious server from steering a Bearer-bearing request to plaintext (which Go's stdlib already strips Authorization on for cross-host redirects, but a same-host http downgrade would still expose other custom headers).
  • The User-Agent advertises the CLI version so backend abuse-detection and forensic logs can identify the client.

Index

Constants

This section is empty.

Variables

View Source
var ErrCollectorUnsupported = errors.New("this deployment does not support the managed collector (needs a main-based backend)")

ErrCollectorUnsupported is returned when the deployment has no managed collector API (the release line, or a backend predating v0_2).

Functions

func SetUserAgentVersion

func SetUserAgentVersion(v string)

SetUserAgentVersion lets cmd inject the build-time version string into the User-Agent header at startup. Safe to call from any goroutine before the first request.

Types

type Client

type Client struct {
	BaseURL    string
	HTTPClient *http.Client
}

Client wraps HTTP calls to the DBGorilla backend API.

func NewClient

func NewClient(baseURL string) *Client

NewClient creates an API client for the given base URL.

func NewInsecureClient

func NewInsecureClient(baseURL string) *Client

NewInsecureClient skips TLS certificate verification. Use only for internal/dev environments with self-signed certs.

func (*Client) CollectorSupported added in v0.2.0

func (c *Client) CollectorSupported() (bool, error)

CollectorSupported probes whether the deployment exposes the v0_2 collector API. A 404 means unsupported (release line); any other reachable status (including auth challenges) means the route exists.

func (*Client) DeleteCollector added in v0.2.0

func (c *Client) DeleteCollector(agentID string) error

DeleteCollector deprovisions a collector identity; its credentials stop working immediately. A 404 is treated as already-gone (idempotent).

func (*Client) Do

func (c *Client) Do(method, path string, body any) ([]byte, int, error)

Do performs an authenticated HTTP request. Returns the response body bytes, status code, and any error.

func (*Client) FetchCollectorStatus added in v0.2.0

func (c *Client) FetchCollectorStatus(agentID string) (*CollectorStatus, error)

FetchCollectorStatus calls GET /api/v0_2/collectors/{id}/status. A 404 maps to (nil, nil) — the collector is not known to the control plane yet.

func (*Client) Get

func (c *Client) Get(path string) ([]byte, int, error)

Get performs an authenticated GET request.

func (*Client) ListCollectors added in v0.2.0

func (c *Client) ListCollectors() ([]map[string]any, error)

ListCollectors returns the tenant's collector agents. The bridge's AgentPage envelope key isn't pinned, so we accept the common shapes (items/agents/data) or a bare array and return the records as generic maps for display.

func (*Client) Post

func (c *Client) Post(path string, body any) ([]byte, int, error)

Post performs an authenticated POST request.

func (*Client) ProvisionCollector added in v0.2.0

func (c *Client) ProvisionCollector() (*CollectorCredentials, error)

ProvisionCollector mints a new collector identity. The caller's user token authorizes the mint; the backend (via the dbg-ingest bridge) creates the Keycloak client and returns its credentials.

type CollectorCredentials added in v0.2.0

type CollectorCredentials struct {
	AgentID  string `json:"agent_id"`
	Secret   string `json:"secret"`
	TenantID string `json:"tenant_id"`
	Domain   string `json:"domain"`
	// Optional per-service endpoints (contract agreed with backend; populated
	// only for non-prod/self-hosted deployments). Empty -> the collector uses
	// its built-in production defaults.
	KeycloakBaseURL string `json:"keycloak_base_url,omitempty"`
	OtlpBaseURL     string `json:"otlp_base_url,omitempty"`
	OpampBaseURL    string `json:"opamp_base_url,omitempty"`
	// PreferredCollectorVersion is the collector version the deployment blesses
	// for this environment (e.g. "0.1.0"). Empty -> the CLI uses its built-in
	// default image. The CLI pins this version unless --image overrides it.
	PreferredCollectorVersion string `json:"preferred_collector_version,omitempty"`
}

CollectorCredentials is the response from POST /api/v0_2/collectors. The secret is returned exactly once. agent_id is the OAuth client_id; domain is the deployment domain for the collector's endpoints.

type CollectorStatus added in v0.2.0

type CollectorStatus struct {
	Status string         `json:"status"`
	Raw    map[string]any `json:"-"`
}

CollectorStatus returns the live connection status for a collector. The shape is the dbg-ingest bridge StatusResponse, passed through; we surface the raw JSON plus a best-effort status string.

type ErrorResponse

type ErrorResponse struct {
	Detail string `json:"detail"`
}

ErrorResponse is the standard FastAPI error response.

type UserInfo

type UserInfo struct {
	Username       string `json:"username"`
	Email          string `json:"email"`
	Tenant         string `json:"tenant"`
	UserID         string `json:"user_id"`
	TenantID       string `json:"tenant_id"`
	IsAdmin        bool   `json:"is_admin"`
	IsSystemTenant bool   `json:"is_system_tenant"`
}

UserInfo matches GET /api/v0_1/auth/user on backend release-202603.007. `tenant` is the organization display name; `tenant_id` is the UUID.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL