Skip to content

Commit 70e466a

Browse files
authored
refactor(rule): refactor rules to use v2 client (#314)
* refactor(rule): refactor rules to use v2 client
1 parent a4654a7 commit 70e466a

17 files changed

+255
-253
lines changed

sysdig/internal/client/secure/client.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ import (
1212
)
1313

1414
type SysdigSecureClient interface {
15-
CreateRule(context.Context, Rule) (Rule, error)
16-
GetRuleByID(context.Context, int) (Rule, error)
17-
UpdateRule(context.Context, Rule) (Rule, error)
18-
DeleteRule(context.Context, int) error
19-
2015
CreateVulnerabilityExceptionList(context.Context, *VulnerabilityExceptionList) (*VulnerabilityExceptionList, error)
2116
GetVulnerabilityExceptionListByID(context.Context, string) (*VulnerabilityExceptionList, error)
2217
DeleteVulnerabilityExceptionList(context.Context, string) error

sysdig/internal/client/secure/models.go

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -6,104 +6,6 @@ import (
66
"io"
77
)
88

9-
// -------- Rules --------
10-
11-
type Rule struct {
12-
ID int `json:"id,omitempty"`
13-
Name string `json:"name"`
14-
Description string `json:"description,omitempty"`
15-
Tags []string `json:"tags"`
16-
Details Details `json:"details"`
17-
Version int `json:"version,omitempty"`
18-
}
19-
20-
type Details struct {
21-
// Containers
22-
Containers *Containers `json:"containers,omitempty"`
23-
24-
// Filesystems
25-
ReadWritePaths *ReadWritePaths `json:"readWritePaths,omitempty"`
26-
ReadPaths *ReadPaths `json:"readPaths,omitempty"`
27-
28-
// Network
29-
AllOutbound bool `json:"allOutbound,omitempty"`
30-
AllInbound bool `json:"allInbound,omitempty"`
31-
TCPListenPorts *TCPListenPorts `json:"tcpListenPorts,omitempty"`
32-
UDPListenPorts *UDPListenPorts `json:"udpListenPorts,omitempty"`
33-
34-
// Processes
35-
Processes *Processes `json:"processes,omitempty"`
36-
37-
// Syscalls
38-
Syscalls *Syscalls `json:"syscalls,omitempty"`
39-
40-
// Falco
41-
Append *bool `json:"append,omitempty"`
42-
Source string `json:"source,omitempty"`
43-
Output string `json:"output,omitempty"`
44-
Condition *Condition `json:"condition,omitempty"`
45-
Priority string `json:"priority,omitempty"`
46-
Exceptions []*Exception `json:"exceptions,omitempty"`
47-
48-
RuleType string `json:"ruleType"`
49-
}
50-
51-
type Containers struct {
52-
Items []string `json:"items"`
53-
MatchItems bool `json:"matchItems"`
54-
}
55-
56-
type ReadWritePaths struct {
57-
Items []string `json:"items"`
58-
MatchItems bool `json:"matchItems"`
59-
}
60-
type ReadPaths struct {
61-
Items []string `json:"items"`
62-
MatchItems bool `json:"matchItems"`
63-
}
64-
65-
type TCPListenPorts struct {
66-
Items []string `json:"items"`
67-
MatchItems bool `json:"matchItems"`
68-
}
69-
70-
type UDPListenPorts struct {
71-
Items []string `json:"items"`
72-
MatchItems bool `json:"matchItems"`
73-
}
74-
75-
type Processes struct {
76-
Items []string `json:"items"`
77-
MatchItems bool `json:"matchItems"`
78-
}
79-
80-
type Syscalls struct {
81-
Items []string `json:"items"`
82-
MatchItems bool `json:"matchItems"`
83-
}
84-
85-
type Condition struct {
86-
Condition string `json:"condition"`
87-
Components []interface{} `json:"components"`
88-
}
89-
90-
type Exception struct {
91-
Name string `json:"name"`
92-
Fields interface{} `json:"fields,omitempty"`
93-
Comps interface{} `json:"comps,omitempty"`
94-
Values interface{} `json:"values,omitempty"`
95-
}
96-
97-
func (r *Rule) ToJSON() io.Reader {
98-
payload, _ := json.Marshal(r)
99-
return bytes.NewBuffer(payload)
100-
}
101-
102-
func RuleFromJSON(body []byte) (rule Rule, err error) {
103-
err = json.Unmarshal(body, &rule)
104-
return
105-
}
106-
1079
// -------- VulnerabilityExceptionList --------
10810

10911
type VulnerabilityExceptionList struct {

sysdig/internal/client/secure/rules.go

Lines changed: 0 additions & 88 deletions
This file was deleted.

sysdig/internal/client/v2/list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const (
1414
)
1515

1616
type ListInterface interface {
17+
Base
1718
CreateList(ctx context.Context, list List) (List, error)
1819
GetListByID(ctx context.Context, id int) (List, error)
1920
UpdateList(ctx context.Context, list List) (List, error)

sysdig/internal/client/v2/macros.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const (
1414
)
1515

1616
type MacroInterface interface {
17+
Base
1718
CreateMacro(ctx context.Context, macro Macro) (Macro, error)
1819
GetMacroByID(ctx context.Context, id int) (Macro, error)
1920
UpdateMacro(ctx context.Context, macro Macro) (Macro, error)

sysdig/internal/client/v2/model.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,89 @@ type Macro struct {
223223
type MacroCondition struct {
224224
Condition string `json:"condition"`
225225
}
226+
227+
type Rule struct {
228+
ID int `json:"id,omitempty"`
229+
Name string `json:"name"`
230+
Description string `json:"description,omitempty"`
231+
Tags []string `json:"tags"`
232+
Details Details `json:"details"`
233+
Version int `json:"version,omitempty"`
234+
}
235+
236+
type Details struct {
237+
// Containers
238+
Containers *Containers `json:"containers,omitempty"`
239+
240+
// Filesystems
241+
ReadWritePaths *ReadWritePaths `json:"readWritePaths,omitempty"`
242+
ReadPaths *ReadPaths `json:"readPaths,omitempty"`
243+
244+
// Network
245+
AllOutbound bool `json:"allOutbound,omitempty"`
246+
AllInbound bool `json:"allInbound,omitempty"`
247+
TCPListenPorts *TCPListenPorts `json:"tcpListenPorts,omitempty"`
248+
UDPListenPorts *UDPListenPorts `json:"udpListenPorts,omitempty"`
249+
250+
// Processes
251+
Processes *Processes `json:"processes,omitempty"`
252+
253+
// Syscalls
254+
Syscalls *Syscalls `json:"syscalls,omitempty"`
255+
256+
// Falco
257+
Append *bool `json:"append,omitempty"`
258+
Source string `json:"source,omitempty"`
259+
Output string `json:"output,omitempty"`
260+
Condition *Condition `json:"condition,omitempty"`
261+
Priority string `json:"priority,omitempty"`
262+
Exceptions []*Exception `json:"exceptions,omitempty"`
263+
264+
RuleType string `json:"ruleType"`
265+
}
266+
267+
type Containers struct {
268+
Items []string `json:"items"`
269+
MatchItems bool `json:"matchItems"`
270+
}
271+
272+
type ReadWritePaths struct {
273+
Items []string `json:"items"`
274+
MatchItems bool `json:"matchItems"`
275+
}
276+
type ReadPaths struct {
277+
Items []string `json:"items"`
278+
MatchItems bool `json:"matchItems"`
279+
}
280+
281+
type TCPListenPorts struct {
282+
Items []string `json:"items"`
283+
MatchItems bool `json:"matchItems"`
284+
}
285+
286+
type UDPListenPorts struct {
287+
Items []string `json:"items"`
288+
MatchItems bool `json:"matchItems"`
289+
}
290+
291+
type Processes struct {
292+
Items []string `json:"items"`
293+
MatchItems bool `json:"matchItems"`
294+
}
295+
296+
type Syscalls struct {
297+
Items []string `json:"items"`
298+
MatchItems bool `json:"matchItems"`
299+
}
300+
301+
type Condition struct {
302+
Condition string `json:"condition"`
303+
Components []interface{} `json:"components"`
304+
}
305+
306+
type Exception struct {
307+
Name string `json:"name"`
308+
Fields interface{} `json:"fields,omitempty"`
309+
Comps interface{} `json:"comps,omitempty"`
310+
Values interface{} `json:"values,omitempty"`
311+
}

sysdig/internal/client/v2/policies.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const (
1414
)
1515

1616
type PolicyInterface interface {
17+
Base
1718
CreatePolicy(ctx context.Context, policy Policy) (Policy, error)
1819
DeletePolicy(ctx context.Context, policyID int) error
1920
UpdatePolicy(ctx context.Context, policy Policy) (Policy, error)

0 commit comments

Comments
 (0)