File tree 3 files changed +50
-4
lines changed
3 files changed +50
-4
lines changed Original file line number Diff line number Diff line change @@ -27,18 +27,26 @@ import (
27
27
28
28
"github.com/crowdsecurity/crowdsec/pkg/models"
29
29
csbouncer "github.com/crowdsecurity/go-cs-bouncer"
30
+ "github.com/hslatman/caddy-crowdsec-bouncer/internal/version"
30
31
31
32
"go.uber.org/zap"
32
33
)
33
34
34
35
const (
35
- userAgentName = "caddy-cs-bouncer"
36
- userAgentVersion = "v0.8.0"
37
- userAgent = userAgentName + "/" + userAgentVersion
38
-
36
+ userAgentName = "caddy-cs-bouncer"
39
37
maxNumberOfDecisionsToLog = 10
40
38
)
41
39
40
+ var (
41
+ userAgent string
42
+ userAgentVersion string
43
+ )
44
+
45
+ func init () {
46
+ userAgentVersion = version .Current ()
47
+ userAgent = userAgentName + "/" + userAgentVersion
48
+ }
49
+
42
50
// Bouncer is a wrapper for a CrowdSec bouncer. It supports both the
43
51
// streaming and live bouncer implementations. The streaming bouncer is
44
52
// backed by an immutable radix tree storing known bad IPs and IP ranges.
Original file line number Diff line number Diff line change
1
+ package version
2
+
3
+ import (
4
+ "runtime/debug"
5
+ )
6
+
7
+ const (
8
+ modulePath = "github.com/hslatman/caddy-crowdsec-bouncer"
9
+ fallback = "v0.8.0"
10
+ )
11
+
12
+ func Current () string {
13
+ info , ok := debug .ReadBuildInfo ()
14
+ if ! ok {
15
+ return fallback
16
+ }
17
+
18
+ for _ , d := range info .Deps {
19
+ if d .Path == modulePath {
20
+ return d .Version
21
+ }
22
+ }
23
+
24
+ return fallback
25
+ }
Original file line number Diff line number Diff line change
1
+ package version
2
+
3
+ import (
4
+ "testing"
5
+
6
+ "github.com/stretchr/testify/assert"
7
+ )
8
+
9
+ func TestCurrent (t * testing.T ) {
10
+ v := Current ()
11
+
12
+ assert .Equal (t , "v0.8.0" , v ) // fallback
13
+ }
You can’t perform that action at this time.
0 commit comments