ab

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package ab is the Apple Business API client: ES256 client-assertion auth + typed read methods. Auth OMITS the JWT `kid` (verified live: a kid -> invalid_client).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Status int
	Body   string
}

APIError carries a non-2xx response.

func (*APIError) Error

func (e *APIError) Error() string

type Client

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

Client is a thin Apple Business API client (read methods for Phase 0).

func NewClient

func NewClient(cfg *config.Config) *Client

NewClient builds an Apple Business API client from the resolved config.

func (*Client) APIWrite

func (c *Client) APIWrite(method, path string, payload any) (int, []byte, error)

APIWrite issues an authenticated non-GET request with a JSON body (used by the gated `api` passthrough). A nil payload sends no body. It retries 401 (re-mint) and 429, never 5xx (a write may have partially applied).

func (*Client) AddBlueprintMembers

func (c *Client) AddBlueprintMembers(bpID, rel, memberType string, ids []string) error

AddBlueprintMembers / RemoveBlueprintMembers converge a blueprint relation via explicit per-member ops (correct whether Apple merges or replaces). Gated in the engine — not used by autonomous config-only apply.

func (*Client) AuditEvents

func (c *Client) AuditEvents(start, end string) ([]Resource, error)

AuditEvents returns audit events between the start and end timestamps (ISO 8601).

func (*Client) BlueprintRelationship

func (c *Client) BlueprintRelationship(id, rel string) ([]Resource, error)

BlueprintRelationship returns linkage IDs for a blueprint member relation.

func (*Client) CreateConfiguration

func (c *Client) CreateConfiguration(name, xml string, platforms []string) (id, updated string, err error)

CreateConfiguration POSTs a CUSTOM_SETTING config with the raw .mobileconfig XML. It returns the new config's ID and its server-assigned updatedDateTime (parsed from the 201 body) so the caller can record an exact baseline with no extra GET.

func (*Client) DeleteConfiguration

func (c *Client) DeleteConfiguration(id string) error

DeleteConfiguration deletes a configuration by id.

func (*Client) FetchBlueprints

func (c *Client) FetchBlueprints(configNameByID map[string]string) ([]LiveBlueprint, error)

FetchBlueprints lists all blueprints and resolves each one's attached configuration IDs to names via configNameByID. One list call plus one relationship call per blueprint (blueprints are few — cheaper than a GET/config).

func (*Client) FetchCustomSettings

func (c *Client) FetchCustomSettings() ([]LiveConfig, error)

FetchCustomSettings returns all CUSTOM_SETTING configs with their raw XML. Uses one list call with fields[] (incl. customSettingsValues) to avoid a GET per config; falls back to a per-config GET only if the list came back sparse.

func (*Client) FetchCustomSettingsWithProgress added in v0.4.4

func (c *Client) FetchCustomSettingsWithProgress(progress func(string)) ([]LiveConfig, error)

func (*Client) GetBlueprint

func (c *Client) GetBlueprint(id string) (*Resource, error)

GetBlueprint fetches a single blueprint by ID.

func (*Client) GetConfiguration

func (c *Client) GetConfiguration(id string) (*Resource, error)

GetConfiguration fetches a single configuration by ID.

func (*Client) ListApps

func (c *Client) ListApps() ([]Resource, error)

ListApps returns the organization's apps (Apps & Books; read-only).

func (*Client) ListBlueprints

func (c *Client) ListBlueprints() ([]Resource, error)

ListBlueprints returns all blueprints.

func (*Client) ListConfigurations

func (c *Client) ListConfigurations() ([]Resource, error)

ListConfigurations returns all configurations (every type; only CUSTOM_SETTING is writable).

func (*Client) ListDevices

func (c *Client) ListDevices() ([]Resource, error)

ListDevices returns the organization's devices (orgDevices).

func (*Client) ListMDMServers

func (c *Client) ListMDMServers() ([]Resource, error)

ListMDMServers returns the organization's MDM servers (read-only).

