client

package
v1.29.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const BodyLogLimit = bodyLogLimit

BodyLogLimit is the truncation cap used by LogBody.

Variables

This section is empty.

Functions

func LogBody added in v1.15.0

func LogBody(w io.Writer, data []byte)

LogBody is the exported alias of logBody.

func LogHeaders added in v1.15.0

func LogHeaders(w io.Writer, h http.Header, redactAuth bool)

LogHeaders is the exported alias of logHeaders, callable from other packages that wrap HTTP transports (e.g. the Platform Gateway client wired through the SDK).

func NewMultipartFileUpload added in v1.13.0

func NewMultipartFileUpload(fieldName string, f *os.File) (body io.ReadSeeker, contentType string, contentLength int64, err error)

NewMultipartFileUpload builds a streaming multipart/form-data body wrapping a single file part and returns the body, Content-Type, and exact Content-Length.

The returned io.ReadSeeker streams directly from the underlying *os.File — no in-memory copy of the file. Seek(0, SeekStart) rewinds the body so Client.Upload can retry on HTTP 429.

The caller owns the file and must close it after Upload returns. filename in the multipart header is derived from filepath.Base(f.Name()).

func ReadResponseBody

func ReadResponseBody(resp *http.Response) ([]byte, error)

ReadResponseBody reads the full body from an HTTP response with a 10 MB limit.

func RedactBodyForLog added in v1.28.0

func RedactBodyForLog(data []byte) []byte

RedactBodyForLog is the exported alias of redactBodyForLog, for transports wrapped outside this package (the Platform Gateway client wired through the SDK).

func RedactCredentialBody added in v1.28.0

func RedactCredentialBody(data []byte) []byte

RedactCredentialBody replaces credential values in a request or response body with "[REDACTED]", across the three encodings this CLI logs: JSON, form- encoded and Classic XML.

Request bodies were logged verbatim at -vvv while responses were redacted, which is the wrong way round for the one body that is guaranteed to carry a secret — the token exchange's. Bodies also carry credentials on the way in by design: the credential policy routes an SMTP or LDAP account password through --from-file precisely so it stays out of argv, and logging it here would put it back in the CI job output.

Applied to responses too, composed with RedactTokenBody: a Classic read of a distribution point or an SMTP server returns its password field.

func RedactTokenBody added in v1.15.0

func RedactTokenBody(data []byte) []byte

RedactTokenBody replaces OAuth2 token values in raw JSON with "[REDACTED]" so response bodies are safe to log at -vvv. Non-JSON data is returned as-is.

func StatusError added in v1.27.0

func StatusError(status int, method, path string, body []byte) error

StatusError maps an HTTP error response to the same structured exit error Do would have returned. For callers that opted a status out of that mapping with registry.WithAllowedStatuses and then decided the response was a genuine failure after all — so the error text and hint stay in one place.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the HTTP client for Jamf Pro API

func New

func New(baseURL string, authProvider auth.Provider, opts ...Option) *Client

New creates a new Jamf Pro API client

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, body io.Reader) (*http.Response, error)

Do executes an HTTP request with authentication and retry logic

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, path string, body io.Reader, contentType string, contentLength int64) (*http.Response, error)

Upload executes a streaming HTTP request with a caller-specified Content-Type and Content-Length. The body is never buffered, so multi-GB files stream straight through.

429 retry: when body implements io.Seeker (e.g. *os.File, *bytes.Reader, or the seekable multipart body from NewMultipartFileUpload), Upload retries up to 3 times on HTTP 429, honoring Retry-After. Non-seekable bodies surface 429 to the caller immediately — retrying would corrupt the upload.

type Option

type Option func(*Client)

Option configures the client

func WithCookieJar

func WithCookieJar(jar http.CookieJar) Option

WithCookieJar sets the cookie jar on the HTTP client. Sharing a jar with the auth provider enables sticky session affinity cookies (e.g. APBALANCEID on Jamf Cloud) to persist from the token exchange through all API calls.

func WithGatewayScope added in v1.28.0

func WithGatewayScope(scope auth.Scope) Option

WithGatewayScope enables platform gateway mode: paths are rewritten into their gateway namespace (/api/v1/x -> /pro/v1/x, /JSSResource/x -> /proclassic/x) and the scope travels as a request header — X-Environment-Id or X-Tenant-Id, or nothing for an organization-scoped credential, which the gateway resolves from the access token.

func WithVerbose

func WithVerbose(level int) Option

WithVerbose sets the verbosity level (1 = request/response lines, 2 = +headers).

Jump to

Keyboard shortcuts

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