Skip to content

Commit 16497bb

Browse files
authored
Merge pull request #23 from deploymenttheory/dev
Added to SDK Jamf Pro Classic API Policies and examples
2 parents b5df92e + 8ee4302 commit 16497bb

File tree

16 files changed

+1180
-8
lines changed

16 files changed

+1180
-8
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,19 @@ This document tracks the progress of API endpoint coverage tests. As endpoints a
293293
- [ ] ✅ DELETE `/JSSResource/osxconfigurationprofiles/id/{id}` - DeleteMacOSConfigurationProfileByID deletes an existing macOS configuration profile by ID.
294294
- [ ] ✅ DELETE `/JSSResource/osxconfigurationprofiles/name/{name}` - DeleteMacOSConfigurationProfileByName deletes an existing macOS configuration profile by its name.
295295

296+
### Policies - /JSSResource/policies
297+
298+
- [ ] ✅ GET `/JSSResource/policies` - GetPolicies retrieves a list of all policies
299+
- [ ] ✅ GET `/JSSResource/policies/id/{id}` - GetPolicyByID retrieves the details of a policy by its ID
300+
- [ ] ✅ GET `/JSSResource/policies/name/{name}` - GetPolicyByName retrieves a policy by its name
301+
- [ ] ✅ GET `/JSSResource/policies/category/{category}` - GetPolicyByCategory retrieves policies by their category
302+
- [ ] ✅ GET `/JSSResource/policies/createdBy/{createdBy}` - GetPoliciesByType retrieves policies by the type of entity that created them
303+
- [ ] ✅ POST `/JSSResource/policies/id/0` - CreatePolicy creates a new policy
304+
- [ ] ✅ PUT `/JSSResource/policies/id/{id}` - UpdatePolicyByID updates an existing policy by its ID
305+
- [ ] ✅ PUT `/JSSResource/policies/name/{name}` - UpdatePolicyByName updates an existing policy by its name
306+
- [ ] ✅ DELETE `/JSSResource/policies/id/{id}` - DeletePolicyByID deletes a policy by its ID
307+
- [ ] ✅ DELETE `/JSSResource/policies/name/{name}` - DeletePolicyByName deletes a policy by its name
308+
296309
### Scripts - /JSSResource/scripts
297310

