client

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 17 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

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

View Source
const PageSize = 1000

PageSize is the page size used for list endpoints (Mist maximum).

Variables

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 ParseUUID

func ParseUUID(s string) (uuid.UUID, bool)

ParseUUID parses s as a UUID.

func Ptr

func Ptr[T comparable](v T) *T

Ptr returns a pointer to v, or nil for the zero value.

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

func ShellHTTPClient() *http.Client

ShellHTTPClient is the HTTP client for the websocket handshake. Redirects are refused, so the token can never follow one to another host.

func WithQuery

func WithQuery(ctx context.Context, key, value string) context.Context

WithQuery returns a context whose requests carry an extra query parameter, for parameters an SDK method does not expose (e.g. page). A parameter the SDK already set is left unchanged.

Types

type APIError

type APIError struct {
	Status  int
	Message string
}

APIError is a non-2xx answer from the Mist API.

func (*APIError) Error

func (e *APIError) Error() string

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 New

func New(c cloud.Cloud, token string, debug bool) (*Client, error)

New builds a client for the given cloud and token.

func (*Client) CheckShellURL

func (c *Client) CheckShellURL(wsURL string) error

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) Get added in v0.2.0

func (c *Client) Get(ctx context.Context, path string, query url.Values) (Raw, error)

Get sends one GET request to an API path the SDK has no working method for, and returns the raw JSON body. It goes through the same read-only guard, debug trace and call counter as the SDK calls. path starts with "/api/"; its segments must already be escaped.

func (*Client) ShellHeader

func (c *Client) ShellHeader(wsURL string) http.Header

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

func (c *Client) ShellHosts() []string

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.

Jump to

Keyboard shortcuts

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