forked from palantir/tenablesc-client
/
agentscan.go
83 lines (64 loc) · 2.48 KB
/
agentscan.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
78
79
80
81
82
83
package tenablesc
import (
"fmt"
)
const agentScanEndpoint = "/agentScan"
const agentGroupsEndpoint = "/agentGroup/%s/remote"
// AgentScan is the fields renderable to and from the API for https://docs.tenable.com/tenablesc/api/Agent-Scan.htm
type AgentScan struct {
BaseInfo
Repository BaseInfo `json:"repository,omitempty"`
NessusManager BaseInfo `json:"nessusManager,omitempty"`
ScanWindow ProbablyString `json:"scanWindow,omitempty"`
AgentGroups []AgentGroup `json:"agentGroups,omitempty"`
Type string `json:"type,omitempty"`
EmailOnLaunch FakeBool `json:"emailOnLaunch,omitempty"`
EmailOnFinish FakeBool `json:"emailOnFinish,omitempty"`
Schedule *ScanSchedule `json:"schedule,omitempty"`
}
type agentScanResponse struct {
Manageable []*AgentScan `json:"manageable" tenable:"recurse"`
Useable []*AgentScan `json:"useable" tenable:"recurse"`
}
// AgentGroup is the fields describing an Agent Group reference in
// https://docs.tenable.com/tenablesc/api/Agent-Scan.htm ;
// for input, only the ID is needed.
type AgentGroup struct {
BaseInfo
NessusManagerID string `json:"nessusManagerID,omitempty"`
RemoteID int `json:"remoteID,omitempty"`
}
func (c *Client) GetAllAgentScans() ([]*AgentScan, error) {
resp := agentScanResponse{}
if _, err := c.getResource(agentScanEndpoint, &resp); err != nil {
return nil, fmt.Errorf("failed to get all agent scans: %w", err)
}
return resp.Manageable, nil
}
func (c *Client) GetAgentGroupsForScanner(id string) ([]*AgentGroup, error) {
var resp []*AgentGroup
if _, err := c.getResource(fmt.Sprintf(agentGroupsEndpoint, id), &resp); err != nil {
return nil, fmt.Errorf("failed to get agent groups for scanner %s: %w", id, err)
}
return resp, nil
}
func (c *Client) CreateAgentScan(s *AgentScan) (*AgentScan, error) {
resp := &AgentScan{}
if _, err := c.postResource(agentScanEndpoint, s, resp); err != nil {
return nil, fmt.Errorf("failed to create agent scan: %w", err)
}
return resp, nil
}
func (c *Client) UpdateAgentScan(s *AgentScan) (*AgentScan, error) {
resp := &AgentScan{}
if _, err := c.patchResourceWithID(agentScanEndpoint, s, resp); err != nil {
return nil, fmt.Errorf("failed to update agent scan: %w", err)
}
return resp, nil
}
func (c *Client) DeleteAgentScan(id string) error {
if _, err := c.deleteResource(fmt.Sprintf("%s/%s", agentScanEndpoint, id), nil, nil); err != nil {
return fmt.Errorf("failed to delete agent scan %s: %w", id, err)
}
return nil
}