Skip to content

Commit 4f2de0c

Browse files
authored
feat: add support for /v4/enrollment/access-management (#826)
* fix: refactor Jamf Protect functions * feat: add support for /v4/enrollment/access-management
1 parent 492d312 commit 4f2de0c

File tree

3 files changed

+127
-0
lines changed

3 files changed

+127
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 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 new settings object
22+
newSettings := jamfpro.ResourceAccessManagementSettings{
23+
AutomatedDeviceEnrollmentServerUuid: "12345678-1234-1234-1234-123456789012",
24+
}
25+
26+
// Create the settings
27+
createdSettings, err := client.CreateAccessManagementSettings(newSettings)
28+
if err != nil {
29+
log.Fatalf("Failed to create access management settings: %v", err)
30+
}
31+
32+
// Pretty print the results
33+
settingsJSON, err := json.MarshalIndent(createdSettings, "", " ")
34+
if err != nil {
35+
log.Fatalf("Failed to marshal JSON: %v", err)
36+
}
37+
38+
fmt.Println(string(settingsJSON))
39+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 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+
// Get the access management settings
22+
settings, err := client.GetAccessManagementSettings()
23+
if err != nil {
24+
log.Fatalf("Failed to get access management 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 JSON: %v", err)
31+
}
32+
33+
fmt.Println(string(settingsJSON))
34+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// jamfproapi_access_management_settings.go
2+
// Jamf Pro API - Access Management
3+
// api reference: /v4/enrollment/access-management
4+
package jamfpro
5+
6+
import (
7+
"fmt"
8+
)
9+
10+
const (
11+
uriAccessManagementSettings = "/api/v4/enrollment/access-management"
12+
)
13+
14+
// Structs
15+
16+
type ResourceAccessManagementSettings struct {
17+
AutomatedDeviceEnrollmentServerUuid string `json:"automatedDeviceEnrollmentServerUuid"`
18+
}
19+
20+
// CRUD
21+
22+
// GetAccessManagementSettings retrieves the current Access Management settings
23+
func (c *Client) GetAccessManagementSettings() (*ResourceAccessManagementSettings, error) {
24+
endpoint := uriAccessManagementSettings
25+
var out ResourceAccessManagementSettings
26+
27+
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &out)
28+
if err != nil {
29+
return nil, fmt.Errorf(errMsgFailedGet, "access management 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+
// CreateAccessManagementSettings configures the Access Management settings on the Jamf Pro server.
40+
func (c *Client) CreateAccessManagementSettings(settingsCreate ResourceAccessManagementSettings) (*ResourceAccessManagementSettings, error) {
41+
endpoint := uriAccessManagementSettings
42+
43+
var out ResourceAccessManagementSettings
44+
resp, err := c.HTTP.DoRequest("POST", endpoint, settingsCreate, &out)
45+
if err != nil {
46+
return nil, fmt.Errorf(errMsgFailedUpdate, "access management 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)