plist

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Overview

common/configurationprofiles/plist/plistdiffsuppression.go contains the functions to process configuration profiles for diff suppression.

common/configurationprofiles/plist/payload.go Description: This file contains the ConfigurationProfile and PayloadContent structs, as well as functions for unmarshalling, marshalling, and validating plist payloads.

common/configurationprofiles/plist/shared.go contains the shared functions to process configuration profiles.

common/configurationprofiles/plist/validate.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertHCLToPlist

func ConvertHCLToPlist(d *schema.ResourceData) (string, error)

ConvertHCLToPlist builds a plist from the Terraform HCL schema data Used by plist generator resource to convert HCL data to plist

func ConvertPlistToHCL

func ConvertPlistToHCL(plistXML string) ([]interface{}, error)

ConvertPlistToHCL converts a plist XML string to Terraform HCL schema data Used by plist generator resource

func DecodePlist

func DecodePlist(plistData []byte) (map[string]interface{}, error)

Function to decode a plist into a map without removing any fields

func EncodePlist

func EncodePlist(cleanedData map[string]interface{}) (string, error)

EncodePlist encodes a cleaned map back to plist XML format

func ExtractPayloadIdentifiers added in v0.26.0

func ExtractPayloadIdentifiers(data interface{}, identifierMap map[string]string, isRoot bool)

ExtractPayloadIdentifiers recursively traverses a plist structure to extract PayloadIdentifier values and associate them with a composite key for proper structure preservation

func ExtractUUIDs added in v0.13.0

func ExtractUUIDs(data interface{}, uuidMap map[string]string, isRoot bool)

ExtractUUIDs recursively traverses a plist structure represented as nested maps and slices, extracting all occurrences of `PayloadUUID` and associating them with a composite key that combines PayloadDisplayName and PayloadType to handle duplicate display names. If a `PayloadDisplayName` is absent at the root level, it uses the special key "root". This function is typically used to map existing UUIDs from a configuration profile retrieved from Jamf Pro.

func GetTypedValue

func GetTypedValue(value interface{}) interface{}

GetTypedValue converts the value from the HCL always stored as string into the appropriate type for plist serialization.

func MarshalPayload

func MarshalPayload(profile *ConfigurationProfile) (string, error)

MarshalPayload marshals a ConfigurationProfile struct into a plist payload using mapstructure.

func MergeConfigurationPayloadFieldsIntoMap

func MergeConfigurationPayloadFieldsIntoMap(payload *PayloadContent) map[string]interface{}

MergeConfigurationPayloadFieldsIntoMap merges the fields of a ConfigurationPayload struct into a map.

func MergeConfigurationProfileFieldsIntoMap

func MergeConfigurationProfileFieldsIntoMap(profile *ConfigurationProfile) map[string]interface{}

MergeConfigurationProfileFieldsIntoMap merges the fields of a ConfigurationProfile struct into a map.

func NormalizeBase64 added in v0.5.0

func NormalizeBase64(input string) string

NormalizeBase64 normalizes base64 content by removing all whitespace characters Returns normalized base64 string with all spacing/formatting removed for comparison Base64 uses characters A-Z, a-z, 0-9, +, /, and = for padding

func NormalizePayloadState

func NormalizePayloadState(payload any) string

NormalizePayloadState processes and normalizes a macOS Configuration Profile payload. This function is crucial for maintaining consistency in plist structures, especially when working with Terraform state management for Jamf Pro configuration profiles.

The function performs the following steps:

  1. Unmarshals the input payload (expected to be a plist XML string) into a generic map structure.
  2. Normalizes the payload content using normalizePlistPayloadContent, which recursively processes nested PayloadContent fields without altering the overall structure.
  3. Marshals the normalized data back into a plist XML string.

The function is designed to work with the plist library for unmarshalling and marshalling, avoiding the use of struct-based approaches (like mapstructure) that might inadvertently add or remove fields.

Parameters:

  • payload: Any type, expected to be a string containing a plist XML representation of a Configuration Profile.

Returns:

  • A string containing the normalized plist XML. If any error occurs during processing, an empty string is returned.

func ProcessConfigurationProfileForDiffSuppression

func ProcessConfigurationProfileForDiffSuppression(plistData string, fieldsToRemove []string) (string, error)

ProcessConfigurationProfileForDiffSuppression processes the plist data through multiple steps to prepare it for diff suppression. This function is used to remove specified fields, normalize base64 content, normalize XML tags, unescape HTML entities, sort keys, and encode back to plist.