298311
- [ ] ✅ GET `/JSSResource/scripts` - GetScripts retrieves all scripts.
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
package main
2+
3+
import (
4+
"encoding/xml"
5+
"fmt"
6+
"log"
7+
8+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
9+
)
10+
11+
func main() {
12+
// Define the path to the JSON configuration file
13+
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
14+
15+
// Load the client OAuth credentials from the configuration file
16+
authConfig, err := jamfpro.LoadClientAuthConfig(configFilePath)
17+
if err != nil {
18+
log.Fatalf("Failed to load client OAuth configuration: %v", err)
19+
}
20+
21+
// Configuration for the jamfpro
22+
config := jamfpro.Config{
23+
InstanceName: authConfig.InstanceName,
24+
DebugMode: true,
25+
Logger: jamfpro.NewDefaultLogger(),
26+
ClientID: authConfig.ClientID,
27+
ClientSecret: authConfig.ClientSecret,
28+
}
29+
30+
// Create a new jamfpro client instance
31+
client, err := jamfpro.NewClient(config)
32+
if err != nil {
33+
log.Fatalf("Failed to create Jamf Pro client: %v", err)
34+
}
35+
36+
// Define a new policy with all required fields
37+
newPolicy := &jamfpro.ResponsePolicy{
38+
General: jamfpro.PolicyGeneral{
39+
Name: "firefox",
40+
Enabled: false,
41+
Trigger: "EVENT",
42+
TriggerCheckin: false,
43+
TriggerEnrollmentComplete: false,
44+
TriggerLogin: false,
45+
TriggerLogout: false,
46+
TriggerNetworkStateChanged: false,
47+
TriggerStartup: false,
48+
Frequency: "Once per computer",
49+
RetryEvent: "none",
50+
RetryAttempts: -1,
51+
NotifyOnEachFailedRetry: false,
52+
LocationUserOnly: false,
53+
TargetDrive: "/",
54+
Offline: false,
55+
},
56+
SelfService: jamfpro.PolicySelfService{
57+
UseForSelfService: false,
58+
SelfServiceDisplayName: "",
59+
InstallButtonText: "Install",
60+
ReinstallButtonText: "",
61+
SelfServiceDescription: "",
62+
ForceUsersToViewDescription: false,
63+
//SelfServiceIcon: jamfpro.Icon{ID: -1, Filename: "", URI: ""},
64+
FeatureOnMainPage: false,
65+
SelfServiceCategories: jamfpro.PolicySelfServiceCategory{
66+
Category: jamfpro.PolicyCategory{
67+
//ID: "-1",
68+
//Name: "None",
69+
DisplayIn: false, // or true, depending on your requirements
70+
FeatureIn: false, // or true, depending on your requirements
71+
},
72+
},
73+
},
74+
AccountMaintenance: jamfpro.PolicyAccountMaintenance{
75+
ManagementAccount: jamfpro.PolicyManagementAccount{
76+
Action: "doNotChange",
77+
ManagedPassword: "",
78+
ManagedPasswordLength: 0,
79+
},
80+
OpenFirmwareEfiPassword: jamfpro.PolicyOpenFirmwareEfiPassword{
81+
OfMode: "none",
82+
OfPassword: "",
83+
OfPasswordSHA256: "",
84+
},
85+
},
86+
Maintenance: jamfpro.PolicyMaintenance{
87+
Recon: false,
88+
ResetName: false,
89+
InstallAllCachedPackages: false,
90+
Heal: false,
91+
Prebindings: false,
92+
Permissions: false,
93+
Byhost: false,
94+
SystemCache: false,
95+
UserCache: false,
96+
Verify: false,
97+
},
98+
FilesProcesses: jamfpro.PolicyFilesProcesses{
99+
DeleteFile: false,
100+
UpdateLocateDatabase: false,
101+
SpotlightSearch: "",
102+
SearchForProcess: "",
103+
KillProcess: false,
104+
RunCommand: "",
105+
},
106+
UserInteraction: jamfpro.PolicyUserInteraction{
107+
MessageStart: "",
108+
AllowUserToDefer: false,
109+
AllowDeferralUntilUtc: "",
110+
AllowDeferralMinutes: 0,
111+
MessageFinish: "",
112+
},
113+
/*DiskEncryption: jamfpro.PolicyDiskEncryption{
114+
Action: "none",
115+
DiskEncryptionConfigurationID: 0,
116+
AuthRestart: false,
117+
//RemediateKeyType: "",
118+
//RemediateDiskEncryptionConfigurationID: 0,
119+
},*/
120+
Reboot: jamfpro.PolicyReboot{
121+
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.",
122+
StartupDisk: "Current Startup Disk",
123+
SpecifyStartup: "",
124+
NoUserLoggedIn: "Do not restart",
125+
UserLoggedIn: "Do not restart",
126+
MinutesUntilReboot: 5,
127+
StartRebootTimerImmediately: false,
128+
FileVault2Reboot: false,
129+
},
130+
}
131+
132+
policyXML, err := xml.MarshalIndent(newPolicy, "", " ")
133+
if err != nil {
134+
log.Fatalf("Error marshaling policy data: %v", err)
135+
}
136+
fmt.Println("Policy Details to be Sent:\n", string(policyXML))
137+
138+
// Call CreatePolicy function
139+
createdPolicy, err := client.CreatePolicyByID(newPolicy)
140+
if err != nil {
141+
log.Fatalf("Error creating policy: %v", err)
142+
}
143+
144+
// Pretty print the created policy details in XML
145+
policyXML, err = xml.MarshalIndent(createdPolicy, "", " ") // Indent with 4 spaces and use '='
146+
if err != nil {
147+
log.Fatalf("Error marshaling policy details data: %v", err)
148+
}
149+
fmt.Println("Created Policy Details:\n", string(policyXML))
150+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
8+
)
9+
10+
func main() {
11+
// Define the path to the JSON configuration file
12+
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
13+
14+
// Load the client OAuth credentials from the configuration file
15+
authConfig, err := jamfpro.LoadClientAuthConfig(configFilePath)
16+
if err != nil {
17+
log.Fatalf("Failed to load client OAuth configuration: %v", err)
18+
}
19+
20+
// Configuration for the jamfpro
21+
config := jamfpro.Config{
22+
InstanceName: authConfig.InstanceName,
23+
DebugMode: true,
24+
Logger: jamfpro.NewDefaultLogger(),
25+
ClientID: authConfig.ClientID,
26+
ClientSecret: authConfig.ClientSecret,
27+
}
28+
29+
// Create a new jamfpro client instance
30+
client, err := jamfpro.NewClient(config)
31+
if err != nil {
32+
log.Fatalf("Failed to create Jamf Pro client: %v", err)
33+
}
34+
35+
// Define the policy ID to be deleted
36+
policyID := 123 // Replace with the actual policy ID
37+
38+
// Delete the policy by ID
39+
err = client.DeletePolicyByID(policyID) // Changed here from := to =
40+
if err != nil {
41+
log.Fatalf("Error deleting policy: %v", err)
42+
}
43+
44+
fmt.Println("Policy deleted successfully.")
45+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
8+
)
9+
10+
func main() {
11+
// Define the path to the JSON configuration file
12+
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
13+
14+
// Load the client OAuth credentials from the configuration file
15+
authConfig, err := jamfpro.LoadClientAuthConfig(configFilePath)
16+
if err != nil {
17+
log.Fatalf("Failed to load client OAuth configuration: %v", err)
18+
}
19+
20+
// Configuration for the jamfpro
21+
config := jamfpro.Config{
22+
InstanceName: authConfig.InstanceName,
23+
DebugMode: true,
24+
Logger: jamfpro.NewDefaultLogger(),
25+
ClientID: authConfig.ClientID,
26+
ClientSecret: authConfig.ClientSecret,
27+
}
28+
29+
// Create a new jamfpro client instance
30+
client, err := jamfpro.NewClient(config)
31+
if err != nil {
32+
log.Fatalf("Failed to create Jamf Pro client: %v", err)
33+
}
34+
35+
// Define the policy name to be deleted
36+
policyName := "PolicyName" // Replace with the actual policy name
37+
38+
// Delete the policy by name
39+
err = client.DeletePolicyByName(policyName) // Changed here from := to =
40+
if err != nil {
41+
log.Fatalf("Error deleting policy: %v", err)
42+
}
43+
44+
fmt.Println("Policy deleted successfully.")
45+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
8+
)
9+
10+
func main() {
11+
// Define the path to the JSON configuration file inside the main function
12+
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
13+
14+
// Load the client OAuth credentials from the configuration file
15+
authConfig, err := jamfpro.LoadClientAuthConfig(configFilePath)
16+
if err != nil {
17+
log.Fatalf("Failed to load client OAuth configuration: %v", err)
18+
}
19+
20+
// Configuration for the jamfpro
21+
config := jamfpro.Config{
22+
InstanceName: authConfig.InstanceName,
23+
DebugMode: true,
24+
Logger: jamfpro.NewDefaultLogger(),
25+
ClientID: authConfig.ClientID,
26+
ClientSecret: authConfig.ClientSecret,
27+
}
28+
29+
// Create a new jamfpro client instanceclient,
30+
client, err := jamfpro.NewClient(config)
31+
if err != nil {
32+
log.Fatalf("Failed to create Jamf Pro client: %v", err)
33+
}
34+
35+
policies, err := client.GetPolicies()
36+
if err != nil {
37+
log.Fatalf("Error fetching policies: %v", err)
38+
}
39+
40+
fmt.Println("Retrieved Policies:")
41+
for _, policy := range policies.Policy {
42+
fmt.Printf("ID: %d, Name: %s\n", policy.ID, policy.Name)
43+
}
44+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package main
2+
3+
import (
4+
"encoding/xml"
5+
"fmt"
6+
"log"
7+
8+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
9+
)
10+
11+
func main() {
12+
// Define the path to the JSON configuration file inside the main function
13+
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
14+
15+
// Load the client OAuth credentials from the configuration file
16+
authConfig, err := jamfpro.LoadClientAuthConfig(configFilePath)
17+
if err != nil {
18+
log.Fatalf("Failed to load client OAuth configuration: %v", err)
19+
}
20+
21+
// Configuration for the jamfpro
22+
config := jamfpro.Config{
23+
InstanceName: authConfig.InstanceName,
24+
DebugMode: true,
25+
Logger: jamfpro.NewDefaultLogger(),
26+
ClientID: authConfig.ClientID,
27+
ClientSecret: authConfig.ClientSecret,
28+
}
29+
30+
// Create a new jamfpro client instance
31+
client, err := jamfpro.NewClient(config)
32+
if err != nil {
33+
log.Fatalf("Failed to create Jamf Pro client: %v", err)
34+
}
35+
36+
// Define the createdBy parameter for testing
37+
createdBy := "jss" // Can be either 'casper' or 'jss'
38+
39+
// Call GetPoliciesByType function
40+
policies, err := client.GetPoliciesByType(createdBy)
41+
if err != nil {
42+
log.Fatalf("Error fetching policies by type: %v", err)
43+
}
44+
45+
// Pretty print the policies details in XML
46+
policiesXML, err := xml.MarshalIndent(policies, "", " ") // Indent with 4 spaces
47+
if err != nil {
48+
log.Fatalf("Error marshaling policies details data: %v", err)
49+
}
50+
fmt.Println("Fetched Policies Details:\n", string(policiesXML))
51+
}

0 commit comments

Comments
 (0)