commands

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 44 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BackupResources = []ResourceDef{

	{
		Name:       "policies",
		ListPath:   "/JSSResource/policies",
		GetPath:    "/JSSResource/policies/id/{id}",
		WrapperKey: "policies",
		IsClassic:  true,
		SubDir:     "policies",
	},

	{
		Name:       "profiles",
		ListPath:   "/JSSResource/osxconfigurationprofiles",
		GetPath:    "/JSSResource/osxconfigurationprofiles/id/{id}",
		WrapperKey: "os_x_configuration_profiles",
		IsClassic:  true,
		SubDir:     "profiles/macos",
	},

	{
		Name:       "profiles",
		ListPath:   "/JSSResource/mobiledeviceconfigurationprofiles",
		GetPath:    "/JSSResource/mobiledeviceconfigurationprofiles/id/{id}",
		WrapperKey: "configuration_profiles",
		IsClassic:  true,
		SubDir:     "profiles/ios",
	},

	{
		Name:     "scripts",
		ListPath: "/v1/scripts",
		GetPath:  "/v1/scripts/{id}",
		SubDir:   "scripts",
	},

	{
		Name:       "extension-attributes",
		ListPath:   "/JSSResource/computerextensionattributes",
		GetPath:    "/JSSResource/computerextensionattributes/id/{id}",
		WrapperKey: "computer_extension_attributes",
		IsClassic:  true,
		SubDir:     "extension-attributes/computer",
	},

	{
		Name:       "extension-attributes",
		ListPath:   "/JSSResource/mobiledeviceextensionattributes",
		GetPath:    "/JSSResource/mobiledeviceextensionattributes/id/{id}",
		WrapperKey: "mobile_device_extension_attributes",
		IsClassic:  true,
		SubDir:     "extension-attributes/mobile",
	},

	{
		Name:     "smart-groups",
		ListPath: "/v1/computer-groups",
		GetPath:  "/v1/computer-groups/{id}",
		SubDir:   "smart-groups/computers",
	},

	{
		Name:     "smart-groups",
		ListPath: "/v1/mobile-device-groups/smart-groups",
		GetPath:  "/v1/mobile-device-groups/{id}",
		SubDir:   "smart-groups/mobile",
	},

	{
		Name:     "categories",
		ListPath: "/v1/categories",
		GetPath:  "/v1/categories/{id}",
		SubDir:   "categories",
	},

	{
		Name:     "buildings",
		ListPath: "/v1/buildings",
		GetPath:  "/v1/buildings/{id}",
		SubDir:   "buildings",
	},

	{
		Name:     "departments",
		ListPath: "/v1/departments",
		GetPath:  "/v1/departments/{id}",
		SubDir:   "departments",
	},

	{
		Name:     "sites",
		ListPath: "/v1/sites",
		GetPath:  "/v1/sites/{id}",
		SubDir:   "sites",
	},

	{
		Name:       "packages",
		ListPath:   "/JSSResource/packages",
		GetPath:    "/JSSResource/packages/id/{id}",
		WrapperKey: "packages",
		IsClassic:  true,
		SubDir:     "packages",
	},

	{
		Name:       "printers",
		ListPath:   "/JSSResource/printers",
		GetPath:    "/JSSResource/printers/id/{id}",
		WrapperKey: "printers",
		IsClassic:  true,
		SubDir:     "printers",
	},

	{
		Name:       "dock-items",
		ListPath:   "/JSSResource/dockitems",
		GetPath:    "/JSSResource/dockitems/id/{id}",
		WrapperKey: "dock_items",
		IsClassic:  true,
		SubDir:     "dock-items",
	},

	{
		Name:       "network-segments",
		ListPath:   "/JSSResource/networksegments",
		GetPath:    "/JSSResource/networksegments/id/{id}",
		WrapperKey: "network_segments",
		IsClassic:  true,
		SubDir:     "network-segments",
	},

	{
		Name:       "restricted-software",
		ListPath:   "/JSSResource/restrictedsoftware",
		GetPath:    "/JSSResource/restrictedsoftware/id/{id}",
		WrapperKey: "restricted_software",
		IsClassic:  true,
		SubDir:     "restricted-software",
	},

	{
		Name:       "disk-encryption",
		ListPath:   "/JSSResource/diskencryptionconfigurations",
		GetPath:    "/JSSResource/diskencryptionconfigurations/id/{id}",
		WrapperKey: "disk_encryption_configurations",
		IsClassic:  true,
		SubDir:     "disk-encryption",
	},

	{
		Name:       "patch-titles",
		ListPath:   "/JSSResource/patchsoftwaretitles",
		GetPath:    "/JSSResource/patchsoftwaretitles/id/{id}",
		WrapperKey: "patch_software_titles",
		IsClassic:  true,
		SubDir:     "patch-titles",
	},

	{
		Name:     "static-groups",
		ListPath: "/v1/computer-groups",
		GetPath:  "/v1/computer-groups/{id}",
		SubDir:   "static-groups/computers",
	},
}

BackupResources lists all resource types that the backup command exports. Ordered by logical grouping: policies/profiles first, then supporting objects.

Functions

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 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 FetchResult

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

FetchResult holds either a result or an error from a parallel fetch.

type ResourceDef

type ResourceDef struct {
	Name       string // CLI display name: "policies"
	ListPath   string // API list endpoint: "/JSSResource/policies" or "/v1/scripts"
	GetPath    string // API detail endpoint with {id} placeholder
	WrapperKey string // Classic API JSON wrapper key (empty for modern)
	IsClassic  bool
	SubDir     string // backup output subdirectory
}

ResourceDef describes an API resource for backup/diff operations.

func FilterResources

func FilterResources(resources []ResourceDef, names []string) []ResourceDef

FilterResources returns only resources whose Name matches one of the given names.

Directories

Path Synopsis
pro

Jump to

Keyboard shortcuts

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