Skip to content

Commit 7663601

Browse files
committed
feat: add functions to retrieve and update Jamf Connect config profiles by UUID, ID, and name
1 parent 6e51703 commit 7663601

File tree

5 files changed

+229
-0
lines changed

5 files changed

+229
-0
lines changed
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 with the HTTP client configuration
16+
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
17+
if err != nil {
18+
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
19+
}
20+
21+
// Example UUID - replace with an actual UUID from your environment
22+
uuid := "your-profile-uuid-here"
23+
24+
// Call GetJamfConnectConfigProfileByID function
25+
profile, err := client.GetJamfConnectConfigProfileByConfigProfileUUID(uuid)
26+
if err != nil {
27+
log.Fatalf("Error fetching Jamf Connect config profile by ID: %v", err)
28+
}
29+
30+
// Pretty print the JSON
31+
response, err := json.MarshalIndent(profile, "", " ") // Indent with 4 spaces
32+
if err != nil {
33+
log.Fatalf("Error marshaling Jamf Connect config profile data: %v", err)
34+
}
35+
fmt.Println("Fetched Jamf Connect config profile by ID:\n", string(response))
36+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// get_jamf_connect_profile_by_id.go
2+
package main
3+
4+
import (
5+
"encoding/json"
6+
"fmt"
7+
"log"
8+
9+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
10+
)
11+
12+
func main() {
13+
// Define the path to the JSON configuration file
14+
configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json"
15+
16+
// Initialize the Jamf Pro client with the HTTP client configuration
17+
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
18+
if err != nil {
19+
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
20+
}
21+
22+
// Example Profile ID - replace with an actual Profile ID from your environment
23+
profileID := 1 // Replace with actual Profile ID
24+
25+
// Call GetJamfConnectConfigProfileByID function
26+
profile, err := client.GetJamfConnectConfigProfileByID(profileID)
27+
if err != nil {
28+
log.Fatalf("Error fetching Jamf Connect config profile by ID: %v", err)
29+
}
30+
31+
// Pretty print the JSON
32+
response, err := json.MarshalIndent(profile, "", " ") // Indent with 4 spaces
33+
if err != nil {
34+
log.Fatalf("Error marshaling Jamf Connect config profile data: %v", err)
35+
}
36+
fmt.Println("Fetched Jamf Connect config profile by ID:\n", string(response))
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// get_jamf_connect_profile_by_name.go
2+
package main
3+
4+
import (
5+
"encoding/json"
6+
"fmt"
7+
"log"
8+
9+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
10+
)
11+
12+
func main() {
13+
// Define the path to the JSON configuration file
14+
configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json"
15+
16+
// Initialize the Jamf Pro client with the HTTP client configuration
17+
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
18+
if err != nil {
19+
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
20+
}
21+
22+
// Example profile name - replace with an actual profile name from your environment
23+
profileName := "Your Jamf Connect Config Profile Name"
24+
25+
// Call GetJamfConnectConfigProfileByName function
26+
profile, err := client.GetJamfConnectConfigProfileByName(profileName)
27+
if err != nil {
28+
log.Fatalf("Error fetching Jamf Connect config profile by name: %v", err)
29+
}
30+
31+
// Pretty print the JSON
32+
response, err := json.MarshalIndent(profile, "", " ") // Indent with 4 spaces
33+
if err != nil {
34+
log.Fatalf("Error marshaling Jamf Connect config profile data: %v", err)
35+
}
36+
fmt.Println("Fetched Jamf Connect config profile by name:\n", string(response))
37+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 with the HTTP client configuration
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 update payload
22+
profileUpdate := &jamfpro.ResourceJamfConnectConfigProfileUpdate{
23+
JamfConnectVersion: "2.43.0", // 2.43.0 / 2.42.0 / 2.41.0 / 2.41.0 / 2.40.0 / 2.39.0 / 2.38.0 / 2.37.0 / 2.36.1 / 2.36.0
24+
AutoDeploymentType: "MINOR_AND_PATCH_UPDATES", // "NONE" / "PATCH_UPDATES" / "MINOR_AND_PATCH_UPDATES"
25+
}
26+
27+
// Define the UUID of the profile to update
28+
profileID := 193
29+
30+
updatedProfile, err := client.UpdateJamfConnectConfigProfileByID(profileID, profileUpdate)
31+
if err != nil {
32+
log.Fatalf("Error updating Jamf Connect config profile: %v", err)
33+
}
34+
35+
response, err := json.MarshalIndent(updatedProfile, "", " ") // Indent with 4 spaces
36+
if err != nil {
37+
log.Fatalf("Error marshaling updated Jamf Connect config profile data: %v", err)
38+
}
39+
fmt.Println("Updated Jamf Connect config profile:\n", string(response))
40+
}

sdk/jamfpro/jamfproapi_jamf_connect.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,66 @@ func (c *Client) GetJamfConnectSettings() (*ResourceJamfConnect, error) {
9191
return &jamfConnect, nil
9292
}
9393

94+
// GetJamfConnectConfigProfileByConfigProfileUUID retrieves a specific Jamf Connect config profile by UUID
95+
func (c *Client) GetJamfConnectConfigProfileByConfigProfileUUID(uuid string) (*ResourceJamfConnectConfigProfile, error) {
96+
if uuid == "" {
97+
return nil, fmt.Errorf("uuid cannot be empty")
98+
}
99+
100+
profiles, err := c.GetJamfConnectConfigProfiles("")
101+
if err != nil {
102+
return nil, fmt.Errorf(errMsgFailedGet, "jamf connect config profile", err)
103+
}
104+
105+
for _, profile := range profiles.Results {
106+
if profile.UUID == uuid {
107+
return &profile, nil
108+
}
109+
}
110+
111+
return nil, fmt.Errorf("no jamf connect config profile found with UUID: %s", uuid)
112+
}
113+
114+
// GetJamfConnectConfigProfileByID retrieves a specific Jamf Connect config profile by ID
115+
func (c *Client) GetJamfConnectConfigProfileByID(profileID int) (*ResourceJamfConnectConfigProfile, error) {
116+
if profileID <= 0 {
117+
return nil, fmt.Errorf("profile ID must be greater than 0")
118+
}
119+
120+
profiles, err := c.GetJamfConnectConfigProfiles("")
121+
if err != nil {
122+
return nil, fmt.Errorf(errMsgFailedGet, "jamf connect config profile", err)
123+
}
124+
125+
for _, profile := range profiles.Results {
126+
if profile.ProfileID == profileID {
127+
return &profile, nil
128+
}
129+
}
130+
131+
return nil, fmt.Errorf("no jamf connect config profile found with ID: %d", profileID)
132+
}
133+
134+
// GetJamfConnectConfigProfileByName retrieves a specific Jamf Connect config profile by name
135+
func (c *Client) GetJamfConnectConfigProfileByName(name string) (*ResourceJamfConnectConfigProfile, error) {
136+
if name == "" {
137+
return nil, fmt.Errorf("name cannot be empty")
138+
}
139+
140+
profiles, err := c.GetJamfConnectConfigProfiles("")
141+
if err != nil {
142+
return nil, fmt.Errorf(errMsgFailedGet, "jamf connect config profile", err)
143+
}
144+
145+
for _, profile := range profiles.Results {
146+
if profile.ProfileName == name {
147+
return &profile, nil
148+
}
149+
}
150+
151+
return nil, fmt.Errorf("no jamf connect config profile found with name: %s", name)
152+
}
153+
94154
// GetJamfConnectConfigProfiles gets full list of Jamf Connect config profiles & handles pagination
95155
func (c *Client) GetJamfConnectConfigProfiles(sort_filter string) (*ResponseJamfConnectConfigProfilesList, error) {
96156
endpoint := fmt.Sprintf("%s/config-profiles", uriJamfConnect)
@@ -139,6 +199,25 @@ func (c *Client) UpdateJamfConnectConfigProfileByConfigProfileUUID(configProfile
139199
return &updatedProfile, nil
140200
}
141201

202+
// UpdateJamfConnectConfigProfileByID updates the Jamf Connect app update settings for a profile specified by ID
203+
func (c *Client) UpdateJamfConnectConfigProfileByID(profileID int, profileUpdate *ResourceJamfConnectConfigProfileUpdate) (*ResourceJamfConnectConfigProfile, error) {
204+
if profileID <= 0 {
205+
return nil, fmt.Errorf("profile ID must be greater than 0")
206+
}
207+
208+
profile, err := c.GetJamfConnectConfigProfileByID(profileID)
209+
if err != nil {
210+
return nil, fmt.Errorf(errMsgFailedGet, "jamf connect config profile", err)
211+
}
212+
213+
updatedProfile, err := c.UpdateJamfConnectConfigProfileByConfigProfileUUID(profile.UUID, profileUpdate)
214+
if err != nil {
215+
return nil, fmt.Errorf(errMsgFailedUpdateByID, "jamf connect config profile", profileID, err)
216+
}
217+
218+
return updatedProfile, nil
219+
}
220+
142221
// RetryJamfConnectDeploymentTasksByConfigProfileUUID requests a retry of Connect install tasks for a specified computers
143222
// asscoiated with a specific jamf connect configuration profile.
144223
func (c *Client) RetryJamfConnectDeploymentTasksByConfigProfileUUID(configProfileUUID string, computerIDs []string) error {

0 commit comments

Comments
 (0)