Skip to content

Commit b535816

Browse files
authored
feat: add support for /v1/self-service-plus/settings (#823)
* fix: refactor Jamf Protect functions * feat: add support for /v1/self-service-plus/settings
1 parent ab7291d commit b535816

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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/Shared/GitHub/go-api-sdk-jamfpro/localtesting/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 Self Service Plus settings
22+
settings, err := client.GetSelfServicePlusSettings()
23+
if err != nil {
24+
log.Fatalf("Failed to get Self Service Plus settings: %v", err)
25+
}
26+
27+
// Pretty print the results
28+
settingsJSON, err := json.MarshalIndent(settings, "", " ")
29+
if err != nil {
30+
log.Fatalf("Failed to marshal settings to JSON: %v", err)
31+
}
32+
33+
fmt.Println("Self Service Plus Settings:")
34+
fmt.Println(string(settingsJSON))
35+
}
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+
"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/Shared/GitHub/go-api-sdk-jamfpro/localtesting/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+
// Create settings to update
21+
settings := jamfpro.ResourceSelfServicePlusSettings{
22+
Enabled: true,
23+
}
24+
25+
// Update the settings
26+
err = client.UpdateSelfServicePlusSettings(settings)
27+
if err != nil {
28+
log.Fatalf("Error updating settings: %v", err)
29+
}
30+
31+
fmt.Println("Successfully updated Self Service Plus settings")
32+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// jamfproapi_self_service_plus.go
2+
// Jamf Pro API - Self Service Plus Settings
3+
// api reference: /v1/self-service-plus/settings
4+
package jamfpro
5+
6+
import (
7+
"fmt"
8+
)
9+
10+
const (
11+
uriSelfServicePlusSettings = "/api/v1/self-service-plus/settings"
12+
)
13+
14+
// Structs
15+
16+
type ResourceSelfServicePlusSettings struct {
17+
Enabled bool `json:"enabled"`
18+
}
19+
20+
// CRUD
21+
22+
// GetSelfServicePlusSettings retrieves the current Self Service Plus settings
23+
func (c *Client) GetSelfServicePlusSettings() (*ResourceSelfServicePlusSettings, error) {
24+
endpoint := uriSelfServicePlusSettings
25+
var out ResourceSelfServicePlusSettings
26+
27+
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &out)
28+
if err != nil {
29+
return nil, fmt.Errorf(errMsgFailedGet, "self service plus 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+
// UpdateSelfServicePlusSettings updates the Self Service Plus settings
40+
func (c *Client) UpdateSelfServicePlusSettings(settings ResourceSelfServicePlusSettings) error {
41+
endpoint := uriSelfServicePlusSettings
42+
43+
resp, _ := c.HTTP.DoRequest("PUT", endpoint, settings, nil)
44+
45+
if resp == nil {
46+
return fmt.Errorf("failed to update Self Service Plus settings: received nil response")
47+
}
48+
49+
if resp.Body != nil {
50+
defer resp.Body.Close()
51+
}
52+
53+
if resp.StatusCode != 204 {
54+
return fmt.Errorf("failed to update Self Service Plus settings: unexpected status code %d", resp.StatusCode)
55+
}
56+
57+
return nil
58+
}

0 commit comments

Comments
 (0)