Skip to content

Commit 608b080

Browse files
authored
Merge pull request #13 from deploymenttheory/dev
Added advanced computer searches - funcs and examples
2 parents 2707d33 + ad1916f commit 608b080

File tree

13 files changed

+756
-203
lines changed

13 files changed

+756
-203
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,18 @@ This document tracks the progress of API endpoint coverage tests. As endpoints a
197197
- [ ] ✅ GET `/JSSResource/activationcode` - GetActivationCode retrieves the current activation code.
198198
- [ ] ✅ PUT `/JSSResource/activationcode` - UpdateActivationCode updates the activation code.
199199

200+
### Jamf Pro Classic API - Advanced Computer Searches
201+
202+
- [ ] ✅ GET `/JSSResource/advancedcomputersearches` - GetAdvancedComputerSearches fetches all advanced computer searches.
203+
- [ ] ✅ GET `/JSSResource/advancedcomputersearches/id/{id}` - GetAdvancedComputerSearchByID fetches an advanced computer search by its ID.
204+
- [ ] ✅ GET `/JSSResource/advancedcomputersearches/name/{name}` - GetAdvancedComputerSearchesByName fetches advanced computer searches by their name.
205+
- [ ] ✅ POST `/JSSResource/advancedcomputersearches` - CreateAdvancedComputerSearch creates a new advanced computer search.
206+
- [ ] ✅ PUT `/JSSResource/advancedcomputersearches/id/{id}` - UpdateAdvancedComputerSearchByID updates an existing advanced computer search by its ID.
207+
- [ ] ✅ PUT `/JSSResource/advancedcomputersearches/name/{name}` - UpdateAdvancedComputerSearchByName updates an advanced computer search by its name.
208+
- [ ] ✅ DELETE `/JSSResource/advancedcomputersearches/id/{id}` - DeleteAdvancedComputerSearchByID deletes an advanced computer search by its ID.
209+
- [ ] ✅ DELETE `/JSSResource/advancedcomputersearches/name/{name}` - DeleteAdvancedComputerSearchByName deletes an advanced computer search by its name.
210+
211+
200212
### Allowed File Extensions - /JSSResource/allowedfileextensions
201213

