-
Notifications
You must be signed in to change notification settings - Fork 4
/
regex_property.go
153 lines (141 loc) · 5.1 KB
/
regex_property.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
package qradar
import (
"context"
"fmt"
"net/http"
)
// RegexPropertyService handles methods related to Regex Properties of the QRadar API.
type RegexPropertyService service
const (
regexPropertyAPIPrefix = "api/config/event_sources/custom_properties/regex_properties"
)
// RegexProperty represents QRadar's Regex Property which is a metadata of a Custom Property.
type RegexProperty struct {
Identifier *string `json:"identifier,omitempty"`
ModificationDate *int `json:"modification_date,omitempty"`
DatetimeFormat *string `json:"datetime_format,omitempty"`
PropertyType *string `json:"property_type,omitempty"`
Name *string `json:"name,omitempty"`
AutoDiscovered *bool `json:"auto_discovered,omitempty"`
Description *string `json:"description,omitempty"`
ID *int `json:"id,omitempty"`
UseForRuleEngine *bool `json:"use_for_rule_engine,omitempty"`
CreationDate *int `json:"creation_date,omitempty"`
Locale *string `json:"locale,omitempty"`
Username *string `json:"username,omitempty"`
}
// DeleteTask represents structure of a Delete Task to ensure safe deletion.
type DeleteTask struct {
ID *int `json:"id,omitempty"`
Message *string `json:"message,omitempty"`
Status *string `json:"status,omitempty"`
Name *string `json:"name,omitempty"`
CreatedBy *string `json:"created_by,omitempty"`
Created *int `json:"created,omitempty"`
Started *int `json:"started,omitempty"`
Modified *int `json:"modified,omitempty"`
Completed *int `json:"completed,omitempty"`
}
// Get returns Regex Properties of the current QRadar installation.
func (c *RegexPropertyService) Get(ctx context.Context, fields, filter string, from, to int) ([]RegexProperty, error) {
req, err := c.client.requestHelp(http.MethodGet, regexPropertyAPIPrefix, fields, filter, from, to, nil, nil)
if err != nil {
return nil, err
}
var result []RegexProperty
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
return result, nil
}
// GetByID returns Regex Property of the current QRadar installation by ID.
func (c *RegexPropertyService) GetByID(ctx context.Context, fields string, id int) (*RegexProperty, error) {
req, err := c.client.requestHelp(http.MethodGet, regexPropertyAPIPrefix, fields, "", 0, 0, &id, nil)
if err != nil {
return nil, err
}
var result RegexProperty
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
return &result, nil
}
// Create creates Regex Property in QRadar installation.
func (c *RegexPropertyService) Create(ctx context.Context, fields string, data interface{}) (*RegexProperty, error) {
req, err := c.client.requestHelp(http.MethodPost, regexPropertyAPIPrefix, fields, "", 0, 0, nil, data)
if err != nil {
return nil, err
}
var result RegexProperty
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
return &result, nil
}
// UpdateByID updates Regex Property in QRadar installation by ID.
func (c *RegexPropertyService) UpdateByID(ctx context.Context, fields string, id int, data interface{}) (*RegexProperty, error) {
req, err := c.client.requestHelp(http.MethodPost, regexPropertyAPIPrefix, fields, "", 0, 0, &id, data)
if err != nil {
return nil, err
}
var result RegexProperty
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
return &result, nil
}
// DeleteByID creates A Delete Task in QRadar installation in order to safely delete Regex Property by ID.
func (c *RegexPropertyService) DeleteByID(ctx context.Context, fields string, id int) (*DeleteTask, error) {
req, err := c.client.requestHelp(http.MethodDelete, regexPropertyAPIPrefix, fields, "", 0, 0, &id, nil)
if err != nil {
return nil, err
}
var result DeleteTask
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
return &result, nil
}
// GetByName returns Regex Property of the current QRadar installation by Name.
func (c *RegexPropertyService) GetByName(ctx context.Context, fields string, name string) (*RegexProperty, error) {
req, err := c.client.requestHelp(http.MethodGet, regexPropertyAPIPrefix, fields, fmt.Sprintf("name=\"%s\"", name), 0, 0, nil, nil)
if err != nil {
return nil, err
}
var result []RegexProperty
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
if len(result) == 0 {
return nil, nil
}
if len(result) > 1 {
return nil, fmt.Errorf("found more rules than expected - %d", len(result))
}
return &result[0], nil
}
// GetByUUID returns Regex Property of the current QRadar installation by UUID.
func (c *RegexPropertyService) GetByUUID(ctx context.Context, fields string, uuid string) (*RegexProperty, error) {
req, err := c.client.requestHelp(http.MethodGet, regexPropertyAPIPrefix, fields, fmt.Sprintf("identifier=\"%s\"", uuid), 0, 0, nil, nil)
if err != nil {
return nil, err
}
var result []RegexProperty
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
if len(result) == 0 {
return nil, nil
}
if len(result) > 1 {
return nil, fmt.Errorf("found more rules than expected - %d", len(result))
}
return &result[0], nil
}