-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscanner.go
114 lines (99 loc) · 3.62 KB
/
scanner.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package wallarm
import (
"encoding/json"
"fmt"
)
type (
// Scanner contains operations available on Scanner resource
Scanner interface {
ScannerCreate(scannerBody *ScannerCreate) (*ScannerCreateBody, error)
ScannerDelete(scannerBody *ScannerDelete, resType string) error
ScannerUpdate(scannerBody *ScannerUpdate, resType string, resID int) error
}
// ScannerCreate is a request query to put in a new resource.
ScannerCreate struct {
Query string `json:"query"`
Clientid int `json:"clientid"`
}
// ScannerCreateBody is a response on the Create action.
ScannerCreateBody struct {
Body struct {
Result string `json:"result"`
Objects []struct {
Rps interface{} `json:"rps"`
ID int `json:"id"`
IP string `json:"ip"`
Domain string `json:"domain"`
New bool `json:"new"`
Datacenter interface{} `json:"datacenter"`
Disabled bool `json:"disabled"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
LastDisabled interface{} `json:"last_disabled"`
Group bool `json:"group"`
ParentID int `json:"parent_id"`
Clientid int `json:"clientid"`
EnabledDomainBinds int `json:"enabled_domain_binds"`
DisabledDomainBinds int `json:"disabled_domain_binds"`
EnabledServiceBinds int `json:"enabled_service_binds"`
DisabledServiceBinds int `json:"disabled_service_binds"`
DiscoveredAutomatically bool `json:"discovered_automatically"`
DisabledEdge interface{} `json:"disabled_edge"`
} `json:"objects"`
} `json:"body"`
}
// ScannerDelete is used to delete scanner resources in bulk.
ScannerDelete struct {
Bulk *[]ScannerDeleteBulk `json:"bulk"`
}
// ScannerFilter is used as a filter for delete query.
ScannerFilter struct {
*ScannerCreate
ID []int `json:"id"`
}
// ScannerDeleteBulk is used to update scope resource.
ScannerDeleteBulk struct {
Filter *ScannerFilter `json:"filter"`
}
// ScannerUpdate is used to update scope resource.
// The only field is disabling of resource so far.
ScannerUpdate struct {
Disabled bool `json:"disabled"`
Clientid int `json:"clientid"`
}
)
// ScannerCreate creates a new resource to scan.
// API reference: https://apiconsole.eu1.wallarm.com
func (api *api) ScannerCreate(scannerBody *ScannerCreate) (*ScannerCreateBody, error) {
uri := "/v2/scope/new"
res, err := api.makeRequest("PUT", uri, "scanner", scannerBody)
if err != nil {
return nil, err
}
var data ScannerCreateBody
if err = json.Unmarshal(res, &data); err != nil {
return nil, err
}
return &data, nil
}
// ScannerDelete deletes resources which have been created previously.
// API reference: https://apiconsole.eu1.wallarm.com
func (api *api) ScannerDelete(scannerBody *ScannerDelete, resType string) error {
uri := fmt.Sprintf("/v2/scope/%s/bulk", resType)
_, err := api.makeRequest("POST", uri, "", scannerBody)
if err != nil {
return err
}
return nil
}
// ScannerUpdate updates resources which have been created in prior.
// For example, you may disable the resource.
// API reference: https://apiconsole.eu1.wallarm.com
func (api *api) ScannerUpdate(scannerBody *ScannerUpdate, resType string, resID int) error {
uri := fmt.Sprintf("/v2/scope/%s/%d", resType, resID)
_, err := api.makeRequest("POST", uri, "scanner", scannerBody)
if err != nil {
return err
}
return nil
}