From 847296d2328c518161e6ce53c998c0796eddda24 Mon Sep 17 00:00:00 2001 From: ShocOne <62835948+ShocOne@users.noreply.github.com> Date: Thu, 15 Aug 2024 11:56:40 +0100 Subject: [PATCH 1/5] + bool pointer helpers and made computer prestage bools use pointers --- .../CreateComputerPrestageFullConfig.go | 76 +++++----- .../CreateComputerPrestageMinimumConfig.go | 134 +++++++++--------- .../GetComputerPrestageByID.go | 2 +- sdk/jamfpro/jamfproapi_computer_prestages.go | 76 +++++----- sdk/jamfpro/shared_helpers.go | 19 +++ 5 files changed, 166 insertions(+), 141 deletions(-) create mode 100644 sdk/jamfpro/shared_helpers.go diff --git a/examples/computer_prestages/CreateComputerPrestageFullConfig/CreateComputerPrestageFullConfig.go b/examples/computer_prestages/CreateComputerPrestageFullConfig/CreateComputerPrestageFullConfig.go index f8266cb1..ee0e84ce 100644 --- a/examples/computer_prestages/CreateComputerPrestageFullConfig/CreateComputerPrestageFullConfig.go +++ b/examples/computer_prestages/CreateComputerPrestageFullConfig/CreateComputerPrestageFullConfig.go @@ -22,42 +22,42 @@ func main() { // Manually create a ResourceComputerPrestage struct with mapped values prestage := jamfpro.ResourceComputerPrestage{ DisplayName: "jamfpro-sdk-example-computerPrestageFull-config", - Mandatory: true, - MDMRemovable: true, + Mandatory: jamfpro.TruePtr(), + MDMRemovable: jamfpro.TruePtr(), SupportPhoneNumber: "118-118", SupportEmailAddress: "email@company.com", Department: "department name", - DefaultPrestage: false, + DefaultPrestage: jamfpro.FalsePtr(), EnrollmentSiteId: "-1", - KeepExistingSiteMembership: true, - KeepExistingLocationInformation: true, - RequireAuthentication: true, + KeepExistingSiteMembership: jamfpro.TruePtr(), + KeepExistingLocationInformation: jamfpro.TruePtr(), + RequireAuthentication: jamfpro.TruePtr(), AuthenticationPrompt: "hello welcome to your enterprise managed macOS device", - PreventActivationLock: false, - EnableDeviceBasedActivationLock: false, - EnableRecoveryLock: false, + PreventActivationLock: jamfpro.FalsePtr(), + EnableDeviceBasedActivationLock: jamfpro.FalsePtr(), + EnableRecoveryLock: jamfpro.FalsePtr(), RecoveryLockPasswordType: "MANUAL", - RotateRecoveryLockPassword: false, + RotateRecoveryLockPassword: jamfpro.FalsePtr(), DeviceEnrollmentProgramInstanceId: "1", SkipSetupItems: jamfpro.ComputerPrestageSubsetSkipSetupItems{ - Accessibility: true, - Appearance: true, - AppleID: true, - Biometric: true, - Diagnostics: true, - DisplayTone: true, - FileVault: true, - Location: true, - Payment: true, - Privacy: true, - Registration: true, - Restore: true, - ScreenTime: true, - Siri: true, - TOS: true, - TermsOfAddress: true, - ICloudDiagnostics: true, - ICloudStorage: true, + Accessibility: jamfpro.TruePtr(), + Appearance: jamfpro.TruePtr(), + AppleID: jamfpro.TruePtr(), + Biometric: jamfpro.TruePtr(), + Diagnostics: jamfpro.TruePtr(), + DisplayTone: jamfpro.TruePtr(), + FileVault: jamfpro.TruePtr(), + Location: jamfpro.TruePtr(), + Payment: jamfpro.TruePtr(), + Privacy: jamfpro.TruePtr(), + Registration: jamfpro.TruePtr(), + Restore: jamfpro.TruePtr(), + ScreenTime: jamfpro.TruePtr(), + Siri: jamfpro.TruePtr(), + TOS: jamfpro.TruePtr(), + TermsOfAddress: jamfpro.TruePtr(), + ICloudDiagnostics: jamfpro.TruePtr(), + ICloudStorage: jamfpro.TruePtr(), }, LocationInformation: jamfpro.ComputerPrestageSubsetLocationInformation{ Username: "", @@ -73,8 +73,8 @@ func main() { }, PurchasingInformation: jamfpro.ComputerPrestageSubsetPurchasingInformation{ ID: "1", - Leased: false, - Purchased: true, + Leased: jamfpro.FalsePtr(), + Purchased: jamfpro.TruePtr(), AppleCareId: "", PONumber: "", Vendor: "", @@ -91,8 +91,8 @@ func main() { EnrollmentCustomizationId: "0", Language: "en", Region: "GB", - AutoAdvanceSetup: true, - InstallProfilesDuringSetup: true, + AutoAdvanceSetup: jamfpro.TruePtr(), + InstallProfilesDuringSetup: jamfpro.TruePtr(), PrestageInstalledProfileIds: []string{ "287", "288", @@ -107,19 +107,19 @@ func main() { VersionLock: 3, AccountSettings: jamfpro.ComputerPrestageSubsetAccountSettings{ ID: "1", - PayloadConfigured: true, - LocalAdminAccountEnabled: true, + PayloadConfigured: jamfpro.TruePtr(), + LocalAdminAccountEnabled: jamfpro.TruePtr(), AdminUsername: "localAdmin", AdminPassword: "thingthing1010", - HiddenAdminAccount: true, - LocalUserManaged: false, + HiddenAdminAccount: jamfpro.TruePtr(), + LocalUserManaged: jamfpro.FalsePtr(), UserAccountType: "ADMINISTRATOR", VersionLock: 1, - PrefillPrimaryAccountInfoFeatureEnabled: false, + PrefillPrimaryAccountInfoFeatureEnabled: jamfpro.FalsePtr(), PrefillType: "CUSTOM", PrefillAccountFullName: "", PrefillAccountUserName: "", - PreventPrefillInfoFromModification: false, + PreventPrefillInfoFromModification: jamfpro.FalsePtr(), }, } diff --git a/examples/computer_prestages/CreateComputerPrestageMinimumConfig/CreateComputerPrestageMinimumConfig.go b/examples/computer_prestages/CreateComputerPrestageMinimumConfig/CreateComputerPrestageMinimumConfig.go index 32bebb6c..45282f8c 100644 --- a/examples/computer_prestages/CreateComputerPrestageMinimumConfig/CreateComputerPrestageMinimumConfig.go +++ b/examples/computer_prestages/CreateComputerPrestageMinimumConfig/CreateComputerPrestageMinimumConfig.go @@ -19,44 +19,45 @@ func main() { } // Define the payload for creating a new computer prestage - // Manually create a ResourceComputerPrestage struct with mapped values prestage := jamfpro.ResourceComputerPrestage{ - DisplayName: "jamfpro-sdk-example-computerPrestage-config", - Mandatory: true, - MDMRemovable: false, - SupportPhoneNumber: "", - SupportEmailAddress: "", - Department: "", - DefaultPrestage: false, + //ID: "-1", + DisplayName: "jamfpro-sdk-example-computerPrestageMinimum-config", + Mandatory: jamfpro.TruePtr(), + MDMRemovable: jamfpro.TruePtr(), + SupportPhoneNumber: "111-222-3333", + SupportEmailAddress: "email@company.com", + Department: "department name", + DefaultPrestage: jamfpro.FalsePtr(), EnrollmentSiteId: "-1", - KeepExistingSiteMembership: false, - KeepExistingLocationInformation: false, - RequireAuthentication: false, - AuthenticationPrompt: "", - PreventActivationLock: true, - EnableDeviceBasedActivationLock: false, + KeepExistingSiteMembership: jamfpro.FalsePtr(), + KeepExistingLocationInformation: jamfpro.FalsePtr(), + RequireAuthentication: jamfpro.FalsePtr(), + AuthenticationPrompt: "hello welcome to your enterprise managed macOS device", + PreventActivationLock: jamfpro.FalsePtr(), + EnableDeviceBasedActivationLock: jamfpro.FalsePtr(), DeviceEnrollmentProgramInstanceId: "1", SkipSetupItems: jamfpro.ComputerPrestageSubsetSkipSetupItems{ - Accessibility: true, - Appearance: true, - AppleID: true, - Biometric: true, - Diagnostics: true, - DisplayTone: true, - FileVault: true, - Location: true, - Payment: true, - Privacy: true, - Registration: true, - Restore: true, - ScreenTime: true, - Siri: true, - TOS: true, - TermsOfAddress: true, - ICloudDiagnostics: true, - ICloudStorage: true, + 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(), }, LocationInformation: jamfpro.ComputerPrestageSubsetLocationInformation{ + ID: "-1", Username: "", Realname: "", Phone: "", @@ -65,13 +66,12 @@ func main() { Position: "", DepartmentId: "-1", BuildingId: "-1", - ID: "1", VersionLock: 0, }, PurchasingInformation: jamfpro.ComputerPrestageSubsetPurchasingInformation{ - ID: "1", - Leased: false, - Purchased: true, + ID: "-1", + Leased: jamfpro.FalsePtr(), + Purchased: jamfpro.TruePtr(), AppleCareId: "", PONumber: "", Vendor: "", @@ -84,49 +84,55 @@ func main() { WarrantyDate: "1970-01-01", VersionLock: 0, }, - AnchorCertificates: []string{}, - EnrollmentCustomizationId: "0", - Language: "en", - Region: "GB", - AutoAdvanceSetup: true, - InstallProfilesDuringSetup: true, - PrestageInstalledProfileIds: []string{}, + EnrollmentCustomizationId: "0", + AutoAdvanceSetup: jamfpro.FalsePtr(), + InstallProfilesDuringSetup: jamfpro.TruePtr(), + PrestageInstalledProfileIds: []string{ + "3847", + "3864", + "3806", + }, CustomPackageIds: []string{}, CustomPackageDistributionPointId: "-1", - EnableRecoveryLock: false, + EnableRecoveryLock: jamfpro.FalsePtr(), RecoveryLockPasswordType: "MANUAL", - RotateRecoveryLockPassword: false, - ID: "1", - ProfileUuid: "C101330EE870D6082D5D08FA013ADE51", + RotateRecoveryLockPassword: jamfpro.FalsePtr(), + ProfileUuid: "0386E7C8D455A040106850A8A2033968", SiteId: "-1", - VersionLock: 3, AccountSettings: jamfpro.ComputerPrestageSubsetAccountSettings{ - ID: "1", - PayloadConfigured: true, - LocalAdminAccountEnabled: true, - AdminUsername: "localAdmin", - HiddenAdminAccount: true, - LocalUserManaged: false, + ID: "-1", + PayloadConfigured: jamfpro.TruePtr(), + LocalAdminAccountEnabled: jamfpro.TruePtr(), + AdminUsername: "Administrator", + AdminPassword: "Administrator", + HiddenAdminAccount: jamfpro.TruePtr(), + LocalUserManaged: jamfpro.FalsePtr(), UserAccountType: "ADMINISTRATOR", - VersionLock: 1, - PrefillPrimaryAccountInfoFeatureEnabled: false, - PrefillType: "CUSTOM", - PrefillAccountFullName: "", - PrefillAccountUserName: "", - PreventPrefillInfoFromModification: false, + PrefillPrimaryAccountInfoFeatureEnabled: jamfpro.TruePtr(), + PrefillType: "DEVICE_OWNER", + PreventPrefillInfoFromModification: jamfpro.FalsePtr(), }, } + // Marshal the prestage struct to JSON and print it + prestageJSON, err := json.MarshalIndent(prestage, "", " ") + if err != nil { + log.Fatalf("Error marshaling prestage data: %v", err) + } + fmt.Println("Prestage configuration to be sent:") + fmt.Println(string(prestageJSON)) + // Call the CreateComputerPrestage function createdPrestage, err := client.CreateComputerPrestage(&prestage) if err != nil { log.Fatalf("Error creating computer prestage: %v", err) } - // Pretty print the computer prestage in JSON - prestageJSON, err := json.MarshalIndent(createdPrestage, "", " ") // Indent with 4 spaces + // Pretty print the created computer prestage in JSON + createdPrestageJSON, err := json.MarshalIndent(createdPrestage, "", " ") if err != nil { - log.Fatalf("Error marshaling computer prestage data: %v", err) + log.Fatalf("Error marshaling created prestage data: %v", err) } - fmt.Println("Created computer prestage:\n", string(prestageJSON)) + fmt.Println("Created computer prestage:") + fmt.Println(string(createdPrestageJSON)) } diff --git a/examples/computer_prestages/GetComputerPrestageByID/GetComputerPrestageByID.go b/examples/computer_prestages/GetComputerPrestageByID/GetComputerPrestageByID.go index 22fb6025..9b0c55d5 100644 --- a/examples/computer_prestages/GetComputerPrestageByID/GetComputerPrestageByID.go +++ b/examples/computer_prestages/GetComputerPrestageByID/GetComputerPrestageByID.go @@ -19,7 +19,7 @@ func main() { } // ID of the computer prestage you want to retrieve - prestageID := "7" // Replace with the actual ID + prestageID := "45" // Replace with the actual ID // Call the GetComputerPrestageByID function prestage, err := client.GetComputerPrestageByID(prestageID) diff --git a/sdk/jamfpro/jamfproapi_computer_prestages.go b/sdk/jamfpro/jamfproapi_computer_prestages.go index 5728fc98..d79f509a 100644 --- a/sdk/jamfpro/jamfproapi_computer_prestages.go +++ b/sdk/jamfpro/jamfproapi_computer_prestages.go @@ -48,19 +48,19 @@ type ResponseComputerPrestageCreate struct { type ResourceComputerPrestage struct { ID string `json:"id"` DisplayName string `json:"displayName"` - Mandatory bool `json:"mandatory"` - MDMRemovable bool `json:"mdmRemovable"` + Mandatory *bool `json:"mandatory"` + MDMRemovable *bool `json:"mdmRemovable"` SupportPhoneNumber string `json:"supportPhoneNumber,omitempty"` SupportEmailAddress string `json:"supportEmailAddress,omitempty"` Department string `json:"department,omitempty"` - DefaultPrestage bool `json:"defaultPrestage"` + DefaultPrestage *bool `json:"defaultPrestage"` EnrollmentSiteId string `json:"enrollmentSiteId,omitempty"` - KeepExistingSiteMembership bool `json:"keepExistingSiteMembership"` - KeepExistingLocationInformation bool `json:"keepExistingLocationInformation"` - RequireAuthentication bool `json:"requireAuthentication"` + KeepExistingSiteMembership *bool `json:"keepExistingSiteMembership"` + KeepExistingLocationInformation *bool `json:"keepExistingLocationInformation"` + RequireAuthentication *bool `json:"requireAuthentication"` AuthenticationPrompt string `json:"authenticationPrompt,omitempty"` - PreventActivationLock bool `json:"preventActivationLock"` - EnableDeviceBasedActivationLock bool `json:"enableDeviceBasedActivationLock"` + PreventActivationLock *bool `json:"preventActivationLock"` + EnableDeviceBasedActivationLock *bool `json:"enableDeviceBasedActivationLock"` DeviceEnrollmentProgramInstanceId string `json:"deviceEnrollmentProgramInstanceId,omitempty"` SkipSetupItems ComputerPrestageSubsetSkipSetupItems `json:"skipSetupItems"` LocationInformation ComputerPrestageSubsetLocationInformation `json:"locationInformation"` @@ -69,15 +69,15 @@ type ResourceComputerPrestage struct { EnrollmentCustomizationId string `json:"enrollmentCustomizationId,omitempty"` Language string `json:"language,omitempty"` Region string `json:"region,omitempty"` - AutoAdvanceSetup bool `json:"autoAdvanceSetup"` - InstallProfilesDuringSetup bool `json:"installProfilesDuringSetup"` + AutoAdvanceSetup *bool `json:"autoAdvanceSetup"` + InstallProfilesDuringSetup *bool `json:"installProfilesDuringSetup"` PrestageInstalledProfileIds []string `json:"prestageInstalledProfileIds,omitempty"` CustomPackageIds []string `json:"customPackageIds,omitempty"` CustomPackageDistributionPointId string `json:"customPackageDistributionPointId,omitempty"` - EnableRecoveryLock bool `json:"enableRecoveryLock"` + EnableRecoveryLock *bool `json:"enableRecoveryLock"` RecoveryLockPasswordType string `json:"recoveryLockPasswordType,omitempty"` RecoveryLockPassword string `json:"recoveryLockPassword,omitempty"` - RotateRecoveryLockPassword bool `json:"rotateRecoveryLockPassword"` + RotateRecoveryLockPassword *bool `json:"rotateRecoveryLockPassword"` ProfileUuid string `json:"profileUuid,omitempty"` SiteId string `json:"siteId,omitempty"` VersionLock int `json:"versionLock,omitempty"` @@ -87,24 +87,24 @@ type ResourceComputerPrestage struct { // Subsets & Containers type ComputerPrestageSubsetSkipSetupItems struct { - Biometric bool `json:"Biometric"` - TermsOfAddress bool `json:"TermsOfAddress"` - FileVault bool `json:"FileVault"` - ICloudDiagnostics bool `json:"iCloudDiagnostics"` - Diagnostics bool `json:"Diagnostics"` - Accessibility bool `json:"Accessibility"` - AppleID bool `json:"AppleID"` - ScreenTime bool `json:"ScreenTime"` - Siri bool `json:"Siri"` - DisplayTone bool `json:"DisplayTone"` - Restore bool `json:"Restore"` - Appearance bool `json:"Appearance"` - Privacy bool `json:"Privacy"` - Payment bool `json:"Payment"` - Registration bool `json:"Registration"` - TOS bool `json:"TOS"` - ICloudStorage bool `json:"iCloudStorage"` - Location bool `json:"Location"` + Biometric *bool `json:"Biometric"` + TermsOfAddress *bool `json:"TermsOfAddress"` + FileVault *bool `json:"FileVault"` + ICloudDiagnostics *bool `json:"iCloudDiagnostics"` + Diagnostics *bool `json:"Diagnostics"` + Accessibility *bool `json:"Accessibility"` + AppleID *bool `json:"AppleID"` + ScreenTime *bool `json:"ScreenTime"` + Siri *bool `json:"Siri"` + DisplayTone *bool `json:"DisplayTone"` + Restore *bool `json:"Restore"` + Appearance *bool `json:"Appearance"` + Privacy *bool `json:"Privacy"` + Payment *bool `json:"Payment"` + Registration *bool `json:"Registration"` + TOS *bool `json:"TOS"` + ICloudStorage *bool `json:"iCloudStorage"` + Location *bool `json:"Location"` } type ComputerPrestageSubsetLocationInformation struct { @@ -122,8 +122,8 @@ type ComputerPrestageSubsetLocationInformation struct { type ComputerPrestageSubsetPurchasingInformation struct { ID string `json:"id,omitempty"` - Leased bool `json:"leased"` - Purchased bool `json:"purchased"` + Leased *bool `json:"leased"` + Purchased *bool `json:"purchased"` AppleCareId string `json:"appleCareId"` PONumber string `json:"poNumber"` Vendor string `json:"vendor"` @@ -139,19 +139,19 @@ type ComputerPrestageSubsetPurchasingInformation struct { type ComputerPrestageSubsetAccountSettings struct { ID string `json:"id,omitempty"` - PayloadConfigured bool `json:"payloadConfigured"` - LocalAdminAccountEnabled bool `json:"localAdminAccountEnabled"` + PayloadConfigured *bool `json:"payloadConfigured"` + LocalAdminAccountEnabled *bool `json:"localAdminAccountEnabled"` AdminUsername string `json:"adminUsername,omitempty"` AdminPassword string `json:"adminPassword,omitempty"` - HiddenAdminAccount bool `json:"hiddenAdminAccount"` - LocalUserManaged bool `json:"localUserManaged"` + HiddenAdminAccount *bool `json:"hiddenAdminAccount"` + LocalUserManaged *bool `json:"localUserManaged"` UserAccountType string `json:"userAccountType,omitempty"` VersionLock int `json:"versionLock,omitempty"` - PrefillPrimaryAccountInfoFeatureEnabled bool `json:"prefillPrimaryAccountInfoFeatureEnabled"` + PrefillPrimaryAccountInfoFeatureEnabled *bool `json:"prefillPrimaryAccountInfoFeatureEnabled"` PrefillType string `json:"prefillType,omitempty"` PrefillAccountFullName string `json:"prefillAccountFullName,omitempty"` PrefillAccountUserName string `json:"prefillAccountUserName,omitempty"` - PreventPrefillInfoFromModification bool `json:"preventPrefillInfoFromModification"` + PreventPrefillInfoFromModification *bool `json:"preventPrefillInfoFromModification"` } // CRUD diff --git a/sdk/jamfpro/shared_helpers.go b/sdk/jamfpro/shared_helpers.go new file mode 100644 index 00000000..17e97526 --- /dev/null +++ b/sdk/jamfpro/shared_helpers.go @@ -0,0 +1,19 @@ +// shared_helpers.go +// these are used where a bool value is set to a pointer in scenarios where the value needs to send a valid false value +// and not an empty value. +package jamfpro + +// BoolPtr returns a pointer to a bool value +func BoolPtr(b bool) *bool { + return &b +} + +// TruePtr returns a pointer to a true bool value +func TruePtr() *bool { + return BoolPtr(true) +} + +// FalsePtr returns a pointer to a false bool value +func FalsePtr() *bool { + return BoolPtr(false) +} From f3fd7a4f3fc4385aa79254fcb8b3be27f129d919 Mon Sep 17 00:00:00 2001 From: ShocOne <62835948+ShocOne@users.noreply.github.com> Date: Thu, 15 Aug 2024 13:01:36 +0100 Subject: [PATCH 2/5] Refactor computer prestage creation to use bool pointers for optional fields --- .../CreateComputerPrestageFullConfig.go | 112 ++++++++--------- .../CreateComputerPrestageMinimumConfig.go | 114 ++++++++---------- sdk/jamfpro/jamfproapi_computer_prestages.go | 111 ++++++++++------- 3 files changed, 178 insertions(+), 159 deletions(-) diff --git a/examples/computer_prestages/CreateComputerPrestageFullConfig/CreateComputerPrestageFullConfig.go b/examples/computer_prestages/CreateComputerPrestageFullConfig/CreateComputerPrestageFullConfig.go index ee0e84ce..d30d2b08 100644 --- a/examples/computer_prestages/CreateComputerPrestageFullConfig/CreateComputerPrestageFullConfig.go +++ b/examples/computer_prestages/CreateComputerPrestageFullConfig/CreateComputerPrestageFullConfig.go @@ -19,47 +19,45 @@ func main() { } // Define the payload for creating a new computer prestage - // Manually create a ResourceComputerPrestage struct with mapped values prestage := jamfpro.ResourceComputerPrestage{ - DisplayName: "jamfpro-sdk-example-computerPrestageFull-config", + //ID: "-1", + DisplayName: "jamfpro-sdk-example-computerPrestageMinimum-config", Mandatory: jamfpro.TruePtr(), MDMRemovable: jamfpro.TruePtr(), - SupportPhoneNumber: "118-118", + SupportPhoneNumber: "111-222-3333", SupportEmailAddress: "email@company.com", Department: "department name", DefaultPrestage: jamfpro.FalsePtr(), EnrollmentSiteId: "-1", - KeepExistingSiteMembership: jamfpro.TruePtr(), - KeepExistingLocationInformation: jamfpro.TruePtr(), - RequireAuthentication: jamfpro.TruePtr(), + KeepExistingSiteMembership: jamfpro.FalsePtr(), + KeepExistingLocationInformation: jamfpro.FalsePtr(), + RequireAuthentication: jamfpro.FalsePtr(), AuthenticationPrompt: "hello welcome to your enterprise managed macOS device", PreventActivationLock: jamfpro.FalsePtr(), EnableDeviceBasedActivationLock: jamfpro.FalsePtr(), - EnableRecoveryLock: jamfpro.FalsePtr(), - RecoveryLockPasswordType: "MANUAL", - RotateRecoveryLockPassword: jamfpro.FalsePtr(), DeviceEnrollmentProgramInstanceId: "1", SkipSetupItems: jamfpro.ComputerPrestageSubsetSkipSetupItems{ - Accessibility: jamfpro.TruePtr(), - Appearance: jamfpro.TruePtr(), - AppleID: jamfpro.TruePtr(), - Biometric: jamfpro.TruePtr(), - Diagnostics: jamfpro.TruePtr(), - DisplayTone: jamfpro.TruePtr(), - FileVault: jamfpro.TruePtr(), - Location: jamfpro.TruePtr(), - Payment: jamfpro.TruePtr(), - Privacy: jamfpro.TruePtr(), - Registration: jamfpro.TruePtr(), - Restore: jamfpro.TruePtr(), - ScreenTime: jamfpro.TruePtr(), - Siri: jamfpro.TruePtr(), - TOS: jamfpro.TruePtr(), - TermsOfAddress: jamfpro.TruePtr(), - ICloudDiagnostics: jamfpro.TruePtr(), - ICloudStorage: jamfpro.TruePtr(), + 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(), }, LocationInformation: jamfpro.ComputerPrestageSubsetLocationInformation{ + //ID: "-1", Username: "", Realname: "", Phone: "", @@ -68,11 +66,10 @@ func main() { Position: "", DepartmentId: "-1", BuildingId: "-1", - ID: "1", - VersionLock: 0, + VersionLock: 1, }, PurchasingInformation: jamfpro.ComputerPrestageSubsetPurchasingInformation{ - ID: "1", + //ID: "-1", Leased: jamfpro.FalsePtr(), Purchased: jamfpro.TruePtr(), AppleCareId: "", @@ -85,54 +82,59 @@ func main() { LeaseDate: "1970-01-01", PODate: "1970-01-01", WarrantyDate: "1970-01-01", - VersionLock: 0, + VersionLock: 1, }, - AnchorCertificates: []string{}, EnrollmentCustomizationId: "0", - Language: "en", - Region: "GB", - AutoAdvanceSetup: jamfpro.TruePtr(), + AutoAdvanceSetup: jamfpro.FalsePtr(), InstallProfilesDuringSetup: jamfpro.TruePtr(), PrestageInstalledProfileIds: []string{ - "287", - "288", - "289"}, - CustomPackageIds: []string{ - "3", + "3847", + "3864", + "3806", }, + CustomPackageIds: []string{}, CustomPackageDistributionPointId: "-1", - ID: "1", - ProfileUuid: "C101330EE870D6082D5D08FA013ADE51", + EnableRecoveryLock: jamfpro.FalsePtr(), + RecoveryLockPasswordType: "MANUAL", + RotateRecoveryLockPassword: jamfpro.FalsePtr(), + ProfileUuid: "0386E7C8D455A040106850A8A2033968", SiteId: "-1", - VersionLock: 3, + VersionLock: 1, AccountSettings: jamfpro.ComputerPrestageSubsetAccountSettings{ - ID: "1", + //ID: "-1", PayloadConfigured: jamfpro.TruePtr(), - LocalAdminAccountEnabled: jamfpro.TruePtr(), - AdminUsername: "localAdmin", - AdminPassword: "thingthing1010", - HiddenAdminAccount: jamfpro.TruePtr(), + LocalAdminAccountEnabled: jamfpro.FalsePtr(), + AdminUsername: "", + AdminPassword: "", + HiddenAdminAccount: jamfpro.FalsePtr(), LocalUserManaged: jamfpro.FalsePtr(), UserAccountType: "ADMINISTRATOR", VersionLock: 1, PrefillPrimaryAccountInfoFeatureEnabled: jamfpro.FalsePtr(), - PrefillType: "CUSTOM", - PrefillAccountFullName: "", - PrefillAccountUserName: "", + PrefillType: "UNKNOWN", PreventPrefillInfoFromModification: jamfpro.FalsePtr(), }, } + // Marshal the prestage struct to JSON and print it + prestageJSON, err := json.MarshalIndent(prestage, "", " ") + if err != nil { + log.Fatalf("Error marshaling prestage data: %v", err) + } + fmt.Println("Prestage configuration to be sent:") + fmt.Println(string(prestageJSON)) + // Call the CreateComputerPrestage function createdPrestage, err := client.CreateComputerPrestage(&prestage) if err != nil { log.Fatalf("Error creating computer prestage: %v", err) } - // Pretty print the computer prestage in JSON - prestageJSON, err := json.MarshalIndent(createdPrestage, "", " ") // Indent with 4 spaces + // Pretty print the created computer prestage in JSON + createdPrestageJSON, err := json.MarshalIndent(createdPrestage, "", " ") if err != nil { - log.Fatalf("Error marshaling computer prestage data: %v", err) + log.Fatalf("Error marshaling created prestage data: %v", err) } - fmt.Println("Created computer prestage:\n", string(prestageJSON)) + fmt.Println("Created computer prestage:") + fmt.Println(string(createdPrestageJSON)) } diff --git a/examples/computer_prestages/CreateComputerPrestageMinimumConfig/CreateComputerPrestageMinimumConfig.go b/examples/computer_prestages/CreateComputerPrestageMinimumConfig/CreateComputerPrestageMinimumConfig.go index 45282f8c..a6b5228e 100644 --- a/examples/computer_prestages/CreateComputerPrestageMinimumConfig/CreateComputerPrestageMinimumConfig.go +++ b/examples/computer_prestages/CreateComputerPrestageMinimumConfig/CreateComputerPrestageMinimumConfig.go @@ -20,72 +20,57 @@ func main() { // Define the payload for creating a new computer prestage prestage := jamfpro.ResourceComputerPrestage{ - //ID: "-1", - DisplayName: "jamfpro-sdk-example-computerPrestageMinimum-config", - Mandatory: jamfpro.TruePtr(), + DisplayName: "Example Mobile Prestage Name", + Mandatory: jamfpro.FalsePtr(), MDMRemovable: jamfpro.TruePtr(), - SupportPhoneNumber: "111-222-3333", - SupportEmailAddress: "email@company.com", - Department: "department name", + SupportPhoneNumber: "5555555555", + SupportEmailAddress: "example@example.com", + Department: "Oxbow", DefaultPrestage: jamfpro.FalsePtr(), EnrollmentSiteId: "-1", - KeepExistingSiteMembership: jamfpro.FalsePtr(), - KeepExistingLocationInformation: jamfpro.FalsePtr(), - RequireAuthentication: jamfpro.FalsePtr(), - AuthenticationPrompt: "hello welcome to your enterprise managed macOS device", - PreventActivationLock: jamfpro.FalsePtr(), - EnableDeviceBasedActivationLock: jamfpro.FalsePtr(), + KeepExistingSiteMembership: jamfpro.TruePtr(), + KeepExistingLocationInformation: jamfpro.TruePtr(), + RequireAuthentication: jamfpro.TruePtr(), + AuthenticationPrompt: "LDAP authentication prompt", + PreventActivationLock: jamfpro.TruePtr(), + EnableDeviceBasedActivationLock: jamfpro.TruePtr(), 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(), + Location: jamfpro.TruePtr(), + Privacy: jamfpro.FalsePtr(), }, LocationInformation: jamfpro.ComputerPrestageSubsetLocationInformation{ - ID: "-1", - Username: "", - Realname: "", - Phone: "", - Email: "", - Room: "", - Position: "", - DepartmentId: "-1", - BuildingId: "-1", - VersionLock: 0, + Username: "name", + Realname: "realName", + Phone: "123-456-7890", + Email: "test@jamf.com", + Room: "room", + Position: "postion", + DepartmentId: "1", + BuildingId: "1", + //ID: "-1", + VersionLock: 1, }, PurchasingInformation: jamfpro.ComputerPrestageSubsetPurchasingInformation{ - ID: "-1", - Leased: jamfpro.FalsePtr(), + //ID: "-1", + Leased: jamfpro.TruePtr(), Purchased: jamfpro.TruePtr(), - AppleCareId: "", - PONumber: "", - Vendor: "", - PurchasePrice: "", - LifeExpectancy: 0, - PurchasingAccount: "", - PurchasingContact: "", - LeaseDate: "1970-01-01", - PODate: "1970-01-01", - WarrantyDate: "1970-01-01", - VersionLock: 0, + AppleCareId: "abcd", + PONumber: "53-1", + Vendor: "Example Vendor", + PurchasePrice: "$500", + LifeExpectancy: 5, + PurchasingAccount: "admin", + PurchasingContact: "true", + LeaseDate: "2019-01-01", + PODate: "2019-01-01", + WarrantyDate: "2019-01-01", + VersionLock: 1, }, EnrollmentCustomizationId: "0", - AutoAdvanceSetup: jamfpro.FalsePtr(), + Language: "en", + Region: "US", + AutoAdvanceSetup: jamfpro.TruePtr(), InstallProfilesDuringSetup: jamfpro.TruePtr(), PrestageInstalledProfileIds: []string{ "3847", @@ -94,24 +79,29 @@ func main() { }, CustomPackageIds: []string{}, CustomPackageDistributionPointId: "-1", - EnableRecoveryLock: jamfpro.FalsePtr(), + EnableRecoveryLock: jamfpro.TruePtr(), RecoveryLockPasswordType: "MANUAL", - RotateRecoveryLockPassword: jamfpro.FalsePtr(), + RotateRecoveryLockPassword: jamfpro.TruePtr(), ProfileUuid: "0386E7C8D455A040106850A8A2033968", SiteId: "-1", + VersionLock: 1, AccountSettings: jamfpro.ComputerPrestageSubsetAccountSettings{ - ID: "-1", + //ID: "-1", PayloadConfigured: jamfpro.TruePtr(), LocalAdminAccountEnabled: jamfpro.TruePtr(), - AdminUsername: "Administrator", - AdminPassword: "Administrator", - HiddenAdminAccount: jamfpro.TruePtr(), - LocalUserManaged: jamfpro.FalsePtr(), - UserAccountType: "ADMINISTRATOR", + AdminUsername: "admin", + AdminPassword: "password", + HiddenAdminAccount: jamfpro.FalsePtr(), + LocalUserManaged: jamfpro.TruePtr(), + UserAccountType: "STANDARD", + VersionLock: 1, PrefillPrimaryAccountInfoFeatureEnabled: jamfpro.TruePtr(), PrefillType: "DEVICE_OWNER", + PrefillAccountFullName: "TestUser FullName", + PrefillAccountUserName: "UserName", PreventPrefillInfoFromModification: jamfpro.FalsePtr(), }, + RecoveryLockPassword: "password123", } // Marshal the prestage struct to JSON and print it diff --git a/sdk/jamfpro/jamfproapi_computer_prestages.go b/sdk/jamfpro/jamfproapi_computer_prestages.go index d79f509a..1b344bb1 100644 --- a/sdk/jamfpro/jamfproapi_computer_prestages.go +++ b/sdk/jamfpro/jamfproapi_computer_prestages.go @@ -46,42 +46,62 @@ type ResponseComputerPrestageCreate struct { // Resource type ResourceComputerPrestage struct { - ID string `json:"id"` - DisplayName string `json:"displayName"` - Mandatory *bool `json:"mandatory"` - MDMRemovable *bool `json:"mdmRemovable"` - SupportPhoneNumber string `json:"supportPhoneNumber,omitempty"` - SupportEmailAddress string `json:"supportEmailAddress,omitempty"` - Department string `json:"department,omitempty"` - DefaultPrestage *bool `json:"defaultPrestage"` - EnrollmentSiteId string `json:"enrollmentSiteId,omitempty"` - KeepExistingSiteMembership *bool `json:"keepExistingSiteMembership"` - KeepExistingLocationInformation *bool `json:"keepExistingLocationInformation"` - RequireAuthentication *bool `json:"requireAuthentication"` - AuthenticationPrompt string `json:"authenticationPrompt,omitempty"` - PreventActivationLock *bool `json:"preventActivationLock"` - EnableDeviceBasedActivationLock *bool `json:"enableDeviceBasedActivationLock"` - DeviceEnrollmentProgramInstanceId string `json:"deviceEnrollmentProgramInstanceId,omitempty"` - SkipSetupItems ComputerPrestageSubsetSkipSetupItems `json:"skipSetupItems"` - LocationInformation ComputerPrestageSubsetLocationInformation `json:"locationInformation"` - PurchasingInformation ComputerPrestageSubsetPurchasingInformation `json:"purchasingInformation"` - AnchorCertificates []string `json:"anchorCertificates,omitempty"` - EnrollmentCustomizationId string `json:"enrollmentCustomizationId,omitempty"` - Language string `json:"language,omitempty"` - Region string `json:"region,omitempty"` - AutoAdvanceSetup *bool `json:"autoAdvanceSetup"` - InstallProfilesDuringSetup *bool `json:"installProfilesDuringSetup"` - PrestageInstalledProfileIds []string `json:"prestageInstalledProfileIds,omitempty"` - CustomPackageIds []string `json:"customPackageIds,omitempty"` - CustomPackageDistributionPointId string `json:"customPackageDistributionPointId,omitempty"` - EnableRecoveryLock *bool `json:"enableRecoveryLock"` - RecoveryLockPasswordType string `json:"recoveryLockPasswordType,omitempty"` - RecoveryLockPassword string `json:"recoveryLockPassword,omitempty"` - RotateRecoveryLockPassword *bool `json:"rotateRecoveryLockPassword"` - ProfileUuid string `json:"profileUuid,omitempty"` - SiteId string `json:"siteId,omitempty"` - VersionLock int `json:"versionLock,omitempty"` - AccountSettings ComputerPrestageSubsetAccountSettings `json:"accountSettings"` + ID string `json:"id"` + DisplayName string `json:"displayName"` + Mandatory *bool `json:"mandatory"` + MDMRemovable *bool `json:"mdmRemovable"` + SupportPhoneNumber string `json:"supportPhoneNumber"` + SupportEmailAddress string `json:"supportEmailAddress"` + Department string `json:"department"` + DefaultPrestage *bool `json:"defaultPrestage"` + EnrollmentSiteId string `json:"enrollmentSiteId"` + KeepExistingSiteMembership *bool `json:"keepExistingSiteMembership"` + KeepExistingLocationInformation *bool `json:"keepExistingLocationInformation"` + RequireAuthentication *bool `json:"requireAuthentication"` + AuthenticationPrompt string `json:"authenticationPrompt"` + PreventActivationLock *bool `json:"preventActivationLock"` + EnableDeviceBasedActivationLock *bool `json:"enableDeviceBasedActivationLock"` + DeviceEnrollmentProgramInstanceId string `json:"deviceEnrollmentProgramInstanceId"` + SkipSetupItems ComputerPrestageSubsetSkipSetupItems `json:"skipSetupItems,omitempty"` + LocationInformation ComputerPrestageSubsetLocationInformation `json:"locationInformation"` + PurchasingInformation ComputerPrestageSubsetPurchasingInformation `json:"purchasingInformation"` + AnchorCertificates []string `json:"anchorCertificates,omitempty"` + EnrollmentCustomizationId string `json:"enrollmentCustomizationId,omitempty"` + Language string `json:"language,omitempty"` + Region string `json:"region,omitempty"` + AutoAdvanceSetup *bool `json:"autoAdvanceSetup"` + InstallProfilesDuringSetup *bool `json:"installProfilesDuringSetup"` + PrestageInstalledProfileIds []string `json:"prestageInstalledProfileIds"` + CustomPackageIds []string `json:"customPackageIds"` + CustomPackageDistributionPointId string `json:"customPackageDistributionPointId"` + EnableRecoveryLock *bool `json:"enableRecoveryLock"` + RecoveryLockPasswordType string `json:"recoveryLockPasswordType,omitempty"` + RecoveryLockPassword string `json:"recoveryLockPassword,omitempty"` + RotateRecoveryLockPassword *bool `json:"rotateRecoveryLockPassword"` + ProfileUuid string `json:"profileUuid,omitempty"` + SiteId string `json:"siteId,omitempty"` + VersionLock int `json:"versionLock,omitempty"` + AccountSettings ComputerPrestageSubsetAccountSettings `json:"accountSettings,omitempty"` + Enabled *bool `json:"enabled"` + SsoForEnrollmentEnabled *bool `json:"ssoForEnrollmentEnabled"` + SsoBypassAllowed *bool `json:"ssoBypassAllowed"` + SsoEnabled *bool `json:"ssoEnabled"` + SsoForMacOsSelfServiceEnabled *bool `json:"ssoForMacOsSelfServiceEnabled"` + TokenExpirationDisabled *bool `json:"tokenExpirationDisabled"` + UserAttributeEnabled *bool `json:"userAttributeEnabled"` + UserAttributeName string `json:"userAttributeName"` + UserMapping string `json:"userMapping"` + EnrollmentSsoForAccountDrivenEnrollmentEnabled *bool `json:"enrollmentSsoForAccountDrivenEnrollmentEnabled"` + GroupEnrollmentAccessEnabled *bool `json:"groupEnrollmentAccessEnabled"` + GroupAttributeName string `json:"groupAttributeName"` + GroupRdnKey string `json:"groupRdnKey"` + GroupEnrollmentAccessName string `json:"groupEnrollmentAccessName"` + IdpProviderType string `json:"idpProviderType"` + OtherProviderTypeName string `json:"otherProviderTypeName"` + MetadataSource string `json:"metadataSource"` + SessionTimeout int `json:"sessionTimeout"` + DeviceType string `json:"deviceType"` + OnboardingItems []OnboardingItem `json:"onboardingItems"` } // Subsets & Containers @@ -114,14 +134,14 @@ type ComputerPrestageSubsetLocationInformation struct { Email string `json:"email"` Room string `json:"room"` Position string `json:"position"` - DepartmentId string `json:"departmentId,omitempty"` - BuildingId string `json:"buildingId,omitempty"` + DepartmentId string `json:"departmentId"` + BuildingId string `json:"buildingId"` ID string `json:"id,omitempty"` VersionLock int `json:"versionLock"` } type ComputerPrestageSubsetPurchasingInformation struct { - ID string `json:"id,omitempty"` + ID string `json:"id"` Leased *bool `json:"leased"` Purchased *bool `json:"purchased"` AppleCareId string `json:"appleCareId"` @@ -131,9 +151,9 @@ type ComputerPrestageSubsetPurchasingInformation struct { LifeExpectancy int `json:"lifeExpectancy"` PurchasingAccount string `json:"purchasingAccount"` PurchasingContact string `json:"purchasingContact"` - LeaseDate string `json:"leaseDate,omitempty"` - PODate string `json:"poDate,omitempty"` - WarrantyDate string `json:"warrantyDate,omitempty"` + LeaseDate string `json:"leaseDate"` + PODate string `json:"poDate"` + WarrantyDate string `json:"warrantyDate"` VersionLock int `json:"versionLock"` } @@ -154,6 +174,13 @@ type ComputerPrestageSubsetAccountSettings struct { PreventPrefillInfoFromModification *bool `json:"preventPrefillInfoFromModification"` } +type OnboardingItem struct { + SelfServiceEntityType string `json:"selfServiceEntityType"` + ID string `json:"id"` + EntityId string `json:"entityId"` + Priority int `json:"priority"` +} + // CRUD // GetComputerPrestagesV3 retrieves all computer prestage information with optional sorting. From 602a27309f84844eee97e531b3be59ac153c7f0b Mon Sep 17 00:00:00 2001 From: ShocOne <62835948+ShocOne@users.noreply.github.com> Date: Thu, 15 Aug 2024 13:25:37 +0100 Subject: [PATCH 3/5] Refactor computer prestage creation to use bool pointers for optional fields --- .../CreateComputerPrestageMinimumConfig.go | 114 ++++++++++-------- sdk/jamfpro/jamfproapi_computer_prestages.go | 40 +++--- 2 files changed, 83 insertions(+), 71 deletions(-) diff --git a/examples/computer_prestages/CreateComputerPrestageMinimumConfig/CreateComputerPrestageMinimumConfig.go b/examples/computer_prestages/CreateComputerPrestageMinimumConfig/CreateComputerPrestageMinimumConfig.go index a6b5228e..7bdcd7f2 100644 --- a/examples/computer_prestages/CreateComputerPrestageMinimumConfig/CreateComputerPrestageMinimumConfig.go +++ b/examples/computer_prestages/CreateComputerPrestageMinimumConfig/CreateComputerPrestageMinimumConfig.go @@ -20,57 +20,72 @@ func main() { // Define the payload for creating a new computer prestage prestage := jamfpro.ResourceComputerPrestage{ - DisplayName: "Example Mobile Prestage Name", - Mandatory: jamfpro.FalsePtr(), + //ID: "-1", + DisplayName: "jamfpro-sdk-example-computerPrestageMinimum-config", + Mandatory: jamfpro.TruePtr(), MDMRemovable: jamfpro.TruePtr(), - SupportPhoneNumber: "5555555555", - SupportEmailAddress: "example@example.com", - Department: "Oxbow", + SupportPhoneNumber: "111-222-3333", + SupportEmailAddress: "email@company.com", + Department: "department name", DefaultPrestage: jamfpro.FalsePtr(), EnrollmentSiteId: "-1", - KeepExistingSiteMembership: jamfpro.TruePtr(), - KeepExistingLocationInformation: jamfpro.TruePtr(), - RequireAuthentication: jamfpro.TruePtr(), - AuthenticationPrompt: "LDAP authentication prompt", - PreventActivationLock: jamfpro.TruePtr(), - EnableDeviceBasedActivationLock: jamfpro.TruePtr(), + KeepExistingSiteMembership: jamfpro.FalsePtr(), + KeepExistingLocationInformation: jamfpro.FalsePtr(), + RequireAuthentication: jamfpro.FalsePtr(), + AuthenticationPrompt: "hello welcome to your enterprise managed macOS device", + PreventActivationLock: jamfpro.FalsePtr(), + EnableDeviceBasedActivationLock: jamfpro.FalsePtr(), DeviceEnrollmentProgramInstanceId: "1", SkipSetupItems: jamfpro.ComputerPrestageSubsetSkipSetupItems{ - Location: jamfpro.TruePtr(), - Privacy: 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(), }, LocationInformation: jamfpro.ComputerPrestageSubsetLocationInformation{ - Username: "name", - Realname: "realName", - Phone: "123-456-7890", - Email: "test@jamf.com", - Room: "room", - Position: "postion", - DepartmentId: "1", - BuildingId: "1", //ID: "-1", - VersionLock: 1, + Username: "", + Realname: "", + Phone: "", + Email: "", + Room: "", + Position: "", + DepartmentId: "-1", + BuildingId: "-1", + VersionLock: 0, }, PurchasingInformation: jamfpro.ComputerPrestageSubsetPurchasingInformation{ //ID: "-1", - Leased: jamfpro.TruePtr(), + Leased: jamfpro.FalsePtr(), Purchased: jamfpro.TruePtr(), - AppleCareId: "abcd", - PONumber: "53-1", - Vendor: "Example Vendor", - PurchasePrice: "$500", - LifeExpectancy: 5, - PurchasingAccount: "admin", - PurchasingContact: "true", - LeaseDate: "2019-01-01", - PODate: "2019-01-01", - WarrantyDate: "2019-01-01", - VersionLock: 1, + AppleCareId: "", + PONumber: "", + Vendor: "", + PurchasePrice: "", + LifeExpectancy: 0, + PurchasingAccount: "", + PurchasingContact: "", + LeaseDate: "1970-01-01", + PODate: "1970-01-01", + WarrantyDate: "1970-01-01", + VersionLock: 0, }, EnrollmentCustomizationId: "0", - Language: "en", - Region: "US", - AutoAdvanceSetup: jamfpro.TruePtr(), + AutoAdvanceSetup: jamfpro.FalsePtr(), InstallProfilesDuringSetup: jamfpro.TruePtr(), PrestageInstalledProfileIds: []string{ "3847", @@ -79,29 +94,26 @@ func main() { }, CustomPackageIds: []string{}, CustomPackageDistributionPointId: "-1", - EnableRecoveryLock: jamfpro.TruePtr(), + EnableRecoveryLock: jamfpro.FalsePtr(), RecoveryLockPasswordType: "MANUAL", - RotateRecoveryLockPassword: jamfpro.TruePtr(), + RotateRecoveryLockPassword: jamfpro.FalsePtr(), ProfileUuid: "0386E7C8D455A040106850A8A2033968", SiteId: "-1", - VersionLock: 1, + VersionLock: 0, AccountSettings: jamfpro.ComputerPrestageSubsetAccountSettings{ //ID: "-1", PayloadConfigured: jamfpro.TruePtr(), - LocalAdminAccountEnabled: jamfpro.TruePtr(), - AdminUsername: "admin", - AdminPassword: "password", + LocalAdminAccountEnabled: jamfpro.FalsePtr(), + AdminUsername: "", + AdminPassword: "", HiddenAdminAccount: jamfpro.FalsePtr(), - LocalUserManaged: jamfpro.TruePtr(), - UserAccountType: "STANDARD", - VersionLock: 1, - PrefillPrimaryAccountInfoFeatureEnabled: jamfpro.TruePtr(), - PrefillType: "DEVICE_OWNER", - PrefillAccountFullName: "TestUser FullName", - PrefillAccountUserName: "UserName", + LocalUserManaged: jamfpro.FalsePtr(), + UserAccountType: "ADMINISTRATOR", + VersionLock: 0, + PrefillPrimaryAccountInfoFeatureEnabled: jamfpro.FalsePtr(), + PrefillType: "UNKNOWN", PreventPrefillInfoFromModification: jamfpro.FalsePtr(), }, - RecoveryLockPassword: "password123", } // Marshal the prestage struct to JSON and print it diff --git a/sdk/jamfpro/jamfproapi_computer_prestages.go b/sdk/jamfpro/jamfproapi_computer_prestages.go index 1b344bb1..8dbc9e37 100644 --- a/sdk/jamfpro/jamfproapi_computer_prestages.go +++ b/sdk/jamfpro/jamfproapi_computer_prestages.go @@ -82,26 +82,26 @@ type ResourceComputerPrestage struct { SiteId string `json:"siteId,omitempty"` VersionLock int `json:"versionLock,omitempty"` AccountSettings ComputerPrestageSubsetAccountSettings `json:"accountSettings,omitempty"` - Enabled *bool `json:"enabled"` - SsoForEnrollmentEnabled *bool `json:"ssoForEnrollmentEnabled"` - SsoBypassAllowed *bool `json:"ssoBypassAllowed"` - SsoEnabled *bool `json:"ssoEnabled"` - SsoForMacOsSelfServiceEnabled *bool `json:"ssoForMacOsSelfServiceEnabled"` - TokenExpirationDisabled *bool `json:"tokenExpirationDisabled"` - UserAttributeEnabled *bool `json:"userAttributeEnabled"` - UserAttributeName string `json:"userAttributeName"` - UserMapping string `json:"userMapping"` - EnrollmentSsoForAccountDrivenEnrollmentEnabled *bool `json:"enrollmentSsoForAccountDrivenEnrollmentEnabled"` - GroupEnrollmentAccessEnabled *bool `json:"groupEnrollmentAccessEnabled"` - GroupAttributeName string `json:"groupAttributeName"` - GroupRdnKey string `json:"groupRdnKey"` - GroupEnrollmentAccessName string `json:"groupEnrollmentAccessName"` - IdpProviderType string `json:"idpProviderType"` - OtherProviderTypeName string `json:"otherProviderTypeName"` - MetadataSource string `json:"metadataSource"` - SessionTimeout int `json:"sessionTimeout"` - DeviceType string `json:"deviceType"` - OnboardingItems []OnboardingItem `json:"onboardingItems"` + Enabled *bool `json:"enabled,omitempty"` + SsoForEnrollmentEnabled *bool `json:"ssoForEnrollmentEnabled,omitempty"` + SsoBypassAllowed *bool `json:"ssoBypassAllowed,omitempty"` + SsoEnabled *bool `json:"ssoEnabled,omitempty"` + SsoForMacOsSelfServiceEnabled *bool `json:"ssoForMacOsSelfServiceEnabled,omitempty"` + TokenExpirationDisabled *bool `json:"tokenExpirationDisabled,omitempty"` + UserAttributeEnabled *bool `json:"userAttributeEnabled,omitempty"` + UserAttributeName string `json:"userAttributeName,omitempty"` + UserMapping string `json:"userMapping,omitempty"` + EnrollmentSsoForAccountDrivenEnrollmentEnabled *bool `json:"enrollmentSsoForAccountDrivenEnrollmentEnabled,omitempty"` + GroupEnrollmentAccessEnabled *bool `json:"groupEnrollmentAccessEnabled,omitempty"` + GroupAttributeName string `json:"groupAttributeName,omitempty"` + GroupRdnKey string `json:"groupRdnKey,omitempty"` + GroupEnrollmentAccessName string `json:"groupEnrollmentAccessName,omitempty"` + IdpProviderType string `json:"idpProviderType,omitempty"` + OtherProviderTypeName string `json:"otherProviderTypeName,omitempty"` + MetadataSource string `json:"metadataSource,omitempty"` + SessionTimeout int `json:"sessionTimeout,omitempty"` + DeviceType string `json:"deviceType,omitempty"` + OnboardingItems []OnboardingItem `json:"onboardingItems,omitempty"` } // Subsets & Containers From 56c9a7b99fd047912d852d7cad2a3bf76597a857 Mon Sep 17 00:00:00 2001 From: ShocOne <62835948+ShocOne@users.noreply.github.com> Date: Thu, 15 Aug 2024 13:56:19 +0100 Subject: [PATCH 4/5] chore: Update Jamf Pro API return-to-service structs and methods --- .../CreateReturnToServiceConfiguration.go | 59 +++++++++++++++++++ sdk/jamfpro/jamfproapi_return_to_service.go | 6 +- 2 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 examples/return_to_service/CreateReturnToServiceConfiguration/CreateReturnToServiceConfiguration.go diff --git a/examples/return_to_service/CreateReturnToServiceConfiguration/CreateReturnToServiceConfiguration.go b/examples/return_to_service/CreateReturnToServiceConfiguration/CreateReturnToServiceConfiguration.go new file mode 100644 index 00000000..a7e61330 --- /dev/null +++ b/examples/return_to_service/CreateReturnToServiceConfiguration/CreateReturnToServiceConfiguration.go @@ -0,0 +1,59 @@ +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) + } + + // Create the Return to Service configuration + config := jamfpro.ResourceReturnToServiceConfiguration{ + DisplayName: "thing", + SsoForEnrollmentEnabled: false, + SsoBypassAllowed: false, + SsoEnabled: false, + SsoForMacOsSelfServiceEnabled: false, + TokenExpirationDisabled: false, + UserAttributeEnabled: false, + UserAttributeName: " ", + UserMapping: "USERNAME", + EnrollmentSsoForAccountDrivenEnrollmentEnabled: false, + GroupEnrollmentAccessEnabled: false, + GroupAttributeName: "http://schemas.xmlsoap.org/claims/Group", + GroupRdnKey: " ", + GroupEnrollmentAccessName: " ", + IdpProviderType: "ADFS", + OtherProviderTypeName: " ", + MetadataSource: "URL", + SessionTimeout: 480, + Title: "Quantity", + Description: "How many of these would you like?", + Priority: 1, + WifiProfileID: "3800", + } + + // Call CreateReturnToServiceConfiguration function + createdConfig, err := client.CreateReturnToServiceConfiguration(config) + if err != nil { + log.Fatalf("Error creating Return to Service configuration: %v", err) + } + + // Pretty print the created configuration in JSON + response, err := json.MarshalIndent(createdConfig, "", " ") // Indent with 4 spaces + if err != nil { + log.Fatalf("Error marshaling created configuration data: %v", err) + } + fmt.Println("Created Return to Service configuration:\n", string(response)) +} diff --git a/sdk/jamfpro/jamfproapi_return_to_service.go b/sdk/jamfpro/jamfproapi_return_to_service.go index 3ae9b6fe..81800904 100644 --- a/sdk/jamfpro/jamfproapi_return_to_service.go +++ b/sdk/jamfpro/jamfproapi_return_to_service.go @@ -54,8 +54,10 @@ type ResourceReturnToServiceConfiguration struct { OtherProviderTypeName string `json:"otherProviderTypeName"` MetadataSource string `json:"metadataSource"` SessionTimeout int `json:"sessionTimeout"` - DeviceType string `json:"deviceType"` - Enabled bool `json:"enabled"` + Title string `json:"title"` + Description string `json:"description"` + Priority int `json:"priority"` + WifiProfileID string `json:"wifiProfileId"` } // GetReturnToServiceConfigurations fetches a list of devices that are in the Return to Service state. From addd85cac23fad7035e8ab7534dbb1e9fad318bb Mon Sep 17 00:00:00 2001 From: ShocOne <62835948+ShocOne@users.noreply.github.com> Date: Tue, 20 Aug 2024 08:55:08 +0100 Subject: [PATCH 5/5] chore: Export all assigned privileges by API integration --- ..._Assigned_Privileges_By_Api_Integration.go | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 recipes/privileges/Export_All_Assigned_Privileges_By_Api_Integration/Export_All_Assigned_Privileges_By_Api_Integration.go diff --git a/recipes/privileges/Export_All_Assigned_Privileges_By_Api_Integration/Export_All_Assigned_Privileges_By_Api_Integration.go b/recipes/privileges/Export_All_Assigned_Privileges_By_Api_Integration/Export_All_Assigned_Privileges_By_Api_Integration.go new file mode 100644 index 00000000..4142b549 --- /dev/null +++ b/recipes/privileges/Export_All_Assigned_Privileges_By_Api_Integration/Export_All_Assigned_Privileges_By_Api_Integration.go @@ -0,0 +1,101 @@ +package main + +import ( + "encoding/csv" + "fmt" + "log" + "os" + "path/filepath" + "strings" + + "github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro" +) + +func main() { + 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) + } + + // Fetch all API integrations + integrations, err := client.GetApiIntegrations("") + if err != nil { + log.Fatalf("Error fetching API integrations: %v", err) + } + + // Create a folder for the CSV file + folderPath := "jamf_pro_exports" + err = os.MkdirAll(folderPath, 0755) + if err != nil { + log.Fatalf("Error creating folder: %v", err) + } + + // Create a CSV file in the new folder + filePath := filepath.Join(folderPath, "api_integrations_export.csv") + file, err := os.Create(filePath) + if err != nil { + log.Fatalf("Error creating CSV file: %v", err) + } + defer file.Close() + + writer := csv.NewWriter(file) + defer writer.Flush() + + // Write CSV header + header := []string{"Integration ID", "Display Name", "Enabled", "Access Token Lifetime", "App Type", "Client ID", "Authorization Scopes", "API Privileges"} + if err := writer.Write(header); err != nil { + log.Fatalf("Error writing CSV header: %v", err) + } + + // Process each integration + for _, integration := range integrations.Results { + // Fetch API roles for this integration + roles, err := client.GetJamfAPIRoles("") + if err != nil { + log.Printf("Error fetching API roles for integration %d: %v", integration.ID, err) + continue + } + + // Collect all privileges for this integration + var privileges []string + for _, role := range roles.Results { + privileges = append(privileges, role.Privileges...) + } + + // Remove duplicates from privileges + uniquePrivileges := removeDuplicates(privileges) + + // Create CSV record + record := []string{ + fmt.Sprintf("%d", integration.ID), + integration.DisplayName, + fmt.Sprintf("%t", integration.Enabled), + fmt.Sprintf("%d", integration.AccessTokenLifetimeSeconds), + integration.AppType, + integration.ClientID, + strings.Join(integration.AuthorizationScopes, ", "), + strings.Join(uniquePrivileges, ", "), + } + + if err := writer.Write(record); err != nil { + log.Printf("Error writing record for integration %d: %v", integration.ID, err) + } + } + + fmt.Printf("Export completed successfully. File saved as %s\n", filePath) +} + +func removeDuplicates(slice []string) []string { + keys := make(map[string]bool) + list := []string{} + for _, entry := range slice { + if _, value := keys[entry]; !value { + keys[entry] = true + list = append(list, entry) + } + } + return list +}