Skip to content

Commit

Permalink
Merge pull request #499 from deploymenttheory/feat-recipes
Browse files Browse the repository at this point in the history
Various bug fixes for computer software update structs and example tweaks
  • Loading branch information
ShocOne authored Sep 17, 2024
2 parents 20eea9f + cf747f5 commit fb5246f
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,28 @@ func main() {
EnableDeviceBasedActivationLock: jamfpro.FalsePtr(),
DeviceEnrollmentProgramInstanceId: "1",
SkipSetupItems: jamfpro.ComputerPrestageSubsetSkipSetupItems{
Biometric: jamfpro.FalsePtr(),
TermsOfAddress: jamfpro.FalsePtr(),
FileVault: jamfpro.FalsePtr(),
ICloudDiagnostics: jamfpro.FalsePtr(),
Diagnostics: jamfpro.FalsePtr(),
Accessibility: jamfpro.FalsePtr(),
AppleID: jamfpro.FalsePtr(),
ScreenTime: jamfpro.FalsePtr(),
Siri: jamfpro.FalsePtr(),
DisplayTone: jamfpro.FalsePtr(),
Restore: jamfpro.FalsePtr(),
Appearance: jamfpro.FalsePtr(),
Privacy: jamfpro.FalsePtr(),
Payment: jamfpro.FalsePtr(),
Registration: jamfpro.FalsePtr(),
TOS: jamfpro.FalsePtr(),
ICloudStorage: jamfpro.FalsePtr(),
Location: jamfpro.FalsePtr(),
Biometric: jamfpro.FalsePtr(),
TermsOfAddress: jamfpro.FalsePtr(),
FileVault: jamfpro.FalsePtr(),
ICloudDiagnostics: jamfpro.FalsePtr(),
Diagnostics: jamfpro.FalsePtr(),
Accessibility: jamfpro.FalsePtr(),
AppleID: jamfpro.FalsePtr(),
ScreenTime: jamfpro.FalsePtr(),
Siri: jamfpro.FalsePtr(),
DisplayTone: jamfpro.FalsePtr(),
Restore: jamfpro.FalsePtr(),
Appearance: jamfpro.FalsePtr(),
Privacy: jamfpro.FalsePtr(),
Payment: jamfpro.FalsePtr(),
Registration: jamfpro.FalsePtr(),
TOS: jamfpro.FalsePtr(),
ICloudStorage: jamfpro.FalsePtr(),
Location: jamfpro.FalsePtr(),
Intelligence: jamfpro.FalsePtr(),
EnableLockdownMode: jamfpro.FalsePtr(),
Welcome: jamfpro.FalsePtr(),
Wallpaper: jamfpro.FalsePtr(),
},
LocationInformation: jamfpro.ComputerPrestageSubsetLocationInformation{
ID: "-1", // Required
Expand Down Expand Up @@ -83,17 +87,20 @@ func main() {
WarrantyDate: "1970-01-01",
VersionLock: 0, // Not required for creates
},
EnrollmentCustomizationId: "0",
AutoAdvanceSetup: jamfpro.FalsePtr(),
InstallProfilesDuringSetup: jamfpro.TruePtr(),
PrestageInstalledProfileIds: []string{},
CustomPackageIds: []string{},
CustomPackageDistributionPointId: "-1",
EnableRecoveryLock: jamfpro.FalsePtr(),
RecoveryLockPasswordType: "MANUAL",
RotateRecoveryLockPassword: jamfpro.FalsePtr(),
SiteId: "-1",
VersionLock: 0, // Not required for creates
EnrollmentCustomizationId: "0",
AutoAdvanceSetup: jamfpro.FalsePtr(),
InstallProfilesDuringSetup: jamfpro.TruePtr(),
PrestageInstalledProfileIds: []string{},
CustomPackageIds: []string{},
CustomPackageDistributionPointId: "-1",
EnableRecoveryLock: jamfpro.FalsePtr(),
RecoveryLockPasswordType: "",
RecoveryLockPassword: "",
RotateRecoveryLockPassword: jamfpro.FalsePtr(),
PrestageMinimumOsTargetVersionType: "NO_ENFORCEMENT", // NO_ENFORCEMENT / MINIMUM_OS_LATEST_VERSION / MINIMUM_OS_LATEST_MAJOR_VERSION / MINIMUM_OS_LATEST_MINOR_VERSION / MINIMUM_OS_SPECIFIC_VERSION
MinimumOsSpecificVersion: "",
SiteId: "-1",
VersionLock: 0, // Not required for creates
AccountSettings: jamfpro.ComputerPrestageSubsetAccountSettings{
PayloadConfigured: jamfpro.TruePtr(),
LocalAdminAccountEnabled: jamfpro.FalsePtr(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func main() {
}

// ID of the computer prestage you want to retrieve
prestageID := "82" // Replace with the actual ID
prestageID := "96" // Replace with the actual ID

// Call the GetComputerPrestageByID function
prestage, err := client.GetComputerPrestageByID(prestageID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ func main() {
}

// Define a sample plan for testing
sampleUpdatePlan := &jamfpro.ResourceCreateManagedSoftwareUpdatePlan{
Devices: []jamfpro.ManagedSoftwareUpdatePlanObject{{
sampleUpdatePlan := &jamfpro.ResourceManagedSoftwareUpdatePlan{
Devices: []jamfpro.ResourcManagedSoftwareUpdatePlanObject{{
ObjectType: "COMPUTER", // COMPUTER / MOBILE_DEVICE / APPLE_TV
DeviceId: "18",
DeviceId: "21",
}},
Config: jamfpro.ManagedSoftwareUpdatePlanConfig{
Config: jamfpro.ResourcManagedSoftwareUpdatePlanConfig{
UpdateAction: "DOWNLOAD_INSTALL_ALLOW_DEFERRAL", // DOWNLOAD_ONLY / DOWNLOAD_INSTALL / DOWNLOAD_INSTALL_ALLOW_DEFERRAL / DOWNLOAD_INSTALL_RESTART / DOWNLOAD_INSTALL_SCHEDULE / UNKNOWN
VersionType: "LATEST_MAJOR", // LATEST_MAJOR / LATEST_MINOR / LATEST_ANY / SPECIFIC_VERSION / UNKNOWN
SpecificVersion: "NO_SPECIFIC_VERSION", // NO_SPECIFIC_VERSION / 14.4.1 etc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ func main() {
}

// Define a sample plan for testing
sampleUpdatePlan := &jamfpro.ResourceCreateManagedSoftwareUpdatePlan{
Group: jamfpro.ManagedSoftwareUpdatePlanObject{
sampleUpdatePlan := &jamfpro.ResourceManagedSoftwareUpdatePlan{
Group: jamfpro.ResourcManagedSoftwareUpdatePlanObject{
ObjectType: "COMPUTER_GROUP", // COMPUTER_GROUP / MOBILE_DEVICE_GROUP
GroupId: "55",
GroupId: "3",
// Do not set DeviceId for a group request
},
Config: jamfpro.ManagedSoftwareUpdatePlanConfig{
Config: jamfpro.ResourcManagedSoftwareUpdatePlanConfig{
UpdateAction: "DOWNLOAD_INSTALL_ALLOW_DEFERRAL", // DOWNLOAD_ONLY / DOWNLOAD_INSTALL / DOWNLOAD_INSTALL_ALLOW_DEFERRAL / DOWNLOAD_INSTALL_RESTART / DOWNLOAD_INSTALL_SCHEDULE / UNKNOWN
VersionType: "LATEST_MAJOR", // LATEST_MAJOR / LATEST_MINOR / LATEST_ANY / SPECIFIC_VERSION / UNKNOWN
SpecificVersion: "NO_SPECIFIC_VERSION", // NO_SPECIFIC_VERSION / 14.4.1 etc
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"encoding/json"
"fmt"
"log"

"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
)

func main() {
// Define the path to the JSON configuration file
configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json"

// Initialize the Jamf Pro client with the HTTP client configuration
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
if err != nil {
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
}

// Call GetManagedSoftwareUpdateFeatureToggle function
updatePlans, err := client.GetManagedSoftwareUpdateFeatureToggle()
if err != nil {
log.Fatalf("Error fetching managed software updates: %v", err)
}

// Pretty print the managed software updates in json
updateJSON, err := json.MarshalIndent(updatePlans, "", " ") // Indent with 4 spaces
if err != nil {
log.Fatalf("Error marshaling managed software updates data: %v", err)
}
fmt.Println("Fetched managed software update feature enablement status:\n", string(updateJSON))
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func main() {
Priority: 0,
AndOr: "and",
SearchType: "like",
Value: "macOS 14",
Value: "macOS 15",
},
},
},
Expand Down
82 changes: 35 additions & 47 deletions sdk/jamfpro/jamfproapi_managed_software_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,33 @@ type ResponseManagedSoftwareUpdateList struct {
AvailableUpdates ResourceAvailableUpdates `json:"availableUpdates"`
}

// Response

type ResponseManagedSoftwareUpdatePlanList struct {
TotalCount int `json:"totalCount"`
Results []ResourceManagedSoftwareUpdatePlanList `json:"results"`
TotalCount int `json:"totalCount"`
Results []ResponseManagedSoftwareUpdatePlan `json:"results"`
}

type ResourceManagedSoftwareUpdatePlanList struct {
PlanUuid string `json:"planUuid,omitempty"`
Device ManagedSoftwareUpdatePlanListSubsetDevice `json:"device,omitempty"`
UpdateAction string `json:"updateAction,omitempty"`
VersionType string `json:"versionType,omitempty"`
SpecificVersion string `json:"specificVersion,omitempty"`
MaxDeferrals int `json:"maxDeferrals,omitempty"`
ForceInstallLocalDateTime string `json:"forceInstallLocalDateTime,omitempty"`
RecipeId string `json:"recipeId,omitempty"`
Status ManagedSoftwareUpdatePlanListSubsetStatus `json:"status,omitempty"`
type ResponseManagedSoftwareUpdatePlan struct {
PlanUuid string `json:"planUuid,omitempty"`
Device ResponseManagedSoftwareUpdatePlanSubsetDevice `json:"device,omitempty"`
UpdateAction string `json:"updateAction,omitempty"`
VersionType string `json:"versionType,omitempty"`
SpecificVersion string `json:"specificVersion,omitempty"`
BuildVersion string `json:"buildVersion,omitempty"`
MaxDeferrals int `json:"maxDeferrals,omitempty"`
ForceInstallLocalDateTime string `json:"forceInstallLocalDateTime,omitempty"`
RecipeId string `json:"recipeId,omitempty"`
Status ResponseManagedSoftwareUpdatePlanSubsetStatus `json:"status,omitempty"`
}

type ManagedSoftwareUpdatePlanListSubsetDevice struct {
type ResponseManagedSoftwareUpdatePlanSubsetDevice struct {
DeviceId string `json:"deviceId,omitempty"`
ObjectType string `json:"objectType,omitempty"`
Href string `json:"href,omitempty"`
}

type ManagedSoftwareUpdatePlanListSubsetStatus struct {
type ResponseManagedSoftwareUpdatePlanSubsetStatus struct {
State string `json:"state,omitempty"`
ErrorReasons []string `json:"errorReasons"`
}
Expand All @@ -62,8 +65,6 @@ type ResourceDeclaration struct {
Group string `json:"group"`
}

// Response

type ResponseManagedSoftwareUpdatePlanCreate struct {
Plans []ManagedSoftwareUpdatePlanCreateSubsetPlan `json:"plans"`
}
Expand All @@ -89,12 +90,12 @@ type ResponseManagedSoftwareUpdateFeatureToggle struct {

// ResponseManagedSoftwareUpdatePlansFeatureToggleStatus represents the response structure for the feature toggle status.
type ResponseManagedSoftwareUpdatePlansFeatureToggleStatus struct {
ToggleOn *FeatureToggleStatusDetail `json:"toggleOn"`
ToggleOff *FeatureToggleStatusDetail `json:"toggleOff"`
ToggleOn *FeatureEnablementToggleStatus `json:"toggleOn"`
ToggleOff *FeatureEnablementToggleStatus `json:"toggleOff"`
}

// FeatureToggleStatusDetail represents the detailed status of the feature toggle (on/off).
type FeatureToggleStatusDetail struct {
type FeatureEnablementToggleStatus struct {
StartTime string `json:"startTime"`
EndTime string `json:"endTime"`
ElapsedTime int `json:"elapsedTime"`
Expand All @@ -114,25 +115,26 @@ type ResourceAvailableUpdates struct {
IOS []string `json:"iOS"`
}

// ResourceCreateManagedSoftwareUpdatePlan represents the payload structure for creating a managed software update plan.
type ResourceCreateManagedSoftwareUpdatePlan struct {
Devices []ManagedSoftwareUpdatePlanObject `json:"devices,omitempty"`
Group ManagedSoftwareUpdatePlanObject `json:"group,omitempty"`
Config ManagedSoftwareUpdatePlanConfig `json:"config,omitempty"`
// ResourceManagedSoftwareUpdatePlan represents the payload structure for creating a managed software update plan.
type ResourceManagedSoftwareUpdatePlan struct {
Devices []ResourcManagedSoftwareUpdatePlanObject `json:"devices,omitempty"`
Group ResourcManagedSoftwareUpdatePlanObject `json:"group,omitempty"`
Config ResourcManagedSoftwareUpdatePlanConfig `json:"config,omitempty"`
}

// ManagedSoftwareUpdatePlanDevice defines the structure for device objects in the managed software update plan.
type ManagedSoftwareUpdatePlanObject struct {
// ResourcManagedSoftwareUpdatePlanDevice defines the structure for device objects in the managed software update plan.
type ResourcManagedSoftwareUpdatePlanObject struct {
ObjectType string `json:"objectType,omitempty"`
DeviceId string `json:"deviceId,omitempty"`
GroupId string `json:"groupId,omitempty"`
}

// ManagedSoftwareUpdatePlanConfig defines the configuration for a managed software update plan.
type ManagedSoftwareUpdatePlanConfig struct {
// ResourcManagedSoftwareUpdatePlanConfig defines the configuration for a managed software update plan.
type ResourcManagedSoftwareUpdatePlanConfig struct {
UpdateAction string `json:"updateAction,omitempty"`
VersionType string `json:"versionType,omitempty"`
SpecificVersion string `json:"specificVersion,omitempty"`
BuildVersion string `json:"buildVersion,omitempty"`
MaxDeferrals int `json:"maxDeferrals,omitempty"`
ForceInstallLocalDateTime string `json:"forceInstallLocalDateTime,omitempty"`
}
Expand All @@ -142,20 +144,6 @@ type ResourceManagedSoftwareUpdateFeatureToggle struct {
Toggle bool `json:"toggle"`
}

// ResourceManagedSoftwareUpdatePlan represents the detailed response for a Managed Software Update Plan.
type ResourceManagedSoftwareUpdatePlan struct {
PlanUuid string `json:"planUuid"`
Device ManagedSoftwareUpdatePlanListSubsetDevice `json:"device"`
UpdateAction string `json:"updateAction"`
VersionType string `json:"versionType"`
SpecificVersion string `json:"specificVersion"`
BuildVersion string `json:"buildVersion,omitempty"`
MaxDeferrals int `json:"maxDeferrals"`
ForceInstallLocalDateTime string `json:"forceInstallLocalDateTime,omitempty"`
RecipeId string `json:"recipeId"`
Status ManagedSoftwareUpdatePlanListSubsetStatus `json:"status"`
}

// CRUD

// GetManagedSoftwareUpdates retrieves a list of all available managed software updates
Expand Down Expand Up @@ -192,7 +180,7 @@ func (c *Client) GetManagedSoftwareUpdatePlans(sort_filter string) (*ResponseMan
out.TotalCount = resp.Size

for _, value := range resp.Results {
var newObj ResourceManagedSoftwareUpdatePlanList
var newObj ResponseManagedSoftwareUpdatePlan
err := mapstructure.Decode(value, &newObj)
if err != nil {
return nil, fmt.Errorf(errMsgFailedMapstruct, "script", err)
Expand All @@ -205,7 +193,7 @@ func (c *Client) GetManagedSoftwareUpdatePlans(sort_filter string) (*ResponseMan
}

// CreateManagedSoftwareUpdatePlanByDeviceID Creates Managed Software Update Plan by Device ID
func (c *Client) CreateManagedSoftwareUpdatePlanByDeviceID(plan *ResourceCreateManagedSoftwareUpdatePlan) (*ResponseManagedSoftwareUpdatePlanCreate, error) {
func (c *Client) CreateManagedSoftwareUpdatePlanByDeviceID(plan *ResourceManagedSoftwareUpdatePlan) (*ResponseManagedSoftwareUpdatePlanCreate, error) {
endpoint := uriManagedSoftwareUpdates + "/plans"
var responseManagedSoftwareUpdatePlanCreate ResponseManagedSoftwareUpdatePlanCreate

Expand Down Expand Up @@ -291,7 +279,7 @@ func (c *Client) GetManagedSoftwareUpdatePlansFeatureToggleStatus() (*ResponseMa
}

// CreateManagedSoftwareUpdatePlanByDeviceGroupID creates a managed software update plan by group ID
func (c *Client) CreateManagedSoftwareUpdatePlanByGroupID(plan *ResourceCreateManagedSoftwareUpdatePlan) (*ResponseManagedSoftwareUpdatePlanCreate, error) {
func (c *Client) CreateManagedSoftwareUpdatePlanByGroupID(plan *ResourceManagedSoftwareUpdatePlan) (*ResponseManagedSoftwareUpdatePlanCreate, error) {
endpoint := uriManagedSoftwareUpdates + "/plans/group"
var responseManagedSoftwareUpdatePlanCreate ResponseManagedSoftwareUpdatePlanCreate

Expand Down Expand Up @@ -325,10 +313,10 @@ func (c *Client) GetManagedSoftwareUpdatePlansByGroupID(groupId string, groupTyp
}

// GetManagedSoftwareUpdatePlanByUUID retrieves a Managed Software Update Plan by its UUID.
func (c *Client) GetManagedSoftwareUpdatePlanByUUID(UUID string) (*ResourceManagedSoftwareUpdatePlan, error) {
func (c *Client) GetManagedSoftwareUpdatePlanByUUID(UUID string) (*ResponseManagedSoftwareUpdatePlan, error) {
endpoint := fmt.Sprintf("%s/plans/%s", uriManagedSoftwareUpdates, UUID)

var planDetail ResourceManagedSoftwareUpdatePlan
var planDetail ResponseManagedSoftwareUpdatePlan
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &planDetail)
if err != nil {
return nil, fmt.Errorf("failed to retrieve managed software update plan with ID %s: %v", UUID, err)
Expand Down

0 comments on commit fb5246f

Please sign in to comment.