Documentation
¶
Index ¶
- Variables
- func BackupFilterNames() []string
- func BackupSubDirs() map[string]string
- func BoundedParallelFetch[T any, R any](ctx context.Context, items []T, concurrency int, ...) ([]R, []error)
- func ClassifyError(err error) error
- func DeduplicateSlug(slug string, seen map[string]bool) string
- func EnrichPrivilegeError(cmd *cobra.Command, err error) error
- func FetchAllPaginated(ctx context.Context, client registry.HTTPClient, basePath string, pageSize int) ([]map[string]any, error)
- func FetchClassicList(ctx context.Context, client registry.HTTPClient, path, wrapperKey string) ([]any, error)
- func FetchClassicListSubset(ctx context.Context, client registry.HTTPClient, path, subset string) ([]map[string]any, error)
- func FetchJSON(ctx context.Context, client registry.HTTPClient, path string) (map[string]any, error)
- func FormatError(err error) bool
- func FprintError(w io.Writer, err error)
- func NewRootCmd(version, commit, date, specProVersion string) *cobra.Command
- func ResolveAuthForProfile(cfg *config.Config, params AuthParams) (string, auth.Provider, error)
- func SlugifyName(name string) string
- func StripServerFields(obj map[string]any) map[string]any
- type AuthParams
- type BackupResource
- type FetchResult
- type ResolvedBackupResource
Constants ¶
This section is empty.
Variables ¶
var BackupResources = []BackupResource{ {Key: "classic-policies", FilterName: "policies", SubDir: "policies"}, {Key: "classic-macos-config-profiles", FilterName: "profiles", SubDir: "profiles/macos"}, {Key: "classic-mobile-config-profiles", FilterName: "profiles", SubDir: "profiles/ios"}, {Key: "computer-prestages", FilterName: "prestages", SubDir: "prestages/computers", ScopePath: "/v2/computer-prestages/{id}/scope"}, {Key: "mobile-device-prestages", FilterName: "prestages", SubDir: "prestages/mobile", ScopePath: "/v2/mobile-device-prestages/{id}/scope"}, {Key: "scripts", FilterName: "scripts", SubDir: "scripts"}, {Key: "computer-extension-attributes", FilterName: "extension-attributes", SubDir: "extension-attributes/computer"}, {Key: "mobile-device-extension-attributes", FilterName: "extension-attributes", SubDir: "extension-attributes/mobile"}, {Key: "classic-user-ext-attrs", FilterName: "extension-attributes", SubDir: "extension-attributes/user"}, {Key: "computer-groups-smart-groups", FilterName: "smart-groups", SubDir: "smart-groups/computers"}, {Key: "computer-groups-static-groups", FilterName: "static-groups", SubDir: "static-groups/computers"}, {Key: "mobile-device-groups-smart-groups", FilterName: "smart-groups", SubDir: "smart-groups/mobile"}, {Key: "mobile-device-groups-static-groups", FilterName: "static-groups", SubDir: "static-groups/mobile"}, {Key: "categories", FilterName: "categories", SubDir: "categories"}, {Key: "buildings", FilterName: "buildings", SubDir: "buildings"}, {Key: "departments", FilterName: "departments", SubDir: "departments"}, {Key: "sites", FilterName: "sites", SubDir: "sites", ListOnly: true}, {Key: "classic-mac-apps", FilterName: "mac-apps", SubDir: "mac-apps"}, {Key: "classic-mobile-apps", FilterName: "mobile-apps", SubDir: "mobile-apps"}, {Key: "classic-packages", FilterName: "packages", SubDir: "packages"}, {Key: "classic-printers", FilterName: "printers", SubDir: "printers"}, {Key: "classic-dock-items", FilterName: "dock-items", SubDir: "dock-items"}, {Key: "classic-network-segments", FilterName: "network-segments", SubDir: "network-segments"}, {Key: "classic-restricted-software", FilterName: "restricted-software", SubDir: "restricted-software"}, {Key: "classic-disk-encryption-configs", FilterName: "disk-encryption", SubDir: "disk-encryption"}, {Key: "patch-software-title-configurations", FilterName: "patch-titles", SubDir: "patch-titles"}, {Key: "classic-account-users", FilterName: "accounts", SubDir: "accounts/users"}, {Key: "classic-account-groups", FilterName: "accounts", SubDir: "accounts/groups"}, }
BackupResources is the curated set of resources included in `backup` and `diff`. Endpoint paths live in generated/backup_registry.go; this file only decides which resources are in scope and how they lay out on disk.
Grouping follows a logical config-object order: policies/profiles first, then scripts/EAs/groups, then supporting objects, then administration.
Functions ¶
func BackupFilterNames ¶ added in v1.11.0
func BackupFilterNames() []string
BackupFilterNames returns the unique set of FilterName values (sorted) — used for CLI help text and completion hints.
func BackupSubDirs ¶ added in v1.28.0
BackupSubDirs maps each curated resource's on-disk subdirectory (relative to the backup root, slash-separated) to the FilterName that owns it. `diff` reads this table rather than walking the backup tree, so files off disk are bucketed under exactly the key live mode uses and a directory and an instance are comparable; it also uses the key set to tell which directories in the backup root a curated resource already owns from those it must key by name.
It matters because thirteen of the curated resources nest two levels deep (profiles/macos, smart-groups/computers, accounts/users, …). `diff` used to treat every top-level directory as a resource and read only the files sitting directly inside it, so those thirteen contributed nothing to either snapshot and their changes were reported as no change at all — silently, exit 0.
func BoundedParallelFetch ¶
func BoundedParallelFetch[T any, R any](ctx context.Context, items []T, concurrency int, fn func(context.Context, T) (R, error)) ([]R, []error)
BoundedParallelFetch runs fn for each item with bounded concurrency. Returns all results (in input order) and any errors collected.
func ClassifyError ¶ added in v1.19.0
ClassifyError normalizes framework errors that carry no explicit exit code so they map to the documented codes. Cobra reports an unknown command as a plain error (default exit 1); classify it as a usage error (2) to match the unknown-flag path handled by SetFlagErrorFunc. Errors that already carry an exit code (including wrapped unknown-flag errors) pass through unchanged.
func DeduplicateSlug ¶
DeduplicateSlug appends a numeric suffix if slug already exists in the set. Returns the unique slug and adds it to the set.
func EnrichPrivilegeError ¶ added in v1.22.0
EnrichPrivilegeError names the permission a 403 wanted, in the vocabulary of whichever API served the command.
The two vocabularies are independent sets and neither is derivable from the other. A Jamf Pro instance enforces API-role privileges ("Read Categories"), granted in Jamf Pro. The Jamf Platform gateway enforces GA capability permissions (categories:read), granted in Jamf Account when the API integration is created; the GA consolidation folded several Jamf Pro privileges into one capability, and Jamf Account no longer offers the old names at all. So printing the wrong one sends the operator to a console where the grant it names does not exist.
Three cases, in the order they are checked:
- A Platform command (jamf:api platform-gateway, which covers the gateway-served Security Cloud commands too). Its jamf:privileges annotation is already the capability vocabulary, and its error comes from the platform SDK rather than internal/client, so nothing has mapped it to an exit code yet.
- A Pro or Classic command whose 403 hint already carries a platform answer: internal/client wrote it, for the request it actually sent, on a gateway credential. Left alone — appending the Jamf Pro names here is the bug this whole function exists to avoid.
- Everything else: a Pro or Classic 403 against a Jamf Pro instance, where the annotation's Jamf Pro privilege names are the right answer.
func FetchAllPaginated ¶
func FetchAllPaginated(ctx context.Context, client registry.HTTPClient, basePath string, pageSize int) ([]map[string]any, error)
FetchAllPaginated fetches all items from a modern API endpoint. It auto-detects the response format:
- Paginated: `{"totalCount": N, "results": [...]}` — fetches all pages
- Array: `[{...}, {...}]` — returns the full array directly
Some Jamf Pro endpoints (e.g. /v1/sites, /v1/computer-groups, /v2/patch-software-title-configurations) return plain arrays even when pagination params are provided. This function handles both transparently.
func FetchClassicList ¶
func FetchClassicList(ctx context.Context, client registry.HTTPClient, path, wrapperKey string) ([]any, error)
FetchClassicList performs a GET on a Classic API list endpoint and returns the unwrapped array. Classic API returns XML; JSON is handled as a fallback.
func FetchClassicListSubset ¶ added in v1.11.0
func FetchClassicListSubset(ctx context.Context, client registry.HTTPClient, path, subset string) ([]map[string]any, error)
FetchClassicListSubset performs a GET on a Classic API endpoint that hosts multiple sibling collections under a single root (currently only /JSSResource/accounts, which nests <users> and <groups> inside <accounts>) and returns the items belonging to the named subset. The runtime mirror of the list_subset manifest opt-in handled by the classic generator in PR 152.
func FetchJSON ¶
func FetchJSON(ctx context.Context, client registry.HTTPClient, path string) (map[string]any, error)
FetchJSON performs a GET request and returns the parsed JSON object. Exported version of the overview.go fetchJSON helper.
func FormatError ¶
FormatError writes a structured JSON error to stdout when the output format is "json". Returns true if the error was handled, false otherwise (caller should fall back to plain stderr).
func FprintError ¶ added in v1.19.0
FprintError writes a human-facing error (and a "hint:" line when present) to w. Used by main when the JSON envelope path does not apply.
func NewRootCmd ¶
func ResolveAuthForProfile ¶
ResolveAuthForProfile determines the server URL and auth provider for a specific profile name using the given config. Unlike resolveAuth, it does not read or mutate package-level variables, making it safe to call multiple times for different profiles (e.g., in the diff command).
func SlugifyName ¶
SlugifyName converts a display name to a filesystem-safe slug. "Deploy Chrome - v1.2" → "deploy-chrome-v1-2"
Types ¶
type AuthParams ¶
type AuthParams struct {
Profile string
ServerURL string
Token string
TokenFile string
TokenStdin bool
ClientID string
ClientSecret string
// TenantID and EnvironmentID are the two scope identifiers a platform
// integration can name, and they are mutually exclusive — see the scope
// handling in ResolveAuthForProfile. Neither set means organization scope.
TenantID string
EnvironmentID string
}
AuthParams holds all auth-related inputs for profile resolution. Enables callers (like diff) to resolve multiple profiles independently.
type BackupResource ¶ added in v1.11.0
type BackupResource struct {
Key string // lookup in generated.BackupEndpoints
FilterName string // --resources filter token
SubDir string // output subdirectory under --output
// ListOnly bypasses the per-ID detail fetch — each list item is written
// directly to disk as its own file. Used for resources whose list response
// is already the complete record (e.g. sites: {id, name}).
ListOnly bool
// ScopePath, when set, names a per-ID device-scope endpoint
// (e.g. "/v2/computer-prestages/{id}/scope"). After fetching each detail
// record the backup/diff code fetches this path and embeds the sorted
// serial numbers under a "scope" key so the assignment list travels with
// the prestage config in a single, diff-friendly file.
ScopePath string
}
BackupResource is a curated entry in the backup/diff resource set. Each entry names a generated CLI command (Key) whose list+get endpoints are resolved at runtime from generated.BackupEndpoints. FilterName is the user-facing token accepted by --resources (e.g. "profiles" covers both macOS and iOS profiles); SubDir is the output directory under the backup root.
Rule of thumb: prefer a modern-API resource over its classic counterpart when both exist (modern responses are richer and paginated). Only fall back to classic when there is no modern equivalent.
type FetchResult ¶
FetchResult holds either a result or an error from a parallel fetch.
type ResolvedBackupResource ¶ added in v1.11.0
type ResolvedBackupResource struct {
BackupResource
generated.BackupEndpoint
}
ResolvedBackupResource couples a curated entry with its generated endpoint metadata. Runtime code iterates the resolved form so it doesn't need to cross-reference two slices at every step.
func ResolveBackupResources ¶ added in v1.11.0
func ResolveBackupResources(filter []string) ([]ResolvedBackupResource, error)
ResolveBackupResources joins the curated BackupResources against the generated endpoint registry, optionally filtering by user-supplied resource names (matched against FilterName). An unknown filter name produces an empty result; a filter name that matches zero curated entries is reported by the caller.
An entry whose Key is missing from generated.BackupEndpoints is a programming error — a regenerated registry and a stale curation list have diverged — and surfaces via an error so tests catch the drift at build time.
Source Files
¶
- agent_context.go
- aliases.go
- completion.go
- config.go
- doctor.go
- gateway_coverage.go
- groups.go
- mcp.go
- multi.go
- platform.go
- platform_account.go
- platform_audit.go
- platform_auth.go
- platform_gateway_setup.go
- privilege_error.go
- pro.go
- pro_audit.go
- pro_auth.go
- pro_backup.go
- pro_blueprints.go
- pro_bulk.go
- pro_bulk_commands.go
- pro_bulk_groups.go
- pro_bulk_policies.go
- pro_classic_app_usage.go
- pro_command_flush.go
- pro_compliance_benchmarks.go
- pro_ddm_reports.go
- pro_device.go
- pro_device_actions.go
- pro_device_resolve.go
- pro_diff.go
- pro_group_tools.go
- pro_helpers.go
- pro_jamf_protect_deployment_tasks.go
- pro_jcds.go
- pro_overview.go
- pro_packages_upload.go
- pro_platform_device_groups.go
- pro_platform_devices.go
- pro_platform_helpers.go
- pro_report.go
- pro_report_compliance.go
- pro_report_ea.go
- pro_report_inventory.go
- pro_report_mdm.go
- pro_report_patch.go
- pro_report_platform.go
- pro_report_policy.go
- pro_report_security.go
- pro_report_serials.go
- pro_report_software.go
- pro_report_updates.go
- pro_resources.go
- pro_setup.go
- protect.go
- protect_action_configs.go
- protect_alerts.go
- protect_analytic_overrides.go
- protect_analytic_sets.go
- protect_analytics.go
- protect_api_clients.go
- protect_audit_logs.go
- protect_auth.go
- protect_backup.go
- protect_computers.go
- protect_exception_sets.go
- protect_groups.go
- protect_helpers.go
- protect_insights.go
- protect_org.go
- protect_overview.go
- protect_permissions.go
- protect_plans.go
- protect_prevent_lists.go
- protect_rbac_refs.go
- protect_roles.go
- protect_rscs.go
- protect_setup.go
- protect_telemetry.go
- protect_ulf.go
- protect_ulf_sets.go
- protect_users.go
- root.go
- school.go
- school_apps.go
- school_classes.go
- school_dep_devices.go
- school_device_groups.go
- school_devices.go
- school_groups.go
- school_ibeacons.go
- school_locations.go
- school_overview.go
- school_profiles.go
- school_setup.go
- school_users.go
- security.go
- security_setup.go
- update_check.go
- version.go