api

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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.

Types

type APIError

type APIError struct {
	StatusCode int
	Code       string
	Message    string
	Cause      string
	Remedy     string
	TraceID    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.

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.

Jump to

Keyboard shortcuts

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