Skip to content

Commit f49f729

Browse files
authored
use go-cs-lib (#68)
1 parent 6429043 commit f49f729

12 files changed

+28
-112
lines changed

Makefile

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ GOBUILD=$(GOCMD) build
66
GOTEST=$(GOCMD) test
77

88
BINARY_NAME=crowdsec-custom-bouncer
9-
GO_MODULE_NAME=github.com/crowdsecurity/cs-custom-bouncer
109
TARBALL_NAME=$(BINARY_NAME).tgz
1110

1211
# Versioning information can be overridden in the environment
@@ -15,9 +14,9 @@ BUILD_TIMESTAMP?=$(shell date +%F"_"%T)
1514
BUILD_TAG?=$(shell git rev-parse HEAD)
1615

1716
LD_OPTS_VARS=\
18-
-X '$(GO_MODULE_NAME)/pkg/version.Version=$(BUILD_VERSION)' \
19-
-X '$(GO_MODULE_NAME)/pkg/version.BuildDate=$(BUILD_TIMESTAMP)' \
20-
-X '$(GO_MODULE_NAME)/pkg/version.Tag=$(BUILD_TAG)'
17+
-X 'github.com/crowdsecurity/go-cs-lib/pkg/version.Version=$(BUILD_VERSION)' \
18+
-X 'github.com/crowdsecurity/go-cs-lib/pkg/version.BuildDate=$(BUILD_TIMESTAMP)' \
19+
-X 'github.com/crowdsecurity/go-cs-lib/pkg/version.Tag=$(BUILD_TAG)'
2120

2221
export CGO_ENABLED=0
2322
export LD_OPTS=-ldflags "-a -s -w -extldflags '-static' $(LD_OPTS_VARS)" \

Pipfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[packages]
22
exceptiongroup = "1.1.1"
33
pexpect = "4.8.0"
4-
pytest-cs = {ref = "0.7.15", git = "https://github.com/crowdsecurity/pytest-cs.git"}
4+
pytest-cs = {ref = "0.7.16", git = "https://github.com/crowdsecurity/pytest-cs.git"}
55
pytest-dependency = "0.5.1"
66
pytest-dotenv = "0.5.2"
77
zxcvbn = "4.4.28"

Pipfile.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/root.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ import (
1919
log "github.com/sirupsen/logrus"
2020
"golang.org/x/sync/errgroup"
2121

22+
"github.com/crowdsecurity/go-cs-lib/pkg/version"
2223
"github.com/crowdsecurity/crowdsec/pkg/models"
2324
csbouncer "github.com/crowdsecurity/go-cs-bouncer"
2425

2526
"github.com/crowdsecurity/cs-custom-bouncer/pkg/cfg"
2627
"github.com/crowdsecurity/cs-custom-bouncer/pkg/custom"
27-
"github.com/crowdsecurity/cs-custom-bouncer/pkg/version"
2828
)
2929

3030
const (
@@ -128,7 +128,7 @@ func Execute() error {
128128
flag.Parse()
129129

130130
if *bouncerVersion {
131-
fmt.Print(version.ShowStr())
131+
fmt.Print(version.FullString())
132132
return nil
133133
}
134134

@@ -172,7 +172,7 @@ func Execute() error {
172172
defer bouncerShutdown(custom)
173173

174174
bouncer := &csbouncer.StreamBouncer{}
175-
bouncer.UserAgent = fmt.Sprintf("%s/%s", name, version.VersionStr())
175+
bouncer.UserAgent = fmt.Sprintf("%s/%s", name, version.String())
176176

177177
err = bouncer.ConfigReader(bytes.NewReader(configBytes))
178178
if err != nil {
@@ -188,7 +188,7 @@ func Execute() error {
188188

189189
g.Go(func() error {
190190
bouncer.Run(ctx)
191-
return fmt.Errorf("stream init failed")
191+
return fmt.Errorf("bouncer stream halted")
192192
})
193193

194194
if config.PrometheusConfig.Enabled {

go.mod

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ require (
66
github.com/coreos/go-systemd/v22 v22.5.0
77
github.com/crowdsecurity/crowdsec v1.4.6
88
github.com/crowdsecurity/go-cs-bouncer v0.0.3
9+
github.com/crowdsecurity/go-cs-lib v0.0.0-20230522124854-671e895fa788
910
github.com/prometheus/client_golang v1.14.0
10-
github.com/sirupsen/logrus v1.9.0
11+
github.com/sirupsen/logrus v1.9.2
1112
golang.org/x/sync v0.1.0
1213
gopkg.in/natefinch/lumberjack.v2 v2.2.1
1314
gopkg.in/yaml.v2 v2.4.0
@@ -42,7 +43,7 @@ require (
4243
github.com/prometheus/procfs v0.9.0 // indirect
4344
go.mongodb.org/mongo-driver v1.11.2 // indirect
4445
golang.org/x/net v0.8.0 // indirect
45-
golang.org/x/sys v0.6.0 // indirect
46+
golang.org/x/sys v0.7.0 // indirect
4647
google.golang.org/protobuf v1.28.1 // indirect
4748
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637 // indirect
4849
gopkg.in/yaml.v3 v3.0.1 // indirect

go.sum

+7-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ github.com/crowdsecurity/crowdsec v1.4.6 h1:KA1wcOGxfkxmapMIVUqT8KFYeOzbTRoWRIHh
1717
github.com/crowdsecurity/crowdsec v1.4.6/go.mod h1:ZtSlyjECIVm8gOfd1FToQmGGwKiFM2SSDEGYp1QGOLQ=
1818
github.com/crowdsecurity/go-cs-bouncer v0.0.3 h1:C3EFp2sJfSTLETZnVfkiHrJSnjO3ozMtT3LXNEsvfCw=
1919
github.com/crowdsecurity/go-cs-bouncer v0.0.3/go.mod h1:Xa40z8girYJOuhiq16cPBKQgrQjHqs3Zbu+wJP9FjwM=
20+
github.com/crowdsecurity/go-cs-lib v0.0.0-20230522124854-671e895fa788 h1:1tjqkYUmbkbYqa21kZsgSWaPIwGyUW0xE/sbb1zpJHg=
21+
github.com/crowdsecurity/go-cs-lib v0.0.0-20230522124854-671e895fa788/go.mod h1:9JJLSpGj1ZXnROV3xAcJvS/HTaUvuA8K3gGOpO4tfVc=
2022
github.com/crowdsecurity/grokky v0.1.0 h1:jLUzZd3vKxYrM4hQ8n5HWLfvs5ag4UP08eT9OTekI4U=
2123
github.com/crowdsecurity/grokky v0.1.0/go.mod h1:fx5UYUYAFIrOUNAkFCUOM2wJcsp9EWSQE9R0/9kaFJg=
2224
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -152,8 +154,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
152154
github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
153155
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
154156
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
155-
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
156-
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
157+
github.com/sirupsen/logrus v1.9.2 h1:oxx1eChJGI6Uks2ZC4W1zpLlVgqB8ner4EuQwV4Ik1Y=
158+
github.com/sirupsen/logrus v1.9.2/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
157159
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
158160
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
159161
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@@ -166,8 +168,8 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
166168
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
167169
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
168170
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
169-
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
170171
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
172+
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
171173
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
172174
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
173175
github.com/vjeantet/grok v1.0.1 h1:2rhIR7J4gThTgcZ1m2JY4TrJZNgjn985U28kT2wQrJ4=
@@ -213,8 +215,8 @@ golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7w
213215
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
214216
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
215217
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
216-
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
217-
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
218+
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
219+
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
218220
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
219221
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
220222
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=

pkg/cfg/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
log "github.com/sirupsen/logrus"
1010
"gopkg.in/yaml.v2"
1111

12-
"github.com/crowdsecurity/crowdsec/pkg/yamlpatch"
12+
"github.com/crowdsecurity/go-cs-lib/pkg/yamlpatch"
1313
)
1414

1515
type PrometheusConfig struct {

pkg/cfg/fileperms.go

-44
This file was deleted.

pkg/cfg/logging.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
log "github.com/sirupsen/logrus"
99
"github.com/sirupsen/logrus/hooks/writer"
1010
"gopkg.in/natefinch/lumberjack.v2"
11+
12+
"github.com/crowdsecurity/go-cs-lib/pkg/logtools"
1113
)
1214

1315
type LoggingConfig struct {
@@ -25,7 +27,7 @@ func (c *LoggingConfig) LoggerForFile(fileName string) (io.Writer, error) {
2527
return os.Stderr, nil
2628
}
2729

28-
logPath, err := setLogFilePermissions(c.LogDir, fileName)
30+
logPath, err := logtools.SetLogFilePermissions(c.LogDir, fileName)
2931
if err != nil {
3032
return nil, err
3133
}

pkg/version/version.go

-44
This file was deleted.

test/bouncer/test_custom_bouncer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_no_lapi(bouncer, cb_stream_cfg_factory):
4040
cb.wait_for_lines_fnmatch([
4141
"*connection refused*",
4242
"*terminating bouncer process*",
43-
"*stream init failed*",
43+
"*bouncer stream halted*",
4444
])
4545

4646

@@ -56,7 +56,7 @@ def test_bad_api_key(crowdsec, bouncer, cb_stream_cfg_factory):
5656
"*Using API key auth*",
5757
"*Processing new and deleted decisions . . .*",
5858
"*auth-api: auth with api key failed return nil response, error*",
59-
"*stream init failed*",
59+
"*bouncer stream halted*",
6060
])
6161
cb.proc.wait(timeout=0.5)
6262
assert not cb.proc.is_running()

test/bouncer/test_yaml_local.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ def test_yaml_local(bouncer, cb_stream_cfg_factory):
1818
cb.wait_for_lines_fnmatch([
1919
"*connection refused*",
2020
"*terminating bouncer process*",
21-
"*stream init failed*",
21+
"*bouncer stream halted*",
2222
])

0 commit comments

Comments
 (0)