Documentation
¶
Overview ¶
Package client wraps mistapi-go for mistctl: it builds an authenticated, GET-only SDK client and returns raw JSON so output matches the API exactly.
Index ¶
- Constants
- Variables
- func ListAll(ctx context.Context, max int, ...) ([]json.RawMessage, error)
- func PagedAll(ctx context.Context, max int, ...) ([]json.RawMessage, error)
- func ParseUUID(s string) (uuid.UUID, bool)
- func Ptr[T comparable](v T) *T
- func SearchAll(ctx context.Context, max int, ...) ([]json.RawMessage, error)
- func SearchFiltered(ctx context.Context, max int, keep func(json.RawMessage) bool, ...) ([]json.RawMessage, error)
- func ShellHTTPClient() *http.Client
- func WithQuery(ctx context.Context, key, value string) context.Context
- type APIError
- type Client
- type ErrNotReadOnly
- type Raw
Constants ¶
const PageSize = 1000
PageSize is the page size used for list endpoints (Mist maximum).
Variables ¶
var BaseTransport http.RoundTripper = http.DefaultTransport
BaseTransport is the underlying HTTP transport. Tests replace it to point the client at a fake API.
Functions ¶
func ListAll ¶
func ListAll(ctx context.Context, max int, fetch func(ctx context.Context, limit, page int) (Raw, error)) ([]json.RawMessage, error)
ListAll follows limit/page pagination of endpoints that return a JSON array, until all items (or max items when max > 0) are collected.
The end is detected from X-Page-Total when the API sends it; otherwise a page shorter than the server's effective page size (X-Page-Limit, or the requested limit) ends the listing. An empty page always ends it.
func PagedAll ¶
func PagedAll(ctx context.Context, max int, fetch func(ctx context.Context, limit, page int) (Raw, error)) ([]json.RawMessage, error)
PagedAll follows limit/page pagination of endpoints that wrap their items in {"results": [...], "limit": N, "total": N}. "total" is trusted over the page length; without it, a page shorter than the effective limit (the response's "limit", or the requested one) ends the listing.
func SearchAll ¶
func SearchAll(ctx context.Context, max int, fetch func(ctx context.Context, limit int, searchAfter *string) (Raw, error)) ([]json.RawMessage, error)
SearchAll follows the search_after cursor of Mist search endpoints.
func SearchFiltered ¶
func SearchFiltered(ctx context.Context, max int, keep func(json.RawMessage) bool, fetch func(ctx context.Context, limit int, searchAfter *string) (Raw, error)) ([]json.RawMessage, error)
SearchFiltered is SearchAll with a local predicate: max applies to the items keep accepts, and pages are fetched until max matches are found or the results end. A repeated cursor or a malformed envelope is an error.
func ShellHTTPClient ¶
ShellHTTPClient is the HTTP client for the websocket handshake. Redirects are refused, so the token can never follow one to another host.
Types ¶
type Client ¶
type Client struct {
SDK mistapi.ClientInterface
Cloud cloud.Cloud
Debug bool
// Calls counts HTTP requests sent during this invocation.
Calls int
// contains filtered or unexported fields
}
Client is a read-only Mist API client.
func (*Client) CheckShellURL ¶
CheckShellURL enforces the websocket policy of remote shells: wss only, a host of the selected cloud (see ShellHosts), the default port (or 443) and no user info. The API token is only ever sent to such a URL.
func (*Client) ShellHeader ¶
ShellHeader returns the headers to send when opening the shell websocket. The API token is only added when the URL passes CheckShellURL.
func (*Client) ShellHosts ¶
ShellHosts returns the websocket hosts allowed for the client's cloud: the API host and its "api-ws" counterpart (api.gc1.mist.com -> api-ws.gc1.mist.com). Nothing else under the parent domain is trusted.
func (*Client) ShellSession ¶
func (c *Client) ShellSession(ctx context.Context, site, device uuid.UUID, node string) (string, error)
ShellSession asks Mist for a remote shell on a switch or gateway and returns the websocket URL to connect to. node selects one member of an SRX HA cluster ("node0" or "node1") and may be empty.
This is the only non-GET call mistctl makes; the transport guard allows exactly this endpoint and nothing else.
type ErrNotReadOnly ¶
type ErrNotReadOnly struct{ Method, URL string }
ErrNotReadOnly is returned when anything tries to send a non-GET request.
func (ErrNotReadOnly) Error ¶
func (e ErrNotReadOnly) Error() string
type Raw ¶
type Raw struct {
Status int
Header http.Header
Body json.RawMessage
}
Raw is an API response body plus metadata.
func Call ¶
func Call[T any](ctx context.Context, c *Client, fn func(context.Context) (models.ApiResponse[T], error)) (Raw, error)
Call runs one SDK call and returns the raw JSON body. Typed decoding errors from the SDK are ignored when the API itself answered 2xx, so a schema drift between the spec and the live API never hides data from the user.