func SortPlistKeys

func SortPlistKeys(data map[string]interface{}) map[string]interface{}

SortPlistKeys recursively sorts the config profile xml keys of a nested map into alphabetical order,and sorts elements within arrays if they are strings or dictionaries. This function is used to prepare the xml plist keys for diff suppression and since there's no guranatee what keys will be present within the XML, nor their order presented, this function is used to ensure that the keys are in a consistent order for comparison.

func UpdateUUIDs added in v0.13.0

func UpdateUUIDs(data interface{}, uuidMap map[string]string, identifierMap map[string]string, isRoot bool)

UpdateUUIDs recursively traverses a plist structure represented as nested maps and slices, updating the values of `PayloadUUID` and `PayloadIdentifier` fields using the UUIDs provided in `uuidMap` and `identifierMap`. It matches UUIDs based on composite keys. If a `PayloadDisplayName` is absent at the root level, it uses the special key "root" from the map. This function ensures that configuration profile UUIDs remain consistent with Jamf Pro expectations during Terraform update operations.

func ValidatePayloadFields

func ValidatePayloadFields(profile *ConfigurationProfile) []error

ValidatePayloadFields validates the mapstructure field tags of a ConfigurationProfile struct and ensures that the required struct field tags are present and correctly populated. It checks for specific validation rules, such as ensuring that required fields are not empty. Additional custom validation rules can be added within this function to enforce other constraints based on the `validate` tags associated with the struct fields.

func ValidatePayloadUUIDsMatch added in v0.14.0

func ValidatePayloadUUIDsMatch(existingPlist, newPlist interface{}, path string, mismatches *[]string)

ValidatePayloadUUIDsMatch recursively compares UUID-related fields (`PayloadUUID` and `PayloadIdentifier`) between two plist structures (`existingPlist` and `newPlist`) to confirm they match exactly. It accumulates any differences found into the provided `mismatches` slice, describing the exact path and mismatched values. This validation step ensures Terraform updates maintain consistency with Jamf Pro's UUID requirements and detects unintended modifications.

Types

type ConfigurationProfile

type ConfigurationProfile struct {
	// Standard / Expected
	PayloadDescription       string           `mapstructure:"PayloadDescription"`
	PayloadDisplayName       string           `mapstructure:"PayloadDisplayName" validate:"required"`
	PayloadEnabled           bool             `mapstructure:"PayloadEnabled" validate:"required"`
	PayloadIdentifier        string           `mapstructure:"PayloadIdentifier" validate:"required"`
	PayloadOrganization      string           `mapstructure:"PayloadOrganization" validate:"required"`
	PayloadRemovalDisallowed bool             `mapstructure:"PayloadRemovalDisallowed" validate:"required"`
	PayloadScope             string           `mapstructure:"PayloadScope" validate:"required,oneof=System User Computer"`
	PayloadType              string           `mapstructure:"PayloadType" validate:"required,eq=Configuration"`
	PayloadUUID              string           `mapstructure:"PayloadUUID" validate:"required"`
	PayloadVersion           int              `mapstructure:"PayloadVersion" validate:"required"`
	PayloadContent           []PayloadContent `mapstructure:"PayloadContent"`
	// Catch all for unexpected fields
	Unexpected map[string]interface{} `mapstructure:",remain"`
}

ConfigurationProfile represents a root level MacOS configuration profile.

func UnmarshalPayload

func UnmarshalPayload(payload string) (*ConfigurationProfile, error)

UnmarshalPayload unmarshals a plist payload into a ConfigurationProfile struct using mapstructure.

type PayloadContent

type PayloadContent struct {
	// Standard / Expected
	PayloadDescription  string `mapstructure:"PayloadDescription"`
	PayloadDisplayName  string `mapstructure:"PayloadDisplayName"`
	PayloadEnabled      bool   `mapstructure:"PayloadEnabled"`
	PayloadIdentifier   string `mapstructure:"PayloadIdentifier"`
	PayloadOrganization string `mapstructure:"PayloadOrganization"`
	PayloadType         string `mapstructure:"PayloadType"`
	PayloadUUID         string `mapstructure:"PayloadUUID"`
	PayloadVersion      int    `mapstructure:"PayloadVersion"`
	// Variable
	ConfigurationItems map[string]interface{} `mapstructure:",remain"`
}

ConfigurationPayload represents a nested MacOS configuration profile.

Directories

Path Synopsis
test

Jump to

Keyboard shortcuts

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