Documentation
¶
Index ¶
- Variables
- func CacheKey(baseURL, clientID string) string
- func ListAll[T any](ctx context.Context, c *Client, endpoint string, query string, ...) ([]T, error)
- type Client
- func (c *Client) AccessToken(ctx context.Context) (*Token, error)
- func (c *Client) BaseURL() string
- func (c *Client) DoGraphQL(ctx context.Context, path, query string, variables map[string]any, target any) error
- func (c *Client) NewCursorGuard() *CursorGuard
- func (c *Client) SetLogger(logger Logger)
- type CursorGuard
- type FileTokenCache
- type Logger
- type Option
- type PaginatedResult
- type Token
- type TokenCache
Constants ¶
This section is empty.
Variables ¶
var ( ErrAuthentication = errors.New("jamfprotect: authentication failed") ErrGraphQL = errors.New("jamfprotect: graphql error") ErrNotFound = errors.New("jamfprotect: resource not found") // ErrUnexpectedResponse indicates the server returned a non-JSON body where a // JSON response was expected — typically an HTML error page from an edge proxy // or WAF — and is distinct from a genuine JSON syntax error from the API. ErrUnexpectedResponse = errors.New("jamfprotect: unexpected non-JSON response") // ErrResponseTooLarge indicates a response body exceeded the client's size // limit and was not read in full. ErrResponseTooLarge = errors.New("jamfprotect: response body too large") // ErrPaginationLimit indicates a paginated list was abandoned because the // server repeated a cursor or the page limit was reached. ErrPaginationLimit = errors.New("jamfprotect: pagination limit exceeded") )
Sentinel errors returned by the client.
Functions ¶
func CacheKey ¶ added in v0.2.0
CacheKey computes a deterministic cache key from a base URL and client ID.
func ListAll ¶
func ListAll[T any]( ctx context.Context, c *Client, endpoint string, query string, baseVars map[string]any, resultKey string, ) ([]T, error)
ListAll executes a paginated GraphQL list query, accumulating all pages. The resultKey must match the JSON field name of the list operation in the GraphQL response (e.g. "listGroups", "listRoles").
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client communicates with the Jamf Protect GraphQL API.
func NewClientWithUserAgent ¶
func NewClientWithUserAgent(baseURL, clientID, clientSecret, userAgent string, opts ...Option) *Client
NewClientWithUserAgent creates a new Jamf Protect GraphQL client with a custom user agent string.
func (*Client) AccessToken ¶
AccessToken ensures a valid token is available and returns it. Tokens returned by Jamf Protect do not include a "Bearer" prefix.
func (*Client) DoGraphQL ¶
func (c *Client) DoGraphQL(ctx context.Context, path, query string, variables map[string]any, target any) error
DoGraphQL executes a raw GraphQL query/mutation against a custom endpoint path. Use "/app" for the main API and "/graphql" for the limited schema endpoint.
func (*Client) NewCursorGuard ¶ added in v0.9.0
func (c *Client) NewCursorGuard() *CursorGuard
NewCursorGuard returns a CursorGuard for one paginated call, using the client's page limit.
type CursorGuard ¶ added in v0.9.0
type CursorGuard struct {
// contains filtered or unexported fields
}
CursorGuard stops pagination that would never terminate. It rejects any cursor already returned earlier in the same run and caps the page count.
func (*CursorGuard) Next ¶ added in v0.9.0
func (g *CursorGuard) Next(cursor string) error
Next records that a page was received with the given next cursor and reports ErrPaginationLimit if following it would revisit a cursor or exceed the page limit.
type FileTokenCache ¶ added in v0.2.0
type FileTokenCache struct {
// contains filtered or unexported fields
}
FileTokenCache persists tokens to disk as JSON files. The directory must be private to the running user: entries are only read from, and written to, a directory owned by the current user that group and others cannot write.
func NewFileTokenCache ¶ added in v0.2.0
func NewFileTokenCache(dir string) *FileTokenCache
NewFileTokenCache creates a FileTokenCache that stores tokens in the given directory.
func (*FileTokenCache) Load ¶ added in v0.2.0
Load reads a cached token from disk. Entries that are not regular files owned by the current user, are accessible by group or others, live in a directory that is not private, or carry an implausible expiry are treated as a miss.
type Logger ¶
type Logger interface {
LogRequest(ctx context.Context, method, url string, headers http.Header, body []byte)
LogResponse(ctx context.Context, statusCode int, headers http.Header, body []byte)
}
Logger is an interface for logging HTTP requests and responses.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithHTTPClient ¶
WithHTTPClient overrides the HTTP client used by the API client.
func WithMaxPages ¶ added in v0.9.0
WithMaxPages sets how many pages a single paginated call may follow before failing with ErrPaginationLimit. The default is 10,000; a non-positive value keeps the default.
func WithMinRequestInterval ¶ added in v0.6.0
WithMinRequestInterval sets the minimum gap enforced between outbound GraphQL requests. The default is 100ms; a non-positive value disables throttling.
func WithTokenCache ¶ added in v0.2.0
func WithTokenCache(cache TokenCache, cacheKey string) Option
WithTokenCache sets a persistent token cache and its lookup key.
type PaginatedResult ¶
type PaginatedResult[T any] struct { Items []T `json:"items"` PageInfo struct { Next *string `json:"next"` Total int `json:"total"` } `json:"pageInfo"` }
PaginatedResult is the common shape returned by all paginated list queries.