-
Notifications
You must be signed in to change notification settings - Fork 11
/
stream_bouncer_test.go
68 lines (54 loc) · 1.73 KB
/
stream_bouncer_test.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
package csbouncer_test
import (
"context"
"fmt"
"log"
csbouncer "github.com/crowdsecurity/go-cs-bouncer"
)
func ExampleStreamBouncer() {
bouncer := &csbouncer.StreamBouncer{
APIKey: "ebd4db481d51525fd0df924a69193921",
APIUrl: "http://localhost:8080/",
}
if err := bouncer.Init(); err != nil {
log.Fatal(err.Error())
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go func() {
bouncer.Run(ctx)
cancel()
}()
for streamDecision := range bouncer.Stream {
for _, decision := range streamDecision.Deleted {
fmt.Printf("expired decisions: IP: %s | Scenario: %s | Duration: %s | Scope : %v\n", *decision.Value, *decision.Scenario, *decision.Duration, *decision.Scope)
}
for _, decision := range streamDecision.New {
fmt.Printf("new decisions: IP: %s | Scenario: %s | Duration: %s | Scope : %v\n", *decision.Value, *decision.Scenario, *decision.Duration, *decision.Scope)
}
}
}
func ExampleStreamBouncer_Config() {
bouncer := &csbouncer.StreamBouncer{}
err := bouncer.Config("./config.yaml")
if err != nil {
log.Fatal(err)
}
if err := bouncer.Init(); err != nil {
log.Fatal(err.Error())
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go func() {
bouncer.Run(ctx)
cancel()
}()
for streamDecision := range bouncer.Stream {
for _, decision := range streamDecision.Deleted {
fmt.Printf("expired decisions: IP: %s | Scenario: %s | Duration: %s | Scope : %v\n", *decision.Value, *decision.Scenario, *decision.Duration, *decision.Scope)
}
for _, decision := range streamDecision.New {
fmt.Printf("new decisions: IP: %s | Scenario: %s | Duration: %s | Scope : %v\n", *decision.Value, *decision.Scenario, *decision.Duration, *decision.Scope)
}
}
}