Skip to content

Commit

Permalink
chore: Refactor policy structs to use pointers for SelfService and Ac…
Browse files Browse the repository at this point in the history
…countMaintenance
  • Loading branch information
ShocOne committed May 26, 2024
1 parent 8096b64 commit 0513d68
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 36 deletions.
55 changes: 38 additions & 17 deletions examples/policies/UpdatePolicyByID/UpdatePolicyByID.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,44 @@ func main() {
General: jamfpro.PolicySubsetGeneral{
Name: "disk-encryption-sdk",
Enabled: false,
Trigger: "EVENT",
TriggerCheckin: false,
TriggerEnrollmentComplete: false,
TriggerLogin: false,
TriggerLogout: false,
TriggerNetworkStateChanged: false,
TriggerStartup: false,
TriggerOther: "EVENT",
Frequency: "Once per computer",
RetryEvent: "none",
RetryAttempts: -1,
NotifyOnEachFailedRetry: false,
LocationUserOnly: false,
TargetDrive: "/",
Offline: false,
Category: &jamfpro.SharedResourceCategory{
ID: -1,
Name: "No category assigned",
},
DateTimeLimitations: &jamfpro.PolicySubsetGeneralDateTimeLimitations{
ActivationDate: "",
ActivationDateEpoch: 0,
ActivationDateUTC: "",
ExpirationDate: "",
ExpirationDateEpoch: 0,
ExpirationDateUTC: "",
NoExecuteStart: "",
NoExecuteEnd: "",
},
NetworkLimitations: &jamfpro.PolicySubsetGeneralNetworkLimitations{
MinimumNetworkConnection: "No Minimum",
AnyIPAddress: true,
NetworkSegments: "",
},
NetworkRequirements: "Any",
Site: &jamfpro.SharedResourceSite{
ID: -1,
Name: "None",
},
},
SelfService: &jamfpro.PolicySubsetSelfService{
UseForSelfService: false,
Expand All @@ -47,30 +71,28 @@ func main() {
ForceUsersToViewDescription: false,
//SelfServiceIcon: jamfpro.PolicySelfServiceIcon{ID: -1, Filename: "", URI: ""},
FeatureOnMainPage: false,
SelfServiceCategories: []jamfpro.PolicySubsetSelfServiceCategory{
SelfServiceCategories: &[]jamfpro.PolicySubsetSelfServiceCategory{
{
Category: jamfpro.PolicyCategory{
//ID: "-1",
//Name: "None",
DisplayIn: false, // or true, depending on your requirements
FeatureIn: false, // or true, depending on your requirements
},
ID: -1,
Name: "None",
DisplayIn: false, // or true, depending on your requirements
FeatureIn: false, // or true, depending on your requirements
},
},
},
AccountMaintenance: jamfpro.PolicySubsetAccountMaintenance{
ManagementAccount: jamfpro.PolicySubsetAccountMaintenanceManagementAccount{
AccountMaintenance: &jamfpro.PolicySubsetAccountMaintenance{
ManagementAccount: &jamfpro.PolicySubsetAccountMaintenanceManagementAccount{
Action: "rotate",
ManagedPassword: "",
ManagedPasswordLength: 0,
},
OpenFirmwareEfiPassword: jamfpro.PolicySubsetAccountMaintenanceOpenFirmwareEfiPassword{
OpenFirmwareEfiPassword: &jamfpro.PolicySubsetAccountMaintenanceOpenFirmwareEfiPassword{
OfMode: "none",
OfPassword: "",
OfPasswordSHA256: "",
},
},
Maintenance: jamfpro.PolicySubsetMaintenance{
Maintenance: &jamfpro.PolicySubsetMaintenance{
Recon: false,
ResetName: false,
InstallAllCachedPackages: false,
Expand All @@ -82,29 +104,29 @@ func main() {
UserCache: false,
Verify: false,
},
FilesProcesses: jamfpro.PolicySubsetFilesProcesses{
FilesProcesses: &jamfpro.PolicySubsetFilesProcesses{
DeleteFile: false,
UpdateLocateDatabase: false,
SpotlightSearch: "",
SearchForProcess: "",
KillProcess: false,
RunCommand: "",
},
UserInteraction: jamfpro.PolicySubsetUserInteraction{
UserInteraction: &jamfpro.PolicySubsetUserInteraction{
MessageStart: "",
AllowUserToDefer: false,
AllowDeferralUntilUtc: "",
AllowDeferralMinutes: 0,
MessageFinish: "",
},
DiskEncryption: jamfpro.PolicySubsetDiskEncryption{
DiskEncryption: &jamfpro.PolicySubsetDiskEncryption{
Action: "apply",
DiskEncryptionConfigurationID: 1,
AuthRestart: true,
//RemediateKeyType: "",
//RemediateDiskEncryptionConfigurationID: 0,
},
Reboot: jamfpro.PolicySubsetReboot{
Reboot: &jamfpro.PolicySubsetReboot{
Message: "This computer will restart in 5 minutes. Please save anything you are working on and log out by choosing Log Out from the bottom of the Apple menu.",
StartupDisk: "Current Startup Disk",
SpecifyStartup: "",
Expand Down Expand Up @@ -132,5 +154,4 @@ func main() {

// Print the ID of the updated policy
fmt.Printf("Updated Policy ID: %d\n", response.ID)

}
59 changes: 40 additions & 19 deletions examples/policies/UpdatePolicyByName/UpdatePolicyByName.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,46 @@ func main() {
General: jamfpro.PolicySubsetGeneral{
Name: "disk-encryption-sdk",
Enabled: false,
Trigger: "EVENT",
TriggerCheckin: false,
TriggerEnrollmentComplete: false,
TriggerLogin: false,
TriggerLogout: false,
TriggerNetworkStateChanged: false,
TriggerStartup: false,
TriggerOther: "EVENT",
Frequency: "Once per computer",
RetryEvent: "none",
RetryAttempts: -1,
NotifyOnEachFailedRetry: false,
LocationUserOnly: false,
TargetDrive: "/",
Offline: false,
Category: &jamfpro.SharedResourceCategory{
ID: -1,
Name: "No category assigned",
},
DateTimeLimitations: &jamfpro.PolicySubsetGeneralDateTimeLimitations{
ActivationDate: "",
ActivationDateEpoch: 0,
ActivationDateUTC: "",
ExpirationDate: "",
ExpirationDateEpoch: 0,
ExpirationDateUTC: "",
NoExecuteStart: "",
NoExecuteEnd: "",
},
NetworkLimitations: &jamfpro.PolicySubsetGeneralNetworkLimitations{
MinimumNetworkConnection: "No Minimum",
AnyIPAddress: true,
NetworkSegments: "",
},
NetworkRequirements: "Any",
Site: &jamfpro.SharedResourceSite{
ID: -1,
Name: "None",
},
},
SelfService: jamfpro.PolicySubsetSelfService{
SelfService: &jamfpro.PolicySubsetSelfService{
UseForSelfService: false,
SelfServiceDisplayName: "",
InstallButtonText: "Install",
Expand All @@ -47,30 +71,28 @@ func main() {
ForceUsersToViewDescription: false,
//SelfServiceIcon: jamfpro.PolicySelfServiceIcon{ID: -1, Filename: "", URI: ""},
FeatureOnMainPage: false,
SelfServiceCategories: []jamfpro.PolicySubsetSelfServiceCategory{
SelfServiceCategories: &[]jamfpro.PolicySubsetSelfServiceCategory{
{
Category: jamfpro.PolicyCategory{
//ID: "-1",
//Name: "None",
DisplayIn: false, // or true, depending on your requirements
FeatureIn: false, // or true, depending on your requirements
},
ID: -1,
Name: "None",
DisplayIn: false, // or true, depending on your requirements
FeatureIn: false, // or true, depending on your requirements
},
},
},
AccountMaintenance: jamfpro.PolicySubsetAccountMaintenance{
ManagementAccount: jamfpro.PolicySubsetAccountMaintenanceManagementAccount{
AccountMaintenance: &jamfpro.PolicySubsetAccountMaintenance{
ManagementAccount: &jamfpro.PolicySubsetAccountMaintenanceManagementAccount{
Action: "rotate",
ManagedPassword: "",
ManagedPasswordLength: 0,
},
OpenFirmwareEfiPassword: jamfpro.PolicySubsetAccountMaintenanceOpenFirmwareEfiPassword{
OpenFirmwareEfiPassword: &jamfpro.PolicySubsetAccountMaintenanceOpenFirmwareEfiPassword{
OfMode: "none",
OfPassword: "",
OfPasswordSHA256: "",
},
},
Maintenance: jamfpro.PolicySubsetMaintenance{
Maintenance: &jamfpro.PolicySubsetMaintenance{
Recon: false,
ResetName: false,
InstallAllCachedPackages: false,
Expand All @@ -82,29 +104,29 @@ func main() {
UserCache: false,
Verify: false,
},
FilesProcesses: jamfpro.PolicySubsetFilesProcesses{
FilesProcesses: &jamfpro.PolicySubsetFilesProcesses{
DeleteFile: false,
UpdateLocateDatabase: false,
SpotlightSearch: "",
SearchForProcess: "",
KillProcess: false,
RunCommand: "",
},
UserInteraction: jamfpro.PolicySubsetUserInteraction{
UserInteraction: &jamfpro.PolicySubsetUserInteraction{
MessageStart: "",
AllowUserToDefer: false,
AllowDeferralUntilUtc: "",
AllowDeferralMinutes: 0,
MessageFinish: "",
},
DiskEncryption: jamfpro.PolicySubsetDiskEncryption{
DiskEncryption: &jamfpro.PolicySubsetDiskEncryption{
Action: "apply",
DiskEncryptionConfigurationID: 1,
AuthRestart: true,
//RemediateKeyType: "",
//RemediateDiskEncryptionConfigurationID: 0,
},
Reboot: jamfpro.PolicySubsetReboot{
Reboot: &jamfpro.PolicySubsetReboot{
Message: "This computer will restart in 5 minutes. Please save anything you are working on and log out by choosing Log Out from the bottom of the Apple menu.",
StartupDisk: "Current Startup Disk",
SpecifyStartup: "",
Expand All @@ -122,7 +144,7 @@ func main() {
}
fmt.Println("Policy Details to be Sent:\n", string(policyXML))

policyName := "policy-creation-test"
policyName := "disk-encryption-sdk"

// Update the policy
response, err := client.UpdatePolicyByName(policyName, updatedPolicy)
Expand All @@ -132,5 +154,4 @@ func main() {

// Print the ID of the updated policy
fmt.Printf("Updated Policy ID: %d\n", response.ID)

}

0 comments on commit 0513d68

Please sign in to comment.