common

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: MPL-2.0 Imports: 20 Imported by: 0

Documentation

Overview

hash.go This package contains shared / common hash functions

hash.go This package contains shared / common hash functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupDownloadedIcon added in v0.6.1

func CleanupDownloadedIcon(webSource, filePath string)

CleanupDownloadedIcon handles the cleanup of downloaded icon files from web sources. It ensures files are only deleted if they were downloaded from HTTP(s) sources and are in the temporary directory.

func CleanupDownloadedPackage added in v0.6.1

func CleanupDownloadedPackage(packageFileSource, localFilePath string)

CleanupDownloadedPackage handles the cleanup of downloaded package files from web sources. It ensures files are only deleted if they were downloaded from HTTP(s) sources and are in the temporary directory.

func Create added in v0.1.6

func Create[sdkPayloadType any, sdkResponseType any](
	ctx context.Context,
	d *schema.ResourceData,
	meta interface{},
	construct payoadConstructorFunc[sdkPayloadType],
	serverOutcomeFunc sdkCreateUpdateFunc[sdkPayloadType, sdkResponseType],
	reader providerReadFunc,
) diag.Diagnostics

Create is a shared helper that handles the creation of a new resource in Jamf Pro with retry logic and state management. It accepts generic types for the SDK payload and response to maintain type safety while being reusable.

Parameters: - ctx: The context for the operation, used for timeouts and cancellation - d: The ResourceData containing the desired state from Terraform - meta: The provider meta object containing the authenticated client - construct: A function that builds the SDK payload from ResourceData - serverOutcomeFunc: The SDK function that performs the actual creation API call - reader: A function that reads back the resource state after creation

Returns: - diag.Diagnostics containing any errors or warnings from the operation

func Delete added in v0.1.6

func Delete(ctx context.Context, d *schema.ResourceData, meta interface{}, serverOutcomeFunc sdkDeleteFunc) diag.Diagnostics

Delete is a shared helper that removes a resource from Jamf Pro with retry logic. It handles both the API deletion and clearing the resource ID from state.

Parameters: - ctx: The context for the operation, used for timeouts and cancellation - d: The ResourceData containing the resource to delete - meta: The provider meta object containing the authenticated client - serverOutcomeFunc: The SDK function that performs the actual delete API call

Returns: - diag.Diagnostics containing any errors or warnings from the operation

func DownloadFile added in v0.6.0

func DownloadFile(url string) (string, error)

DownloadFile downloads a file from a URL and saves it to a temporary directory with security validation. It follows redirects up to a maximum of 10 times. The filename is determined in the following order: 1. From Content-Disposition header if present and valid 2. From the final URL after redirects if valid 3. Falls back to a timestamp-based name if both sources are invalid

The function implements several security measures: - Validates filenames to prevent directory traversal - Restricts filenames to alphanumeric characters, dots, hyphens, underscores, and spaces - Replaces '%' characters with '_' - Ensures final path remains within temporary directory - Verifies path safety after normalization

Returns the path to the downloaded file and any error encountered. Possible errors include: - Failed to create temporary file - Too many redirects - Download failure - Write failure - Invalid filename - Path traversal attempt - Rename failure

func HandleResourceNotFoundError added in v0.1.6

func HandleResourceNotFoundError(err error, d *schema.ResourceData, cleanup bool) diag.Diagnostics

HandleResourceNotFoundError is a helper function to handle 404 and 410 errors and remove the resource from Terraform state

func HashString added in v0.1.6

func HashString(s string) string

HashString calculates the SHA-256 hash of a string and returns it as a hexadecimal string.

func Read added in v0.1.6

func Read[sdkResponseType any](
	ctx context.Context,
	d *schema.ResourceData,
	meta interface{},
	removeDeleteResourcesFromState bool,
	serverOutcomeFunc sdkGetFunc[sdkResponseType],
	providerStateFunc providerStateFunc[sdkResponseType],
) diag.Diagnostics

Read is a shared helper that retrieves the current state of a resource from Jamf Pro and updates the Terraform state. It includes retry logic and can optionally remove deleted resources from state.

Parameters: - ctx: The context for the operation, used for timeouts and cancellation - d: The ResourceData to be updated with the current state - meta: The provider meta object containing the authenticated client - removeDeleteResourcesFromState: Whether to remove the resource from state if not found - serverOutcomeFunc: The SDK function that performs the actual read API call - providerStateFunc: A function that updates ResourceData with the API response

Returns: - diag.Diagnostics containing any errors or warnings from the operation

func SerializeAndRedactJSON added in v0.1.6

func SerializeAndRedactJSON(resource interface{}, redactFields []string) (string, error)

SerializeAndRedactJSON serializes a resource to JSON and redacts specified fields.

func SerializeAndRedactXML added in v0.1.6

func SerializeAndRedactXML(resource interface{}, redactFields []string) (string, error)

SerializeAndRedactXML serializes a resource to XML and redacts specified fields.

func Update added in v0.1.6

func Update[sdkPayloadType any, sdkResponseType any](
	ctx context.Context,
	d *schema.ResourceData,
	meta interface{},
	constructor payoadConstructorFunc[sdkPayloadType],
	outcomeFunc sdkUpdateFunc[sdkPayloadType, sdkResponseType],
	reader providerReadFunc,

) diag.Diagnostics

Update is a shared helper that handles updating an existing resource in Jamf Pro with retry logic. It constructs the update payload, sends it to the API, and refreshes the state.

Parameters: - ctx: The context for the operation, used for timeouts and cancellation - d: The ResourceData containing the desired state from Terraform - meta: The provider meta object containing the authenticated client - constructor: A function that builds the SDK payload from ResourceData - outcomeFunc: The SDK function that performs the actual update API call - reader: A function that reads back the resource state after update

Returns: - diag.Diagnostics containing any errors or warnings from the operation

Types

This section is empty.

Directories

Path Synopsis
configurationprofiles
datavalidators
common/configurationprofiles/datavalidators/helpers.go
common/configurationprofiles/datavalidators/helpers.go
plist
common/configurationprofiles/plist/plistdiffsuppression.go contains the functions to process configuration profiles for diff suppression.
common/configurationprofiles/plist/plistdiffsuppression.go contains the functions to process configuration profiles for diff suppression.
common/constructobject.go
common/constructobject.go

Jump to

Keyboard shortcuts

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