202214
- [ ] ✅ GET `/JSSResource/allowedfileextensions` - GetAllowedFileExtensions retrieves all allowed file extensions
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
// Define the name of the advanced computer search
12+
const advancedComputerSearchName = "YourSearchName" // Replace with the actual name
13+
14+
func main() {
15+
// Define the path to the JSON configuration file
16+
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
17+
18+
// Load the client OAuth credentials from the configuration file
19+
authConfig, err := jamfpro.LoadClientAuthConfig(configFilePath)
20+
if err != nil {
21+
log.Fatalf("Failed to load client OAuth configuration: %v", err)
22+
}
23+
24+
// Configuration for Jamf Pro
25+
config := jamfpro.Config{
26+
InstanceName: authConfig.InstanceName,
27+
DebugMode: true,
28+
Logger: jamfpro.NewDefaultLogger(),
29+
ClientID: authConfig.ClientID,
30+
ClientSecret: authConfig.ClientSecret,
31+
}
32+
33+
// Create a new Jamf Pro client instance
34+
client, err := jamfpro.NewClient(config)
35+
if err != nil {
36+
log.Fatalf("Failed to create Jamf Pro client: %v", err)
37+
}
38+
39+
// Define the advanced computer search details
40+
newSearch := &jamfpro.ResponseAdvancedComputerSearch{
41+
Name: "Advanced Search Name",
42+
ViewAs: "Standard Web Page",
43+
Criteria: []jamfpro.Criteria{
44+
{
45+
Criterion: jamfpro.CriterionDetail{
46+
Name: "Last Inventory Update",
47+
Priority: 0,
48+
AndOr: "and",
49+
SearchType: "more than x days ago",
50+
Value: "7",
51+
OpeningParen: false,
52+
ClosingParen: false,
53+
},
54+
},
55+
},
56+
DisplayFields: []jamfpro.DisplayField{
57+
{
58+
DisplayField: jamfpro.DisplayFieldDetail{
59+
Name: "IP Address",
60+
},
61+
},
62+
},
63+
Site: jamfpro.SiteDetail{
64+
ID: -1,
65+
Name: "None",
66+
},
67+
}
68+
69+
// Create the advanced computer search
70+
createdSearch, err := client.CreateAdvancedComputerSearch(newSearch)
71+
if err != nil {
72+
fmt.Println("Error creating advanced computer search:", err)
73+
return
74+
}
75+
76+
// Print the created advanced computer search details
77+
createdSearchXML, err := xml.MarshalIndent(createdSearch, "", " ")
78+
if err != nil {
79+
fmt.Println("Error marshaling created search to XML:", err)
80+
return
81+
}
82+
fmt.Printf("Created Advanced Computer Search:\n%s\n", string(createdSearchXML))
83+
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
// main_delete_by_id.go
12
package main
23

34
import (
4-
"encoding/xml"
5-
"fmt"
65
"log"
76

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

10+
const advancedComputerSearchID = 7 // Replace with the actual ID
11+
1112
func main() {
12-
// Define the path to the JSON configuration file inside the main function
13+
// Define the path to the JSON configuration file
1314
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
1415

1516
// Load the client OAuth credentials from the configuration file
@@ -18,7 +19,7 @@ func main() {
1819
log.Fatalf("Failed to load client OAuth configuration: %v", err)
1920
}
2021

21-
// Configuration for the jamfpro
22+
// Configuration for Jamf Pro
2223
config := jamfpro.Config{
2324
InstanceName: authConfig.InstanceName,
2425
DebugMode: true,
@@ -27,22 +28,17 @@ func main() {
2728
ClientSecret: authConfig.ClientSecret,
2829
}
2930

30-
// Create a new jamfpro client instance
31+
// Create a new Jamf Pro client instance
3132
client, err := jamfpro.NewClient(config)
3233
if err != nil {
3334
log.Fatalf("Failed to create Jamf Pro client: %v", err)
3435
}
3536

36-
// Call GetComputerPrestages function
37-
prestages, err := client.GetComputerPrestages()
37+
// Delete the advanced computer search by ID
38+
err = client.DeleteAdvancedComputerSearchByID(advancedComputerSearchID)
3839
if err != nil {
39-
log.Fatalf("Error fetching Computer Prestages: %v", err)
40+
log.Fatalf("Error deleting advanced computer search by ID: %v", err)
4041
}
4142

42-
// Pretty print the prestages in XML
43-
prestagesXML, err := xml.MarshalIndent(prestages, "", " ") // Indent with 4 spaces
44-
if err != nil {
45-
log.Fatalf("Error marshaling Computer Prestages data: %v", err)
46-
}
47-
fmt.Println("Fetched Computer Prestages:\n", string(prestagesXML))
43+
log.Println("Advanced computer search deleted successfully.")
4844
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// main_delete_by_name.go
2+
package main
3+
4+
import (
5+
"log"
6+
7+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
8+
)
9+
10+
const advancedComputerSearchName = "SearchName" // Replace with the actual name
11+
12+
func main() {
13+
// Define the path to the JSON configuration file
14+
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
15+
16+
// Load the client OAuth credentials from the configuration file
17+
authConfig, err := jamfpro.LoadClientAuthConfig(configFilePath)
18+
if err != nil {
19+
log.Fatalf("Failed to load client OAuth configuration: %v", err)
20+
}
21+
22+
// Configuration for Jamf Pro
23+
config := jamfpro.Config{
24+
InstanceName: authConfig.InstanceName,
25+
DebugMode: true,
26+
Logger: jamfpro.NewDefaultLogger(),
27+
ClientID: authConfig.ClientID,
28+
ClientSecret: authConfig.ClientSecret,
29+
}
30+
31+
// Create a new Jamf Pro client instance
32+
client, err := jamfpro.NewClient(config)
33+
if err != nil {
34+
log.Fatalf("Failed to create Jamf Pro client: %v", err)
35+
}
36+
37+
// Delete the advanced computer search by name
38+
err = client.DeleteAdvancedComputerSearchByName(advancedComputerSearchName)
39+
if err != nil {
40+
log.Fatalf("Error deleting advanced computer search by name: %v", err)
41+
}
42+
43+
log.Println("Advanced computer search deleted successfully by name.")
44+
}
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
package main
22

33
import (
4-
"encoding/json"
4+
"encoding/xml"
55
"fmt"
66
"log"
77

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

11-
const (
12-
prestageName = "pse-ade_lbgstaging_Jamf_Connect_New_Config-1.1-0000" // Replace with the actual prestage name you want to fetch
13-
)
11+
// Define the ID of the advanced computer search
12+
const advancedComputerSearchID = 123 // Replace 123 with the actual ID
1413

1514
func main() {
16-
// Define the path to the JSON configuration file inside the main function
15+
// Define the path to the JSON configuration file
1716
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
1817

1918
// Load the client OAuth credentials from the configuration file
@@ -22,7 +21,7 @@ func main() {
2221
log.Fatalf("Failed to load client OAuth configuration: %v", err)
2322
}
2423

25-
// Configuration for the jamfpro
24+
// Configuration for Jamf Pro
2625
config := jamfpro.Config{
2726
InstanceName: authConfig.InstanceName,
2827
DebugMode: true,
@@ -31,22 +30,22 @@ func main() {
3130
ClientSecret: authConfig.ClientSecret,
3231
}
3332

34-
// Create a new jamfpro client instance,
33+
// Create a new Jamf Pro client instance
3534
client, err := jamfpro.NewClient(config)
3635
if err != nil {
3736
log.Fatalf("Failed to create Jamf Pro client: %v", err)
3837
}
3938

40-
// Call GetComputerPrestageByNameByID function
41-
prestage, err := client.GetComputerPrestageByNameByID(prestageName)
39+
// Call GetAdvancedComputerSearchByID function using the constant ID
40+
advancedComputerSearch, err := client.GetAdvancedComputerSearchByID(advancedComputerSearchID)
4241
if err != nil {
43-
log.Fatalf("Error fetching Jamf computer prestage by name: %v", err)
42+
log.Fatalf("Error fetching advanced computer search by ID: %v", err)
4443
}
4544

46-
// Pretty print the prestage in JSON
47-
prestageJSON, err := json.MarshalIndent(prestage, "", " ") // Indent with 4 spaces
45+
// Pretty print the advanced computer search in XML
46+
advancedComputerSearchXML, err := xml.MarshalIndent(advancedComputerSearch, "", " ") // Indent with 4 spaces
4847
if err != nil {
49-
log.Fatalf("Error marshaling Jamf computer prestage data: %v", err)
48+
log.Fatalf("Error marshaling advanced computer search data: %v", err)
5049
}
51-
fmt.Println("Fetched Jamf computer prestage:\n", string(prestageJSON))
50+
fmt.Println("Fetched Advanced Computer Search by ID:\n", string(advancedComputerSearchXML))
5251
}

examples/computer_prestages/GetComputerPrestageByID/GetComputerPrestageByID.go renamed to examples/advanced_computer_searches/GetAdvancedComputerSearches/GetAdvancedComputerSearches.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func main() {
12-
// Define the path to the JSON configuration file inside the main function
12+
// Define the path to the JSON configuration file
1313
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
1414

1515
// Load the client OAuth credentials from the configuration file
@@ -18,7 +18,7 @@ func main() {
1818
log.Fatalf("Failed to load client OAuth configuration: %v", err)
1919
}
2020

21-
// Configuration for the jamfpro
21+
// Configuration for Jamf Pro
2222
config := jamfpro.Config{
2323
InstanceName: authConfig.InstanceName,
2424
DebugMode: true,
@@ -27,25 +27,22 @@ func main() {
2727
ClientSecret: authConfig.ClientSecret,
2828
}
2929

30-
// Create a new jamfpro client instance
30+
// Create a new Jamf Pro client instance
3131
client, err := jamfpro.NewClient(config)
3232
if err != nil {
3333
log.Fatalf("Failed to create Jamf Pro client: %v", err)
3434
}
3535

36-
// Define the ID of the Computer Prestage you want to fetch as a string
37-
prestageID := "2" // Replace with the actual prestage ID as a string
38-
39-
// Call GetComputerPrestageByID function
40-
prestage, err := client.GetComputerPrestageByID(prestageID)
36+
// Call GetAdvancedComputerSearches function
37+
advancedComputerSearches, err := client.GetAdvancedComputerSearches()
4138
if err != nil {
42-
log.Fatalf("Error fetching Computer Prestage by ID: %v", err)
39+
log.Fatalf("Error fetching advanced computer searches: %v", err)
4340
}
4441

45-
// Pretty print the prestage in XML
46-
prestageXML, err := xml.MarshalIndent(prestage, "", " ") // Indent with 4 spaces
42+
// Pretty print the advanced computer searches in XML
43+
advancedComputerSearchesXML, err := xml.MarshalIndent(advancedComputerSearches, "", " ") // Indent with 4 spaces
4744
if err != nil {
48-
log.Fatalf("Error marshaling Computer Prestage data: %v", err)
45+
log.Fatalf("Error marshaling advanced computer searches data: %v", err)
4946
}
50-
fmt.Println("Fetched Computer Prestage:\n", string(prestageXML))
47+
fmt.Println("Fetched Advanced Computer Searches:\n", string(advancedComputerSearchesXML))
5148
}
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+
// Define the name of the advanced computer search
12+
const advancedComputerSearchName = "YourSearchName" // Replace with the actual name
13+
14+
func main() {
15+
// Define the path to the JSON configuration file
16+
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
17+
18+
// Load the client OAuth credentials from the configuration file
19+
authConfig, err := jamfpro.LoadClientAuthConfig(configFilePath)
20+
if err != nil {
21+
log.Fatalf("Failed to load client OAuth configuration: %v", err)
22+
}
23+
24+
// Configuration for Jamf Pro
25+
config := jamfpro.Config{
26+
InstanceName: authConfig.InstanceName,
27+
DebugMode: true,
28+
Logger: jamfpro.NewDefaultLogger(),
29+
ClientID: authConfig.ClientID,
30+
ClientSecret: authConfig.ClientSecret,
31+
}
32+
33+
// Create a new Jamf Pro client instance
34+
client, err := jamfpro.NewClient(config)
35+
if err != nil {
36+
log.Fatalf("Failed to create Jamf Pro client: %v", err)
37+
}
38+
39+
// Call GetAdvancedComputerSearchesByName function using the constant name
40+
advancedComputerSearchByName, err := client.GetAdvancedComputerSearchesByName(advancedComputerSearchName)
41+
if err != nil {
42+
log.Fatalf("Error fetching advanced computer search by name: %v", err)
43+
}
44+
45+
// Pretty print the advanced computer search by name in XML
46+
advancedComputerSearchByNameXML, err := xml.MarshalIndent(advancedComputerSearchByName, "", " ") // Indent with 4 spaces
47+
if err != nil {
48+
log.Fatalf("Error marshaling advanced computer search by name data: %v", err)
49+
}
50+
fmt.Println("Fetched Advanced Computer Search by Name:\n", string(advancedComputerSearchByNameXML))
51+
}

0 commit comments

Comments
 (0)