-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaction.go
272 lines (247 loc) · 10.8 KB
/
action.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
package wallarm
import (
"encoding/json"
"fmt"
)
type (
// Action contains operations available on Action resource
Action interface {
HintRead(hintBody *HintRead) (*HintReadResp, error)
RuleRead(ruleBody *ActionRead) (*ActionFetch, error)
HintCreate(ruleBody *ActionCreate) (*ActionCreateResp, error)
RuleDelete(actionID int) error
HintDelete(hintbody *HintDelete) error
}
// ActionDetails defines the Action of how to parse the request.
// Point represents a part of the request where the condition should be satisfied.
// ActionDetails is used to define the particular assets of the Action field.
ActionDetails struct {
Type string `json:"type,omitempty"`
Point []interface{} `json:"point,omitempty"`
Value interface{} `json:"value,omitempty"`
}
// ActionCreate is a creation skeleton for the Rule.
ActionCreate struct {
Type string `json:"type"`
Action *[]ActionDetails `json:"action,omitempty"`
Clientid int `json:"clientid,omitempty"`
Validated bool `json:"validated"`
Point TwoDimensionalSlice `json:"point,omitempty"`
Rules []string `json:"rules,omitempty"`
AttackType string `json:"attack_type,omitempty"`
Mode string `json:"mode,omitempty"`
Counter string `json:"counter,omitempty"`
Regex string `json:"regex,omitempty"`
RegexID int `json:"regex_id,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
Name string `json:"name,omitempty"`
Values []string `json:"values,omitempty"`
Comment string `json:"comment,omitempty"`
FileType string `json:"file_type,omitempty"`
Parser string `json:"parser,omitempty"`
State string `json:"state,omitempty"`
VarType string `json:"var_type,omitempty"`
VariativityDisabled bool `json:"variativity_disabled,omitempty"`
LoginRegex string `json:"login_regex,omitempty"`
CredStuffType string `json:"cred_stuff_type,omitempty"`
CredStuffMode string `json:"cred_stuff_mode,omitempty"`
CaseSensitive *bool `json:"case_sensitive,omitempty"`
LoginPoint TwoDimensionalSlice `json:"login_point,omitempty"`
Delay int `json:"delay,omitempty"`
Burst int `json:"burst,omitempty"`
Rate int `json:"rate,omitempty"`
RspStatus int `json:"rsp_status,omitempty"`
TimeUnit string `json:"time_unit,omitempty"`
OverlimitTime int `json:"overlimit_time,omitempty"`
Suffix string `json:"suffix,omitempty"`
MaxDepth int `json:"max_depth,omitempty"`
MaxValueSizeKb int `json:"max_value_size_kb,omitempty"`
MaxDocSizeKb int `json:"max_doc_size_kb,omitempty"`
MaxAliasesSizeKb int `json:"max_aliases,omitempty"`
MaxDocPerBatch int `json:"max_doc_per_batch,omitempty"`
Introspection *bool `json:"introspection,omitempty"`
DebugEnabled *bool `json:"debug_enabled,omitempty"`
}
// ActionFilter is the specific filter for getting the rules.
// This is an inner structure.
ActionFilter struct {
ID []int `json:"id,omitempty"`
NotID []int `json:"!id,omitempty"`
Clientid []int `json:"clientid,omitempty"`
HintType []string `json:"hint_type,omitempty"`
}
// TwoDimensionalSlice is used for Point and HintsCount structures.
TwoDimensionalSlice [][]interface{}
// ActionRead is used as a filter to fetch the rules.
ActionRead struct {
Filter *ActionFilter `json:"filter"`
Limit int `json:"limit"`
Offset int `json:"offset"`
}
// ActionFetch is a response struct which portrays
// all conditions set for requests of filtered type.
ActionFetch struct {
Status int `json:"status"`
Body []struct {
ID int `json:"id"`
Clientid int `json:"clientid"`
Name interface{} `json:"name"`
Conditions []interface{} `json:"conditions"`
Hints int `json:"hints"`
GroupedHintsCount int `json:"grouped_hints_count"`
UpdatedAt int `json:"updated_at"`
} `json:"body"`
}
// ActionBody is an inner body for the Action and Hint responses.
ActionBody struct {
ID int `json:"id"`
ActionID int `json:"actionid"`
Clientid int `json:"clientid"`
Action []ActionDetails `json:"action"`
CreateTime int `json:"create_time"`
CreateUserid int `json:"create_userid"`
Validated bool `json:"validated"`
System bool `json:"system"`
RegexID interface{} `json:"regex_id"`
UpdatedAt int `json:"updated_at"`
Type string `json:"type"`
Enabled bool `json:"enabled"`
Mode string `json:"mode"`
Regex string `json:"regex"`
Point []interface{} `json:"point"`
AttackType string `json:"attack_type"`
Rules []string `json:"rules"`
Counter string `json:"counter,omitempty"`
VarType string `json:"var_type"`
LoginRegex string `json:"login_regex"`
CredStuffType string `json:"cred_stuff_type"`
CredStuffMode string `json:"cred_stuff_mode"`
CaseSensitive *bool `json:"case_sensitive"`
LoginPoint []interface{} `json:"login_point"`
// Headers for the Set Response Headers Rule
// are defined by these two parameters.
Name string `json:"name"`
Values []interface{} `json:"values"`
Delay int `json:"delay,omitempty"`
Burst int `json:"burst,omitempty"`
Rate int `json:"rate,omitempty"`
RspStatus int `json:"rsp_status,omitempty"`
TimeUnit string `json:"time_unit,omitempty"`
OverlimitTime int `json:"overlimit_time,omitempty"`
Suffix string `json:"suffix,omitempty"`
FileType string `json:"file_type,omitempty"`
Parser string `json:"parser,omitempty"`
State string `json:"state,omitempty"`
MaxDepth int `json:"max_depth,omitempty"`
MaxValueSizeKb int `json:"max_value_size_kb,omitempty"`
MaxDocSizeKb int `json:"max_doc_size_kb,omitempty"`
MaxAliasesSizeKb int `json:"max_aliases,omitempty"`
MaxDocPerBatch int `json:"max_doc_per_batch,omitempty"`
Introspection *bool `json:"introspection,omitempty"`
DebugEnabled *bool `json:"debug_enabled,omitempty"`
}
// ActionCreateResp is the response of just created Rule.
ActionCreateResp struct {
Status int `json:"status"`
Body *ActionBody `json:"body"`
}
// HintReadResp is the response of filtered rules by Action ID.
HintReadResp struct {
Status int `json:"status"`
Body *[]ActionBody `json:"body"`
}
// HintRead is used to define whether action of the rule exists.
HintRead struct {
Filter *HintFilter `json:"filter"`
OrderBy string `json:"order_by"`
OrderDesc bool `json:"order_desc"`
Limit int `json:"limit"`
Offset int `json:"offset"`
}
// HintFilter is used as a filter by Action ID.
HintFilter struct {
Clientid []int `json:"clientid,omitempty"`
ActionID []int `json:"actionid,omitempty"`
ID []int `json:"id,omitempty"`
NotID []int `json:"!id,omitempty"`
NotActionID []int `json:"!actionid,omitempty"`
CreateUserid []int `json:"create_userid,omitempty"`
NotCreateUserid []int `json:"!create_userid,omitempty"`
CreateTime [][]int `json:"create_time,omitempty"`
NotCreateTime [][]int `json:"!create_time,omitempty"`
System bool `json:"system,omitempty"`
Type []string `json:"type,omitempty"`
Point TwoDimensionalSlice `json:"point,omitempty"`
}
// HintDelete is used for removal of Rule by Hint ID.
HintDelete struct {
Filter *HintDeleteFilter `json:"filter"`
}
// HintDeleteFilter is used as a filter by Hint ID.
HintDeleteFilter struct {
Clientid []int `json:"clientid"`
ID int `json:"id"`
}
)
// HintRead reads the Rules defined by Action ID.
// API reference: https://apiconsole.eu1.wallarm.com
func (api *api) HintRead(hintBody *HintRead) (*HintReadResp, error) {
uri := "/v1/objects/hint"
respBody, err := api.makeRequest("POST", uri, "hint", hintBody)
if err != nil {
return nil, err
}
var h HintReadResp
if err = json.Unmarshal(respBody, &h); err != nil {
return nil, err
}
return &h, nil
}
// RuleRead reads the Rules defined by a filter.
// API reference: https://apiconsole.eu1.wallarm.com
func (api *api) RuleRead(ruleBody *ActionRead) (*ActionFetch, error) {
uri := "/v1/objects/action"
respBody, err := api.makeRequest("POST", uri, "rule", ruleBody)
if err != nil {
return nil, err
}
var a ActionFetch
if err = json.Unmarshal(respBody, &a); err != nil {
return nil, err
}
return &a, nil
}
// HintCreate creates Rules in Wallarm Cloud.
// API reference: https://apiconsole.eu1.wallarm.com
func (api *api) HintCreate(ruleBody *ActionCreate) (*ActionCreateResp, error) {
uri := "/v1/objects/hint/create"
respBody, err := api.makeRequest("POST", uri, "rule", ruleBody)
if err != nil {
return nil, err
}
var a ActionCreateResp
if err = json.Unmarshal(respBody, &a); err != nil {
return nil, err
}
return &a, nil
}
// RuleDelete deletes the Rule defined by unique ID.
// API reference: https://apiconsole.eu1.wallarm.com
func (api *api) RuleDelete(actionID int) error {
uri := fmt.Sprintf("/v2/action/%d", actionID)
_, err := api.makeRequest("DELETE", uri, "rule", nil)
if err != nil {
return err
}
return nil
}
// HintDelete deletes the Rule defined by the unique Hint ID.
// API reference: https://apiconsole.eu1.wallarm.com
func (api *api) HintDelete(hintbody *HintDelete) error {
uri := "/v1/objects/hint/delete"
_, err := api.makeRequest("POST", uri, "hint", hintbody)
if err != nil {
return err
}
return nil
}