Documentation
¶
Index ¶
- Constants
- func ApplyClientHeaders(req *http.Request)
- func BuildOAuthTokenSource(cfg *config.Config) oauth2.TokenSource
- func CheckResponse(resp *http.Response, body []byte) error
- func MaybePersistRefreshedOAuthToken(cfg *config.Config, tok *oauth2.Token, mu *sync.Mutex)
- func NewAuthRequestEditor(cfg *config.Config) func(context.Context, *http.Request) error
- func NewAuthedHTTPClient(cfg *config.Config, maxRetries int, timeout time.Duration) *http.Client
- func NewClientHeadersTransport(base http.RoundTripper) http.RoundTripper
- func SetClientInfo(info ClientInfo)
- func UserAgent() string
- type APIError
- type Client
- type ClientInfo
Constants ¶
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
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 ¶
CheckResponse returns nil for 2xx responses or an *APIError describing the failure for non-2xx responses.
func MaybePersistRefreshedOAuthToken ¶ added in v0.10.0
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
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
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.
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.
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.
type ClientInfo ¶ added in v0.21.0
ClientInfo identifies this CLI process to the Oodle servers.