Skip to content

Commit 81bddd0

Browse files
authored
Merge pull request #655 from deploymenttheory/feat/patch_policies
feat: add examples for managing external patch sources in Jamf Pro SDK
2 parents a9785e5 + 4c06f01 commit 81bddd0

File tree

7 files changed

+222
-2
lines changed

7 files changed

+222
-2
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
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/localtesting/jamfpro/clientconfig.json"
14+
15+
// Initialize the Jamf Pro client
16+
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
17+
if err != nil {
18+
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
19+
}
20+
21+
// Create new patch source
22+
newSource := &jamfpro.ResourcePatchExternalSource{
23+
Name: "Test External Source",
24+
HostName: "patch.example.com",
25+
Port: 443,
26+
SSLEnabled: true,
27+
}
28+
29+
// Create the patch external source
30+
createdSource, err := client.CreateExternalPatchSource(newSource)
31+
if err != nil {
32+
log.Fatalf("Error creating patch external source: %v", err)
33+
}
34+
35+
// Pretty print the created source
36+
resp, err := json.MarshalIndent(createdSource, "", " ")
37+
if err != nil {
38+
log.Fatalf("Error marshaling created source data: %v", err)
39+
}
40+
fmt.Printf("Created Patch External Source:\n%s\n", string(resp))
41+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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/localtesting/jamfpro/clientconfig.json"
13+
14+
// Initialize the Jamf Pro client
15+
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
16+
if err != nil {
17+
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
18+
}
19+
20+
// Specify the ID to delete
21+
sourceID := "3"
22+
23+
// Delete the patch external source
24+
err = client.DeleteExternalPatchSourceByID(sourceID)
25+
if err != nil {
26+
log.Fatalf("Error deleting patch external source: %v", err)
27+
}
28+
29+
fmt.Printf("Successfully deleted patch external source with ID: %s\n", sourceID)
30+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
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/localtesting/jamfpro/clientconfig.json"
14+
15+
// Initialize the Jamf Pro client
16+
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
17+
if err != nil {
18+
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
19+
}
20+
21+
// Specify the ID to fetch
22+
sourceID := "3"
23+
24+
// Get the patch external source by ID
25+
source, err := client.GetPatchExternalSourceByID(sourceID)
26+
if err != nil {
27+
log.Fatalf("Error fetching patch external source: %v", err)
28+
}
29+
30+
// Pretty print the source
31+
resp, err := json.MarshalIndent(source, "", " ")
32+
if err != nil {
33+
log.Fatalf("Error marshaling source data: %v", err)
34+
}
35+
fmt.Printf("Patch External Source (ID: %s):\n%s\n", sourceID, string(resp))
36+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
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/localtesting/jamfpro/clientconfig.json"
14+
15+
// Initialize the Jamf Pro client
16+
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
17+
if err != nil {
18+
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
19+
}
20+
21+
// Specify the name to fetch
22+
sourceName := "Test External Source"
23+
24+
// Get the patch external source by name
25+
source, err := client.GetPatchExternalSourceByName(sourceName)
26+
if err != nil {
27+
log.Fatalf("Error fetching patch external source: %v", err)
28+
}
29+
30+
// Pretty print the source
31+
resp, err := json.MarshalIndent(source, "", " ")
32+
if err != nil {
33+
log.Fatalf("Error marshaling source data: %v", err)
34+
}
35+
fmt.Printf("Patch External Source (Name: %s):\n%s\n", sourceName, string(resp))
36+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
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/localtesting/jamfpro/clientconfig.json"
14+
15+
// Initialize the Jamf Pro client
16+
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
17+
if err != nil {
18+
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
19+
}
20+
21+
// Get all patch external sources
22+
sources, err := client.GetPatchExternalSources()
23+
if err != nil {
24+
log.Fatalf("Error fetching patch external sources: %v", err)
25+
}
26+
27+
// Pretty print the sources
28+
resp, err := json.MarshalIndent(sources, "", " ")
29+
if err != nil {
30+
log.Fatalf("Error marshaling sources data: %v", err)
31+
}
32+
fmt.Printf("Patch External Sources:\n%s\n", string(resp))
33+
}
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+
"encoding/json"
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/localtesting/jamfpro/clientconfig.json"
14+
15+
// Initialize the Jamf Pro client
16+
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
17+
if err != nil {
18+
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
19+
}
20+
21+
// Updated source details
22+
updatedSource := &jamfpro.ResourcePatchExternalSource{
23+
Name: "Updated External Source",
24+
HostName: "patch.example.com",
25+
Port: 443,
26+
SSLEnabled: true,
27+
}
28+
29+
// Specify the ID to update
30+
sourceID := "3"
31+
32+
// Update the patch external source
33+
resultSource, err := client.UpdateExternalPatchSourceByID(sourceID, updatedSource)
34+
if err != nil {
35+
log.Fatalf("Error updating patch external source: %v", err)
36+
}
37+
38+
// Pretty print the updated source
39+
resp, err := json.MarshalIndent(resultSource, "", " ")
40+
if err != nil {
41+
log.Fatalf("Error marshaling updated source data: %v", err)
42+
}
43+
fmt.Printf("Updated Patch External Source:\n%s\n", string(resp))
44+
}

sdk/jamfpro/classicapi_patch_external_sources.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ type ResponsePatchExternalSourcesListItem struct {
3333

3434
// ResourcePatchExternalSource represents the root element of the patch external source.
3535
type ResourcePatchExternalSource struct {
36+
ID int `xml:"id" json:"id"`
3637
HostName string `xml:"host_name,omitempty" json:"host_name"`
3738
SSLEnabled bool `xml:"ssl_enabled" json:"ssl_enabled"`
38-
Port int `xml:"port" json:"port"`
39-
ID int `xml:"id" json:"id"`
39+
Port int `xml:"port,omitempty" json:"port"`
4040
Name string `xml:"name,omitempty" json:"name"`
4141
}
4242

0 commit comments

Comments
 (0)