-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhost.go
65 lines (54 loc) · 1.44 KB
/
host.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
package sophosutm
import (
"encoding/json"
"fmt"
)
type Host struct {
Locked string `json:"_locked"`
Ref string `json:"_ref"`
Type string `json:"_type"`
Name string `json:"name"`
Comment string `json:"comment"`
Address string `json:"address"`
Address6 string `json:"address6"`
Hostnames []string `json:"hostnames"`
DUIDS []string `json:"duids"`
MACS []string `json:"macs"`
Interface string `json:"interface"`
Resolved bool `json:"resolved"`
Resolved6 bool `json:"resolved6"`
ReverseDNS bool `json:"reverse_dns"`
}
// GetHost gets a host defintion
func (c *Client) GetHost(ref string) (Host, error) {
getObjectResponse, err := c.GetObject(fmt.Sprintf("/objects/network/host/%s", ref))
var host Host
err = json.Unmarshal([]byte(getObjectResponse), &host)
if err != nil {
return host, err
}
return host, nil
}
// CreateHost creates a new host
func (c *Client) CreateHost(host Host) (Host, error) {
reqBody, _ := json.Marshal(
host,
)
createObjectResponse, err := c.CreateObject("/objects/network/host/", reqBody)
if err != nil {
return host, err
}
err = json.Unmarshal([]byte(createObjectResponse), &host)
if err != nil {
return host, err
}
return host, nil
}
// DeleteHost deletes a host
func (c *Client) DeleteHost(ref string) error {
_, err := c.DeleteObject(fmt.Sprintf("/objects/network/host/%s", ref))
if err != nil {
return err
}
return nil
}