/
classicapi_gsx_connection.go
67 lines (51 loc) · 1.66 KB
/
classicapi_gsx_connection.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
63
64
65
66
67
// classicapi_gsx_connection.go
// Jamf Pro Classic Api - GSX Connection
// api reference: https://developer.jamf.com/jamf-pro/reference/gsxconnection
// Classic API requires the structs to support an XML data structure.
package jamfpro
import (
"encoding/xml"
"fmt"
)
const uriGSXConnection = "/JSSResource/gsxconnection"
// Resource
type ResourceGSXConnection struct {
Enabled bool `xml:"enabled"`
Username string `xml:"username"`
AccountNumber int `xml:"account_number"`
Region string `xml:"region"`
URI string `xml:"uri"`
}
// CRUD
// GetGSXConnectionInformation gets the GSX connection settings
func (c *Client) GetGSXConnectionInformation() (*ResourceGSXConnection, error) {
endpoint := uriGSXConnection
var gsxConnectionSettings ResourceGSXConnection
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &gsxConnectionSettings)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGet, "gsx connection information", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &gsxConnectionSettings, nil
}
// UpdateGSXConnectionInformation updates the GSX connection settings
func (c *Client) UpdateGSXConnectionInformation(settings *ResourceGSXConnection) error {
endpoint := uriGSXConnection
requestBody := struct {
XMLName xml.Name `xml:"gsx_connection"`
*ResourceGSXConnection
}{
ResourceGSXConnection: settings,
}
var handleResponse struct{}
resp, err := c.HTTP.DoRequest("PUT", endpoint, &requestBody, &handleResponse)
if err != nil {
return fmt.Errorf(errMsgFailedUpdate, "gsx connection information", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return nil
}