Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use go-cs-lib #68

Merged
merged 2 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ GOBUILD=$(GOCMD) build
GOTEST=$(GOCMD) test

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

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

LD_OPTS_VARS=\
-X '$(GO_MODULE_NAME)/pkg/version.Version=$(BUILD_VERSION)' \
-X '$(GO_MODULE_NAME)/pkg/version.BuildDate=$(BUILD_TIMESTAMP)' \
-X '$(GO_MODULE_NAME)/pkg/version.Tag=$(BUILD_TAG)'
-X 'github.com/crowdsecurity/go-cs-lib/pkg/version.Version=$(BUILD_VERSION)' \
-X 'github.com/crowdsecurity/go-cs-lib/pkg/version.BuildDate=$(BUILD_TIMESTAMP)' \
-X 'github.com/crowdsecurity/go-cs-lib/pkg/version.Tag=$(BUILD_TAG)'

export CGO_ENABLED=0
export LD_OPTS=-ldflags "-a -s -w -extldflags '-static' $(LD_OPTS_VARS)" \
Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[packages]
exceptiongroup = "1.1.1"
pexpect = "4.8.0"
pytest-cs = {ref = "0.7.15", git = "https://github.com/crowdsecurity/pytest-cs.git"}
pytest-cs = {ref = "0.7.16", git = "https://github.com/crowdsecurity/pytest-cs.git"}
pytest-dependency = "0.5.1"
pytest-dotenv = "0.5.2"
zxcvbn = "4.4.28"
Expand Down
6 changes: 3 additions & 3 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import (
log "github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"

"github.com/crowdsecurity/go-cs-lib/pkg/version"
"github.com/crowdsecurity/crowdsec/pkg/models"
csbouncer "github.com/crowdsecurity/go-cs-bouncer"

"github.com/crowdsecurity/cs-custom-bouncer/pkg/cfg"
"github.com/crowdsecurity/cs-custom-bouncer/pkg/custom"
"github.com/crowdsecurity/cs-custom-bouncer/pkg/version"
)

const (
Expand Down Expand Up @@ -128,7 +128,7 @@ func Execute() error {
flag.Parse()

if *bouncerVersion {
fmt.Print(version.ShowStr())
fmt.Print(version.FullString())
return nil
}

Expand Down Expand Up @@ -172,7 +172,7 @@ func Execute() error {
defer bouncerShutdown(custom)

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

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

g.Go(func() error {
bouncer.Run(ctx)
return fmt.Errorf("stream init failed")
return fmt.Errorf("bouncer stream halted")
})

if config.PrometheusConfig.Enabled {
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ require (
github.com/coreos/go-systemd/v22 v22.5.0
github.com/crowdsecurity/crowdsec v1.4.6
github.com/crowdsecurity/go-cs-bouncer v0.0.3
github.com/crowdsecurity/go-cs-lib v0.0.0-20230522124854-671e895fa788
github.com/prometheus/client_golang v1.14.0
github.com/sirupsen/logrus v1.9.0
github.com/sirupsen/logrus v1.9.2
golang.org/x/sync v0.1.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
gopkg.in/yaml.v2 v2.4.0
Expand Down Expand Up @@ -42,7 +43,7 @@ require (
github.com/prometheus/procfs v0.9.0 // indirect
go.mongodb.org/mongo-driver v1.11.2 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/sys v0.7.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
12 changes: 7 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ github.com/crowdsecurity/crowdsec v1.4.6 h1:KA1wcOGxfkxmapMIVUqT8KFYeOzbTRoWRIHh
github.com/crowdsecurity/crowdsec v1.4.6/go.mod h1:ZtSlyjECIVm8gOfd1FToQmGGwKiFM2SSDEGYp1QGOLQ=
github.com/crowdsecurity/go-cs-bouncer v0.0.3 h1:C3EFp2sJfSTLETZnVfkiHrJSnjO3ozMtT3LXNEsvfCw=
github.com/crowdsecurity/go-cs-bouncer v0.0.3/go.mod h1:Xa40z8girYJOuhiq16cPBKQgrQjHqs3Zbu+wJP9FjwM=
github.com/crowdsecurity/go-cs-lib v0.0.0-20230522124854-671e895fa788 h1:1tjqkYUmbkbYqa21kZsgSWaPIwGyUW0xE/sbb1zpJHg=
github.com/crowdsecurity/go-cs-lib v0.0.0-20230522124854-671e895fa788/go.mod h1:9JJLSpGj1ZXnROV3xAcJvS/HTaUvuA8K3gGOpO4tfVc=
github.com/crowdsecurity/grokky v0.1.0 h1:jLUzZd3vKxYrM4hQ8n5HWLfvs5ag4UP08eT9OTekI4U=
github.com/crowdsecurity/grokky v0.1.0/go.mod h1:fx5UYUYAFIrOUNAkFCUOM2wJcsp9EWSQE9R0/9kaFJg=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -152,8 +154,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/sirupsen/logrus v1.9.2 h1:oxx1eChJGI6Uks2ZC4W1zpLlVgqB8ner4EuQwV4Ik1Y=
github.com/sirupsen/logrus v1.9.2/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand All @@ -166,8 +168,8 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/vjeantet/grok v1.0.1 h1:2rhIR7J4gThTgcZ1m2JY4TrJZNgjn985U28kT2wQrJ4=
Expand Down Expand Up @@ -213,8 +215,8 @@ golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand Down
2 changes: 1 addition & 1 deletion pkg/cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"

"github.com/crowdsecurity/crowdsec/pkg/yamlpatch"
"github.com/crowdsecurity/go-cs-lib/pkg/yamlpatch"
)

type PrometheusConfig struct {
Expand Down
44 changes: 0 additions & 44 deletions pkg/cfg/fileperms.go

This file was deleted.

4 changes: 3 additions & 1 deletion pkg/cfg/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
log "github.com/sirupsen/logrus"
"github.com/sirupsen/logrus/hooks/writer"
"gopkg.in/natefinch/lumberjack.v2"

"github.com/crowdsecurity/go-cs-lib/pkg/logtools"
)

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

logPath, err := setLogFilePermissions(c.LogDir, fileName)
logPath, err := logtools.SetLogFilePermissions(c.LogDir, fileName)
if err != nil {
return nil, err
}
Expand Down
44 changes: 0 additions & 44 deletions pkg/version/version.go

This file was deleted.

4 changes: 2 additions & 2 deletions test/bouncer/test_custom_bouncer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_no_lapi(bouncer, cb_stream_cfg_factory):
cb.wait_for_lines_fnmatch([
"*connection refused*",
"*terminating bouncer process*",
"*stream init failed*",
"*bouncer stream halted*",
])


Expand All @@ -56,7 +56,7 @@ def test_bad_api_key(crowdsec, bouncer, cb_stream_cfg_factory):
"*Using API key auth*",
"*Processing new and deleted decisions . . .*",
"*auth-api: auth with api key failed return nil response, error*",
"*stream init failed*",
"*bouncer stream halted*",
])
cb.proc.wait(timeout=0.5)
assert not cb.proc.is_running()
Expand Down
2 changes: 1 addition & 1 deletion test/bouncer/test_yaml_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ def test_yaml_local(bouncer, cb_stream_cfg_factory):
cb.wait_for_lines_fnmatch([
"*connection refused*",
"*terminating bouncer process*",
"*stream init failed*",
"*bouncer stream halted*",
])