api

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// ClientHeader holds "oodle-cli/<version>".
	ClientHeader = "OODLE-CLIENT"
	// ClientAgentHeader holds the name of the AI coding agent that
	// runs the CLI. It is not sent when no agent is detected.
	ClientAgentHeader = "OODLE-CLIENT-AGENT"
	// ClientCommandHeader holds the command path without the binary
	// name, for example "logs query".
	ClientCommandHeader = "OODLE-CLIENT-COMMAND"
)

Headers that name the client on every request to Oodle. The Oodle servers read them to attribute work to oodle-cli, and to tell a CLI run by an AI coding agent apart from one run by a person. Without them a CLI request looks the same as any other Go program.

Variables

This section is empty.

Functions

func ApplyClientHeaders added in v0.21.0

func ApplyClientHeaders(req *http.Request)

ApplyClientHeaders sets the User-Agent and the OODLE-CLIENT headers on req. Use it for a request that does not go through a client from this package.

func BuildOAuthTokenSource added in v0.10.0

func BuildOAuthTokenSource(cfg *config.Config) oauth2.TokenSource

BuildOAuthTokenSource creates an oauth2.TokenSource from the given config. If refresh credentials are available, the source auto-refreshes expired tokens.

func CheckResponse

func CheckResponse(resp *http.Response, body []byte) error

CheckResponse returns nil for 2xx responses or an *APIError describing the failure for non-2xx responses.

func MaybePersistRefreshedOAuthToken added in v0.10.0

func MaybePersistRefreshedOAuthToken(cfg *config.Config, tok *oauth2.Token, mu *sync.Mutex)

MaybePersistRefreshedOAuthToken writes a refreshed token back to the config file if the access token, refresh token, or expiry has changed.

func NewAuthRequestEditor added in v0.13.0

func NewAuthRequestEditor(cfg *config.Config) func(context.Context, *http.Request) error

NewAuthRequestEditor returns a request editor that applies Oodle authentication: an OAuth Bearer token when one is configured (refreshing and persisting it as needed), falling back to the API key.

Exported so hand-rolled clients for endpoints the generated OpenAPI client does not cover (e.g. the Grafana migration endpoints) authenticate exactly like every other command, rather than hardcoding X-API-Key and silently failing for OAuth-only users.

func NewAuthedHTTPClient added in v0.13.0

func NewAuthedHTTPClient(
	cfg *config.Config,
	maxRetries int,
	timeout time.Duration,
) *http.Client

NewAuthedHTTPClient returns an http.Client that authenticates and retries the same way the generated API client does. `timeout` overrides the default request timeout, which matters for uploads far larger than a normal API call.

func NewClientHeadersTransport added in v0.21.0

func NewClientHeadersTransport(base http.RoundTripper) http.RoundTripper

NewClientHeadersTransport wraps base so that every request names this CLI. A nil base means http.DefaultTransport.

func SetClientInfo added in v0.21.0

func SetClientInfo(info ClientInfo)

SetClientInfo records the identity that every later request sends. The root command calls it once, before any client is built. A process runs one command, so a package-level value is enough.

func UserAgent added in v0.21.0

func UserAgent() string

UserAgent returns the User-Agent this CLI sends. Traces record the User-Agent of each request, so it names the CLI, the agent and the command even where the servers do not read the OODLE-CLIENT headers.

Types

type APIError

type APIError struct {
	StatusCode int
	Code       string
	Message    string
	Cause      string
	Remedy     string
	TraceID    string
	// Details is printed last, after all other parts. It holds
	// lists such as the objects that block a delete, which read
	// badly with other parts after them.
	Details string
}

APIError is the structured representation of a non-2xx Oodle API response.

func (*APIError) Error

func (e *APIError) Error() string

Error implements the error interface. An empty code or trace is left out, because "(code: , trace: )" tells the user nothing.

type Client

type Client struct {
	// Inner is exported so command files can call generated methods directly.
	Inner  *client.ClientWithResponses
	Config *config.Config
	// contains filtered or unexported fields
}

Client wraps the generated OpenAPI client and adds Oodle-specific behaviour: API-key injection, retries on transient failures, and friendly error formatting.

func NewClient

func NewClient(cfg *config.Config, maxRetries int) (*Client, error)

NewClient constructs a Client for the given config.

func (*Client) NewAuthedHTTPClient added in v0.13.0

func (c *Client) NewAuthedHTTPClient(timeout time.Duration) *http.Client

NewAuthedHTTPClient returns an http.Client that shares this client's auth and retry behaviour, for endpoints the generated OpenAPI client does not cover.

type ClientInfo added in v0.21.0

type ClientInfo struct {
	Version string
	Command string
	Agent   string
}

ClientInfo identifies this CLI process to the Oodle servers.

Jump to

Keyboard shortcuts

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