func (*Client) ListPackages

func (c *Client) ListPackages() ([]Resource, error)

ListPackages returns the organization's packages (custom apps/pkgs; read-only). The endpoint is gated by the built-in-device-management permission, so it may 403 for an account without it.

func (*Client) ListUserGroups

func (c *Client) ListUserGroups() ([]Resource, error)

ListUserGroups returns the organization's user groups (read-only).

func (*Client) ListUsers

func (c *Client) ListUsers() ([]Resource, error)

ListUsers returns the organization's users (read-only; identity is not API-writable).

func (*Client) Raw

func (c *Client) Raw(method, path string, body io.Reader) (int, []byte, error)

Raw issues an authenticated request. For replayable (nil-body) requests it re-mints once on 401 and backs off on 429/5xx (respecting Retry-After).

func (*Client) RemoveBlueprintMembers

func (c *Client) RemoveBlueprintMembers(bpID, rel, memberType string, ids []string) error

RemoveBlueprintMembers detaches members (per-member DELETE) from a blueprint relation.

func (*Client) ResolveApp added in v0.2.0

func (c *Client) ResolveApp(nameOrID string) (*Resource, error)

ResolveApp finds an owned app by id, bundleId, or name. id/bundleId are unique so they win immediately; name may collide, so a name that matches >1 app is an error (caller should use the id/bundleId). App ids are numeric adamIds, not UUIDs, so looksLikeID never matches — always list and match here.

func (*Client) ResolveBlueprint

func (c *Client) ResolveBlueprint(nameOrID string) (*Resource, error)

ResolveBlueprint finds a blueprint by id (UUID) or by its `name` attribute.

func (*Client) ResolveConfig

func (c *Client) ResolveConfig(nameOrID string) (*Resource, error)

ResolveConfig finds a configuration by id (UUID) or by its `name` attribute.

func (*Client) TokenSource

func (c *Client) TokenSource() *TokenSource

TokenSource exposes the underlying bearer-token source (for whoami/health checks).

func (*Client) UpdateConfiguration

func (c *Client) UpdateConfiguration(id, name, xml string) (updated string, err error)

UpdateConfiguration PATCHes a CUSTOM_SETTING config's name + profile XML and returns the server-assigned updatedDateTime (parsed from the 200 body).

type LiveBlueprint

type LiveBlueprint struct {
	Name    string
	ID      string
	Configs []string // attached config names, sorted; an unresolved id passes through as-is
}

LiveBlueprint is a blueprint with the NAMES of its attached configurations.

type LiveConfig

type LiveConfig struct {
	Name    string
	ID      string
	XML     string
	Updated string
}

LiveConfig is a CUSTOM_SETTING configuration with its raw profile XML.

type Resource

type Resource struct {
	Type       string          `json:"type"`
	ID         string          `json:"id"`
	Attributes json.RawMessage `json:"attributes"`
}

Resource is a JSON:API resource object.

func (Resource) Attr

func (r Resource) Attr() map[string]any

Attr decodes attributes into a generic map (for table output / string fields).

func (Resource) AttrStr

func (r Resource) AttrStr(key string) string

AttrStr returns a string attribute (empty if absent/non-string).

type TokenSource

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

TokenSource mints and caches a bearer token from an ES256 client assertion.

func NewTokenSource

func NewTokenSource(cfg *config.Config, hc *http.Client) *TokenSource

NewTokenSource caches the bearer in a stable, per-credential file (see tokenCachePath).

func (*TokenSource) Expiry

func (ts *TokenSource) Expiry() time.Time

Expiry returns the cached token expiry (after a successful Token()).

func (*TokenSource) Invalidate

func (ts *TokenSource) Invalidate()

Invalidate forces a re-mint on the next Token() (e.g., after a 401).

func (*TokenSource) Token

func (ts *TokenSource) Token() (string, error)

Token returns a valid bearer, minting/refreshing if <60s remain.

Jump to

Keyboard shortcuts

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