Skip to content

Commit 33b1ec8

Browse files
authored
pkg/types -> new imports pt 3 (#4014)
1 parent d024c41 commit 33b1ec8

File tree

14 files changed

+68
-68
lines changed

14 files changed

+68
-68
lines changed

cmd/crowdsec/crowdsec.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"github.com/crowdsecurity/crowdsec/pkg/exprhelpers"
2020
"github.com/crowdsecurity/crowdsec/pkg/metrics"
2121
"github.com/crowdsecurity/crowdsec/pkg/parser"
22-
"github.com/crowdsecurity/crowdsec/pkg/types"
22+
"github.com/crowdsecurity/crowdsec/pkg/pipeline"
2323
)
2424

2525
// initCrowdsec prepares the log processor service
@@ -172,8 +172,8 @@ func startLPMetrics(ctx context.Context, cConfig *csconfig.Config, apiClient *ap
172172

173173
// runCrowdsec starts the log processor service
174174
func runCrowdsec(ctx context.Context, cConfig *csconfig.Config, parsers *parser.Parsers, hub *cwhub.Hub, datasources []acquisition.DataSource) error {
175-
inputEventChan = make(chan types.Event)
176-
inputLineChan = make(chan types.Event)
175+
inputEventChan = make(chan pipeline.Event)
176+
inputLineChan = make(chan pipeline.Event)
177177

178178
startParserRoutines(cConfig, parsers)
179179

cmd/crowdsec/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"github.com/crowdsecurity/crowdsec/pkg/leakybucket"
2828
"github.com/crowdsecurity/crowdsec/pkg/logging"
2929
"github.com/crowdsecurity/crowdsec/pkg/parser"
30-
"github.com/crowdsecurity/crowdsec/pkg/types"
30+
"github.com/crowdsecurity/crowdsec/pkg/pipeline"
3131
)
3232

3333
var (
@@ -49,9 +49,9 @@ var (
4949
holders []leakybucket.BucketFactory
5050
buckets *leakybucket.Buckets
5151

52-
inputLineChan chan types.Event
53-
inputEventChan chan types.Event
54-
outputEventChan chan types.Event // the buckets init returns its own chan that is used for multiplexing
52+
inputLineChan chan pipeline.Event
53+
inputEventChan chan pipeline.Event
54+
outputEventChan chan pipeline.Event // the buckets init returns its own chan that is used for multiplexing
5555
// settings
5656
lastProcessedItem time.Time // keep track of last item timestamp in time-machine. it is used to GC buckets when we dump them.
5757
pluginBroker csplugin.PluginBroker

cmd/crowdsec/output.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import (
1212
leaky "github.com/crowdsecurity/crowdsec/pkg/leakybucket"
1313
"github.com/crowdsecurity/crowdsec/pkg/models"
1414
"github.com/crowdsecurity/crowdsec/pkg/parser"
15-
"github.com/crowdsecurity/crowdsec/pkg/types"
15+
"github.com/crowdsecurity/crowdsec/pkg/pipeline"
1616
)
1717

18-
func dedupAlerts(alerts []types.RuntimeAlert) ([]*models.Alert, error) {
18+
func dedupAlerts(alerts []pipeline.RuntimeAlert) ([]*models.Alert, error) {
1919
var dedupCache []*models.Alert
2020

2121
for idx, alert := range alerts {
@@ -44,7 +44,7 @@ func dedupAlerts(alerts []types.RuntimeAlert) ([]*models.Alert, error) {
4444
return dedupCache, nil
4545
}
4646

47-
func PushAlerts(ctx context.Context, alerts []types.RuntimeAlert, client *apiclient.ApiClient) error {
47+
func PushAlerts(ctx context.Context, alerts []pipeline.RuntimeAlert, client *apiclient.ApiClient) error {
4848
alertsToPush, err := dedupAlerts(alerts)
4949
if err != nil {
5050
return fmt.Errorf("failed to transform alerts for api: %w", err)
@@ -58,12 +58,12 @@ func PushAlerts(ctx context.Context, alerts []types.RuntimeAlert, client *apicli
5858
return nil
5959
}
6060

61-
var bucketOverflows []types.Event
61+
var bucketOverflows []pipeline.Event
6262

63-
func runOutput(ctx context.Context, input chan types.Event, overflow chan types.Event, buckets *leaky.Buckets, postOverflowCTX parser.UnixParserCtx,
63+
func runOutput(ctx context.Context, input chan pipeline.Event, overflow chan pipeline.Event, buckets *leaky.Buckets, postOverflowCTX parser.UnixParserCtx,
6464
postOverflowNodes []parser.Node, client *apiclient.ApiClient) error {
6565
var (
66-
cache []types.RuntimeAlert
66+
cache []pipeline.RuntimeAlert
6767
cacheMutex sync.Mutex
6868
)
6969

@@ -76,7 +76,7 @@ func runOutput(ctx context.Context, input chan types.Event, overflow chan types.
7676
if len(cache) > 0 {
7777
cacheMutex.Lock()
7878
cachecopy := cache
79-
newcache := make([]types.RuntimeAlert, 0)
79+
newcache := make([]pipeline.RuntimeAlert, 0)
8080
cache = newcache
8181
cacheMutex.Unlock()
8282
/*
@@ -121,7 +121,7 @@ func runOutput(ctx context.Context, input chan types.Event, overflow chan types.
121121
// dump after postoveflow processing to avoid missing whitelist info
122122
if dumpStates && event.Overflow.Alert != nil {
123123
if bucketOverflows == nil {
124-
bucketOverflows = make([]types.Event, 0)
124+
bucketOverflows = make([]pipeline.Event, 0)
125125
}
126126
bucketOverflows = append(bucketOverflows, event)
127127
}

cmd/crowdsec/parse.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88

99
"github.com/crowdsecurity/crowdsec/pkg/metrics"
1010
"github.com/crowdsecurity/crowdsec/pkg/parser"
11-
"github.com/crowdsecurity/crowdsec/pkg/types"
11+
"github.com/crowdsecurity/crowdsec/pkg/pipeline"
1212
)
1313

14-
func runParse(input chan types.Event, output chan types.Event, parserCTX parser.UnixParserCtx, nodes []parser.Node) error {
14+
func runParse(input chan pipeline.Event, output chan pipeline.Event, parserCTX parser.UnixParserCtx, nodes []parser.Node) error {
1515
for {
1616
select {
1717
case <-parsersTomb.Dying():
@@ -24,7 +24,7 @@ func runParse(input chan types.Event, output chan types.Event, parserCTX parser.
2424
/*Application security engine is going to generate 2 events:
2525
- one that is treated as a log and can go to scenarios
2626
- another one that will go directly to LAPI*/
27-
if event.Type == types.APPSEC {
27+
if event.Type == pipeline.APPSEC {
2828
outputEventChan <- event
2929
continue
3030
}

cmd/crowdsec/pour.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
1111
leaky "github.com/crowdsecurity/crowdsec/pkg/leakybucket"
1212
"github.com/crowdsecurity/crowdsec/pkg/metrics"
13-
"github.com/crowdsecurity/crowdsec/pkg/types"
13+
"github.com/crowdsecurity/crowdsec/pkg/pipeline"
1414
)
1515

16-
func maybeGC(parsed types.Event, buckets *leaky.Buckets, cConfig *csconfig.Config) error {
16+
func maybeGC(parsed pipeline.Event, buckets *leaky.Buckets, cConfig *csconfig.Config) error {
1717
log.Infof("%d existing buckets", leaky.LeakyRoutineCount)
1818
// when in forensics mode, garbage collect buckets
1919
if cConfig.Crowdsec.BucketsGCEnabled {
@@ -34,7 +34,7 @@ func maybeGC(parsed types.Event, buckets *leaky.Buckets, cConfig *csconfig.Confi
3434
return nil
3535
}
3636

37-
func runPour(input chan types.Event, holders []leaky.BucketFactory, buckets *leaky.Buckets, cConfig *csconfig.Config) error {
37+
func runPour(input chan pipeline.Event, holders []leaky.BucketFactory, buckets *leaky.Buckets, cConfig *csconfig.Config) error {
3838
count := 0
3939

4040
for {

cmd/crowdsec/serve.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
2222
"github.com/crowdsecurity/crowdsec/pkg/database"
2323
"github.com/crowdsecurity/crowdsec/pkg/exprhelpers"
24-
"github.com/crowdsecurity/crowdsec/pkg/types"
24+
"github.com/crowdsecurity/crowdsec/pkg/pipeline"
2525
)
2626

2727
func reloadHandler(ctx context.Context, _ os.Signal) (*csconfig.Config, error) {
@@ -205,7 +205,7 @@ func shutdown(_ os.Signal, cConfig *csconfig.Config) error {
205205
return nil
206206
}
207207

208-
func drainChan(c chan types.Event) {
208+
func drainChan(c chan pipeline.Event) {
209209
time.Sleep(500 * time.Millisecond)
210210
// delay to avoid draining chan before the acquisition/parser
211211
// get a chance to push its event

pkg/alertcontext/alertcontext.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
"github.com/crowdsecurity/crowdsec/pkg/exprhelpers"
1616
"github.com/crowdsecurity/crowdsec/pkg/models"
17-
"github.com/crowdsecurity/crowdsec/pkg/types"
17+
"github.com/crowdsecurity/crowdsec/pkg/pipeline"
1818
)
1919

2020
const MaxContextValueLen = 4000
@@ -30,8 +30,8 @@ type Context struct {
3030
func ValidateContextExpr(key string, expressions []string) error {
3131
for _, expression := range expressions {
3232
_, err := expr.Compile(expression, exprhelpers.GetExprOptions(map[string]interface{}{
33-
"evt": &types.Event{},
34-
"match": &types.MatchedRule{},
33+
"evt": &pipeline.Event{},
34+
"match": &pipeline.MatchedRule{},
3535
"req": &http.Request{},
3636
})...)
3737
if err != nil {
@@ -70,8 +70,8 @@ func NewAlertContext(contextToSend map[string][]string, valueLength int) error {
7070

7171
for _, value := range values {
7272
valueCompiled, err := expr.Compile(value, exprhelpers.GetExprOptions(map[string]interface{}{
73-
"evt": &types.Event{},
74-
"match": &types.MatchedRule{},
73+
"evt": &pipeline.Event{},
74+
"match": &pipeline.MatchedRule{},
7575
"req": &http.Request{},
7676
})...)
7777
if err != nil {
@@ -144,13 +144,13 @@ func TruncateContext(values []string, contextValueLen int) (string, error) {
144144
return ret, nil
145145
}
146146

147-
func EvalAlertContextRules(evt types.Event, match *types.MatchedRule, request *http.Request, tmpContext map[string][]string) []error {
147+
func EvalAlertContextRules(evt pipeline.Event, match *pipeline.MatchedRule, request *http.Request, tmpContext map[string][]string) []error {
148148
var errors []error
149149

150150
// if we're evaluating context for appsec event, match and request will be present.
151151
// otherwise, only evt will be.
152152
if match == nil {
153-
match = types.NewMatchedRule()
153+
match = pipeline.NewMatchedRule()
154154
}
155155

156156
if request == nil {
@@ -212,12 +212,12 @@ func EvalAlertContextRules(evt types.Event, match *types.MatchedRule, request *h
212212
}
213213

214214
// Iterate over the individual appsec matched rules to create the needed alert context.
215-
func AppsecEventToContext(event types.AppsecEvent, request *http.Request) (models.Meta, []error) {
215+
func AppsecEventToContext(event pipeline.AppsecEvent, request *http.Request) (models.Meta, []error) {
216216
var errors []error
217217

218218
tmpContext := make(map[string][]string)
219219

220-
evt := types.MakeEvent(false, types.LOG, false)
220+
evt := pipeline.MakeEvent(false, pipeline.LOG, false)
221221
for _, matched_rule := range event.MatchedRules {
222222
tmpErrors := EvalAlertContextRules(evt, &matched_rule, request, tmpContext)
223223
errors = append(errors, tmpErrors...)
@@ -232,7 +232,7 @@ func AppsecEventToContext(event types.AppsecEvent, request *http.Request) (model
232232
}
233233

234234
// Iterate over the individual events to create the needed alert context.
235-
func EventToContext(events []types.Event) (models.Meta, []error) {
235+
func EventToContext(events []pipeline.Event) (models.Meta, []error) {
236236
var errors []error
237237

238238
tmpContext := make(map[string][]string)

pkg/alertcontext/alertcontext_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/crowdsecurity/go-cs-lib/ptr"
1212

1313
"github.com/crowdsecurity/crowdsec/pkg/models"
14-
"github.com/crowdsecurity/crowdsec/pkg/types"
14+
"github.com/crowdsecurity/crowdsec/pkg/pipeline"
1515
)
1616

1717
func TestNewAlertContext(t *testing.T) {
@@ -43,7 +43,7 @@ func TestEventToContext(t *testing.T) {
4343
name string
4444
contextToSend map[string][]string
4545
valueLength int
46-
events []types.Event
46+
events []pipeline.Event
4747
expectedResult models.Meta
4848
}{
4949
{
@@ -53,7 +53,7 @@ func TestEventToContext(t *testing.T) {
5353
"nonexistent_field": {"evt.Parsed.nonexist"},
5454
},
5555
valueLength: 100,
56-
events: []types.Event{
56+
events: []pipeline.Event{
5757
{
5858
Parsed: map[string]string{
5959
"source_ip": "1.2.3.4",
@@ -76,7 +76,7 @@ func TestEventToContext(t *testing.T) {
7676
"cve": {"evt.Parsed.cve"},
7777
},
7878
valueLength: 100,
79-
events: []types.Event{
79+
events: []pipeline.Event{
8080
{
8181
Parsed: map[string]string{
8282
"source_ip": "1.2.3.4",
@@ -122,7 +122,7 @@ func TestEventToContext(t *testing.T) {
122122
"uri": {"evt.Parsed.uri"},
123123
},
124124
valueLength: 100,
125-
events: []types.Event{
125+
events: []pipeline.Event{
126126
{
127127
Parsed: map[string]string{
128128
"source_ip": "1.2.3.4",
@@ -168,7 +168,7 @@ func TestEventToContext(t *testing.T) {
168168
"uri": {"evt.Parsed.uri"},
169169
},
170170
valueLength: 100,
171-
events: []types.Event{
171+
events: []pipeline.Event{
172172
{
173173
Parsed: map[string]string{
174174
"source_ip": "1.2.3.4",
@@ -244,7 +244,7 @@ func TestAppsecEventToContext(t *testing.T) {
244244
tests := []struct {
245245
name string
246246
contextToSend map[string][]string
247-
match types.AppsecEvent
247+
match pipeline.AppsecEvent
248248
req *http.Request
249249
expectedResult models.Meta
250250
expectedErrLen int
@@ -254,8 +254,8 @@ func TestAppsecEventToContext(t *testing.T) {
254254
contextToSend: map[string][]string{
255255
"id": {"match.id"},
256256
},
257-
match: types.AppsecEvent{
258-
MatchedRules: types.MatchedRules{
257+
match: pipeline.AppsecEvent{
258+
MatchedRules: pipeline.MatchedRules{
259259
{
260260
"id": "test",
261261
},
@@ -275,8 +275,8 @@ func TestAppsecEventToContext(t *testing.T) {
275275
contextToSend: map[string][]string{
276276
"ua": {"req.UserAgent()"},
277277
},
278-
match: types.AppsecEvent{
279-
MatchedRules: types.MatchedRules{
278+
match: pipeline.AppsecEvent{
279+
MatchedRules: pipeline.MatchedRules{
280280
{
281281
"id": "test",
282282
},
@@ -300,8 +300,8 @@ func TestAppsecEventToContext(t *testing.T) {
300300
contextToSend: map[string][]string{
301301
"foobarxx": {"req.Header.Values('Foobar')"},
302302
},
303-
match: types.AppsecEvent{
304-
MatchedRules: types.MatchedRules{
303+
match: pipeline.AppsecEvent{
304+
MatchedRules: pipeline.MatchedRules{
305305
{
306306
"id": "test",
307307
},
@@ -326,8 +326,8 @@ func TestAppsecEventToContext(t *testing.T) {
326326
contextToSend: map[string][]string{
327327
"foobarxx": {"len(req.Header.Values('Foobar'))"},
328328
},
329-
match: types.AppsecEvent{
330-
MatchedRules: types.MatchedRules{
329+
match: pipeline.AppsecEvent{
330+
MatchedRules: pipeline.MatchedRules{
331331
{
332332
"id": "test",
333333
},
@@ -352,8 +352,8 @@ func TestAppsecEventToContext(t *testing.T) {
352352
contextToSend: map[string][]string{
353353
"ja4h": {"JA4H(req)"},
354354
},
355-
match: types.AppsecEvent{
356-
MatchedRules: types.MatchedRules{
355+
match: pipeline.AppsecEvent{
356+
MatchedRules: pipeline.MatchedRules{
357357
{
358358
"id": "test",
359359
},
@@ -404,8 +404,8 @@ func TestEvalAlertContextRules(t *testing.T) {
404404
tests := []struct {
405405
name string
406406
contextToSend map[string][]string
407-
event types.Event
408-
match types.MatchedRule
407+
event pipeline.Event
408+
match pipeline.MatchedRule
409409
req *http.Request
410410
expectedResult map[string][]string
411411
expectedErrLen int
@@ -416,7 +416,7 @@ func TestEvalAlertContextRules(t *testing.T) {
416416
"source_ip": {"evt.Parsed.source_ip"},
417417
"id": {"match.id"},
418418
},
419-
event: types.Event{
419+
event: pipeline.Event{
420420
Parsed: map[string]string{
421421
"source_ip": "1.2.3.4",
422422
"source_machine": "mymachine",

pkg/appsec/appsec.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
1515
"github.com/crowdsecurity/crowdsec/pkg/exprhelpers"
16-
"github.com/crowdsecurity/crowdsec/pkg/types"
16+
"github.com/crowdsecurity/crowdsec/pkg/pipeline"
1717
)
1818

1919
type Hook struct {
@@ -49,7 +49,7 @@ func (h *Hook) Build(hookStage int) error {
4949
case hookPostEval:
5050
ctx = GetPostEvalEnv(&AppsecRuntimeConfig{}, &ParsedRequest{})
5151
case hookOnMatch:
52-
ctx = GetOnMatchEnv(&AppsecRuntimeConfig{}, &ParsedRequest{}, types.Event{})
52+
ctx = GetOnMatchEnv(&AppsecRuntimeConfig{}, &ParsedRequest{}, pipeline.Event{})
5353
}
5454

5555
opts := exprhelpers.GetExprOptions(ctx)
@@ -445,7 +445,7 @@ func (w *AppsecRuntimeConfig) ProcessOnLoadRules() error {
445445
return nil
446446
}
447447

448-
func (w *AppsecRuntimeConfig) ProcessOnMatchRules(request *ParsedRequest, evt types.Event) error {
448+
func (w *AppsecRuntimeConfig) ProcessOnMatchRules(request *ParsedRequest, evt pipeline.Event) error {
449449
has_match := false
450450

451451
for _, rule := range w.CompiledOnMatch {

0 commit comments

Comments
 (0)