-
Notifications
You must be signed in to change notification settings - Fork 5
/
classicapi_smtp_server.go
77 lines (60 loc) · 2.06 KB
/
classicapi_smtp_server.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
68
69
70
71
72
73
74
75
76
77
// classicapi_smtp_server.go
// Jamf Pro Classic Api - SMTP Server
// api reference: https://developer.jamf.com/jamf-pro/reference/smtpserver
// Classic API requires the structs to support an XML data structure.
package jamfpro
import (
"encoding/xml"
"fmt"
)
const uriSMTPServer = "/JSSResource/smtpserver"
// Struct for the SMTP server settings response
// Resource
type ResourceSMTPServer struct {
Enabled bool `xml:"enabled"`
Host string `xml:"host"`
Port int `xml:"port"`
Timeout int `xml:"timeout"`
AuthorizationRequired bool `xml:"authorization_required"`
Username string `xml:"username"`
Password string `xml:"password"`
SSL bool `xml:"ssl"`
TLS bool `xml:"tls"`
SendFromName string `xml:"send_from_name"`
SendFromEmail string `xml:"send_from_email"`
}
// CRUD
// GetSMTPServerInformation gets the SMTP server settings
func (c *Client) GetSMTPServerInformation() (*ResourceSMTPServer, error) {
endpoint := uriSMTPServer
var smtpSettings ResourceSMTPServer
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &smtpSettings)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGet, "smtp server information", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &smtpSettings, nil
}
// UpdateSMTPServerInformation updates the SMTP server settings
func (c *Client) UpdateSMTPServerInformation(settings *ResourceSMTPServer) error {
endpoint := uriSMTPServer
// Wrap the settings with the desired XML name using an anonymous struct
requestBody := struct {
XMLName xml.Name `xml:"smtp_server"`
*ResourceSMTPServer
}{
ResourceSMTPServer: settings,
}
// Create a dummy struct for the response
var handleResponse struct{}
resp, err := c.HTTP.DoRequest("PUT", endpoint, &requestBody, &handleResponse)
if err != nil {
return fmt.Errorf(errMsgFailedUpdate, "smtp server information", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return nil
}