Skip to content

Commit ce74dc3

Browse files
authored
feat: add support for v2/engage (#785)
* fix: refactor Jamf Protect functions * feat: add v2/engage support
1 parent 6d96015 commit ce74dc3

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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/neilmartin/GitHub/go-api-sdk-jamfpro/localtesting/config.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+
engageInfo, err := client.GetEngageSettings()
22+
if err != nil {
23+
log.Fatalf("Failed to get engage info, %v", err)
24+
}
25+
26+
engageInfoJson, err := json.MarshalIndent(engageInfo, "", " ")
27+
if err != nil {
28+
log.Fatalf("Failed to marshal json, %v", err)
29+
}
30+
31+
fmt.Println(string(engageInfoJson))
32+
}
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/neilmartin/GitHub/go-api-sdk-jamfpro/localtesting/config.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+
settingsUpdate := jamfpro.ResourceEngageSettings{
22+
IsEnabled: false,
23+
}
24+
25+
engageInfo, err := client.UpdateEngageSettings(settingsUpdate)
26+
if err != nil {
27+
log.Fatalf("Failed to get engage info, %v", err)
28+
}
29+
30+
engageInfoJson, err := json.MarshalIndent(engageInfo, "", " ")
31+
if err != nil {
32+
log.Fatalf("Failed to marshal json, %v", err)
33+
}
34+
35+
fmt.Println(string(engageInfoJson))
36+
}

sdk/jamfpro/jamfproapi_engage.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// jamfproapi_engage.go
2+
// Jamf Pro Api - Engage
3+
// api reference: https://developer.jamf.com/jamf-pro/reference/get_v2-engage
4+
// Jamf Pro API requires the structs to support a JSON data structure.
5+
6+
package jamfpro
7+
8+
import "fmt"
9+
10+
const UriEngageSettings = "/api/v2/engage"
11+
12+
// Structs
13+
14+
// Resource
15+
16+
type ResourceEngageSettings struct {
17+
IsEnabled bool `json:"isEnabled"`
18+
}
19+
20+
// CRUD
21+
22+
// GetEngageSettings retrieves the Engage settings from the Jamf Pro server.
23+
func (c *Client) GetEngageSettings() (*ResourceEngageSettings, error) {
24+
endpoint := UriEngageSettings
25+
26+
var out ResourceEngageSettings
27+
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &out)
28+
if err != nil {
29+
return nil, fmt.Errorf(errMsgFailedGet, "engage settings", err)
30+
}
31+
32+
if resp != nil && resp.Body != nil {
33+
defer resp.Body.Close()
34+
}
35+
36+
return &out, nil
37+
}
38+
39+
// UpdateEngageSettings updates the Engage settings on the Jamf Pro server.
40+
func (c *Client) UpdateEngageSettings(settingsUpdate ResourceEngageSettings) (*ResourceEngageSettings, error) {
41+
endpoint := UriEngageSettings
42+
43+
var out ResourceEngageSettings
44+
resp, err := c.HTTP.DoRequest("PUT", endpoint, settingsUpdate, &out)
45+
if err != nil {
46+
return nil, fmt.Errorf(errMsgFailedUpdate, "engage settings", err)
47+
}
48+
49+
if resp != nil && resp.Body != nil {
50+
defer resp.Body.Close()
51+
}
52+
53+
return &out, nil
54+
}

0 commit comments

Comments
 (0)