-
Notifications
You must be signed in to change notification settings - Fork 5
/
classicapi_activation_code.go
62 lines (48 loc) · 1.55 KB
/
classicapi_activation_code.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// classicapi_activation_code.go
// Jamf Pro Classic Api - activationcode
// api reference: https://developer.jamf.com/jamf-pro/reference/activationcode
// Classic API requires the structs to support an XML data structure.
package jamfpro
import (
"encoding/xml"
"fmt"
)
const uriAPIActivationCode = "/JSSResource/activationcode"
// Responses
// ResponseActivationCode represents the structure of the response for an activation code.
type ResourceActivationCode struct {
OrganizationName string `xml:"organization_name"`
Code string `xml:"code"`
}
// CRUD
// GetActivationCode retrieves the activation code.
func (c *Client) GetActivationCode() (*ResourceActivationCode, error) {
endpoint := uriAPIActivationCode
var activationCode ResourceActivationCode
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &activationCode)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGet, "activation code", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &activationCode, nil
}
// UpdateActivationCode updates the activation code.
func (c *Client) UpdateActivationCode(organizationName, code string) error {
endpoint := uriAPIActivationCode
requestBody := struct {
XMLName xml.Name `xml:"activation_code"`
ResourceActivationCode
}{
ResourceActivationCode: ResourceActivationCode{
OrganizationName: organizationName,
Code: code,
},
}
_, err := c.HTTP.DoRequest("POST", endpoint, &requestBody, nil)
if err != nil {
return fmt.Errorf(errMsgFailedUpdate, "activation code", err)
}
return nil
}