commands

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 58 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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: "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: "smart-computer-groups", FilterName: "smart-groups", SubDir: "smart-groups/computers"},
	{Key: "static-computer-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-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: "classic-patch-titles", 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 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 DeduplicateSlug

func DeduplicateSlug(slug string, seen map[string]bool) string

DeduplicateSlug appends a numeric suffix if slug already exists in the set. Returns the unique slug and adds it to the set.

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

func FormatError(err error) bool

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 NewRootCmd

func NewRootCmd(version, commit, date string) *cobra.Command

func ResolveAuthForProfile

func ResolveAuthForProfile(cfg *config.Config, params AuthParams) (string, auth.Provider, error)

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

func SlugifyName(name string) string

SlugifyName converts a display name to a filesystem-safe slug. "Deploy Chrome - v1.2" → "deploy-chrome-v1-2"

func StripServerFields

func StripServerFields(obj map[string]any) map[string]any

StripServerFields removes server-generated fields from a JSON object for clean diffing. Removes id, timestamps, and other server-set fields.

Types

type AuthParams

type AuthParams struct {
	Profile      string
	ServerURL    string
	Token        string
	TokenFile    string
	TokenStdin   bool
	ClientID     string
	ClientSecret string
	TenantID     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
}

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

type FetchResult[R any] struct {
	Value R
	Err   error
}

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.

Directories

Path Synopsis
pro

Jump to

Keyboard shortcuts

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