-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.go
193 lines (176 loc) · 6.25 KB
/
client.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package wallarm
import "encoding/json"
type (
// Client contains operations available on Client resource
Client interface {
ClientCreate(clientBody *ClientCreate) (*SingleClientInfo, error)
ClientUpdate(clientBody *ClientUpdate) (*ClientInfo, error)
ClientRead(clientBody *ClientRead) (*ClientInfo, error)
}
// ClientFields defines fields which are subject to update.
ClientFields struct {
Enabled bool `json:"enabled"`
ScannerMode string `json:"scanner_mode,omitempty"`
AttackRecheckerMode string `json:"attack_rechecker_mode,omitempty"`
}
// ClientFilter is used for filtration.
// ID is a Client ID entity.
ClientFilter struct {
ID int `json:"id"`
}
// ClientCreate is a root object for updating.
ClientCreate struct {
Name string `json:"name"`
VulnPrefix string `json:"vuln_prefix"`
PartnerUUID string `json:"partner_uuid"`
}
// ClientUpdate is a root object for updating.
ClientUpdate struct {
Filter *ClientFilter `json:"filter"`
Fields *ClientFields `json:"fields"`
}
// ClientRead is used for filtration of Client Info.
ClientRead struct {
Filter *ClientReadFilter `json:"filter"`
Limit int `json:"limit"`
Offset int `json:"offset"`
}
// ClientReadFilter is the inner object for Filter.
ClientReadFilter struct {
ClientFilter
Enabled bool `json:"enabled,omitempty"`
Name string `json:"name,omitempty"`
}
// ClientInfo is the response on the Client Read.
// It shows the common information about the client.
ClientInfo struct {
Status int `json:"status"`
Body []ClientInfoBody `json:"body"`
}
SingleClientInfo struct {
Status int `json:"status"`
Body ClientInfoBody `json:"body"`
}
ClientInfoBody struct {
ID int `json:"id"`
UUID string `json:"uuid"`
ClientFilter
Name string `json:"name"`
Components []string `json:"components"`
VulnPrefix string `json:"vuln_prefix"`
SupportPlan string `json:"support_plan"`
DateFormat string `json:"date_format"`
BlockingType string `json:"blocking_type"`
ScannerMode string `json:"scanner_mode"`
QratorBlacklists bool `json:"qrator_blacklists"`
Notifications struct {
ReportDaily struct {
Email []interface{} `json:"email"`
Telegram []interface{} `json:"telegram"`
Slack []interface{} `json:"slack"`
Splunk []interface{} `json:"splunk"`
PagerDuty []interface{} `json:"pager_duty"`
} `json:"report_daily"`
ReportWeekly struct {
Email []interface{} `json:"email"`
Telegram []interface{} `json:"telegram"`
Slack []interface{} `json:"slack"`
Splunk []interface{} `json:"splunk"`
PagerDuty []interface{} `json:"pager_duty"`
} `json:"report_weekly"`
ReportMonthly struct {
Email []interface{} `json:"email"`
Telegram []interface{} `json:"telegram"`
Slack []interface{} `json:"slack"`
Splunk []interface{} `json:"splunk"`
PagerDuty []interface{} `json:"pager_duty"`
} `json:"report_monthly"`
System struct {
Email []interface{} `json:"email"`
Telegram []interface{} `json:"telegram"`
Slack []interface{} `json:"slack"`
Splunk []interface{} `json:"splunk"`
PagerDuty []interface{} `json:"pager_duty"`
} `json:"system"`
Vuln struct {
Email []interface{} `json:"email"`
Telegram []interface{} `json:"telegram"`
Slack []interface{} `json:"slack"`
Splunk []interface{} `json:"splunk"`
PagerDuty []interface{} `json:"pager_duty"`
} `json:"vuln"`
Scope struct {
Email []interface{} `json:"email"`
Telegram []interface{} `json:"telegram"`
Slack []interface{} `json:"slack"`
Splunk []interface{} `json:"splunk"`
PagerDuty []interface{} `json:"pager_duty"`
} `json:"scope"`
} `json:"notifications"`
LastScan interface{} `json:"last_scan"`
ScannerCluster string `json:"scanner_cluster"`
ScannerScopeCluster string `json:"scanner_scope_cluster"`
ScannerState struct {
LastScan int `json:"last_scan"`
LastVuln int `json:"last_vuln"`
LastVulnCheck interface{} `json:"last_vuln_check"`
LastWapi interface{} `json:"last_wapi"`
} `json:"scanner_state"`
Language string `json:"language"`
AttackRecheckerMode string `json:"attack_rechecker_mode"`
VulnRecheckerMode string `json:"vuln_rechecker_mode"`
Validated bool `json:"validated"`
Enabled bool `json:"enabled"`
CreateAt int `json:"create_at"`
Partnerid int `json:"partnerid"`
PartnerUUID string `json:"partner_uuid"`
CanEnableBlacklist bool `json:"can_enable_blacklist"`
BlacklistDisabledAt int `json:"blacklist_disabled_at"`
HiddenVulns bool `json:"hidden_vulns"`
ScannerPriority string `json:"scanner_priority"`
}
)
// ClientCreate create client.
// API reference: https://apiconsole.eu1.wallarm.com
func (api *api) ClientCreate(clientBody *ClientCreate) (*SingleClientInfo, error) {
uri := "/v1/objects/client/create"
respBody, err := api.makeRequest("POST", uri, "client", clientBody)
if err != nil {
return nil, err
}
var c SingleClientInfo
if err = json.Unmarshal(respBody, &c); err != nil {
return nil, err
}
return &c, nil
}
// ClientUpdate changes client state.
// It can be used with global Scanner, Attack Rechecker Statuses.
// API reference: https://apiconsole.eu1.wallarm.com
func (api *api) ClientUpdate(clientBody *ClientUpdate) (*ClientInfo, error) {
uri := "/v1/objects/client/update"
respBody, err := api.makeRequest("POST", uri, "client", clientBody)
if err != nil {
return nil, err
}
var c ClientInfo
if err = json.Unmarshal(respBody, &c); err != nil {
return nil, err
}
return &c, nil
}
// ClientRead requests common info about the account.
// There is info about Scanner, Attack Rechecker, and others.
// API reference: https://apiconsole.eu1.wallarm.com
func (api *api) ClientRead(clientBody *ClientRead) (*ClientInfo, error) {
uri := "/v1/objects/client"
respBody, err := api.makeRequest("POST", uri, "client", clientBody)
if err != nil {
return nil, err
}
var c ClientInfo
if err = json.Unmarshal(respBody, &c); err != nil {
return nil, err
}
return &c, nil
}