Skip to content

Commit 230f3fe

Browse files
authored
feat: add support for device-enrollments/public-key retrieval (#776)
1 parent beda951 commit 230f3fe

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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 with the HTTP client configuration
15+
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
16+
if err != nil {
17+
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
18+
}
19+
20+
// Call the GetDeviceEnrollmentsPublicKey method to retrieve the public key
21+
response, err := client.GetDeviceEnrollmentsPublicKey()
22+
if err != nil {
23+
log.Fatalf("Failed to retrieve Public Key: %v", err)
24+
}
25+
fmt.Print(response)
26+
}

sdk/jamfpro/jamfproapi_device_enrollments.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,23 @@ func (c *Client) GetDeviceEnrollmentSyncStates(id string) ([]ResourceDeviceEnrol
175175
return out, nil
176176
}
177177

178+
// GetDeviceEnrollmentsPublicKey retrieves the public key for device enrollments
179+
func (c *Client) GetDeviceEnrollmentsPublicKey() (string, error) {
180+
endpoint := fmt.Sprintf("%s/public-key", uriDeviceEnrollments)
181+
182+
var out []byte
183+
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &out)
184+
if err != nil {
185+
return "", fmt.Errorf(errMsgFailedGet, "device enrollment public key", err)
186+
}
187+
188+
if resp != nil && resp.Body != nil {
189+
defer resp.Body.Close()
190+
}
191+
192+
return string(out), nil
193+
}
194+
178195
// CreateDeviceEnrollmentWithMDMServerToken creates a new device enrollment instance using
179196
// The downloaded token base 64 encoded from the MDM server to be used to create a new Device Enrollment Instance.
180197
func (c *Client) CreateDeviceEnrollmentWithMDMServerToken(tokenUpload *ResourceDeviceEnrollmentTokenUpload) (*ResponseDeviceEnrollmentTokenUpload, error) {

0 commit comments

Comments
 (0)