Skip to content

Commit

Permalink
Add support for {env.<variable.} replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
hslatman committed Nov 12, 2023
1 parent 50f68af commit 4b81e8d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions crowdsec/crowdsec.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ func (c *CrowdSec) configure() error {
c.EnableStreaming = &cfg.EnableStreaming
c.EnableHardFails = &cfg.EnableHardFails
}

repl := caddy.NewReplacer() // create replacer with the default, global replacement functions, including ".env" env var reading
c.APIUrl = repl.ReplaceKnown(c.APIUrl, "")
c.APIKey = repl.ReplaceKnown(c.APIKey, "")

s := c.APIUrl
u, err := url.Parse(s)
if err != nil {
Expand Down Expand Up @@ -167,6 +172,10 @@ func (c *CrowdSec) Validate() error {

// TODO: fail hard after provisioning is not correct? Or do it in provisioning already?

if c.APIKey == "" {
return errors.New("crowdsec API Key must not be empty")
}

if c.bouncer == nil {
return errors.New("bouncer instance not available due to (potential) misconfiguration")
}
Expand Down
3 changes: 2 additions & 1 deletion internal/bouncer/bouncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"go.uber.org/zap/zapcore"
)

const version = "v0.5.2"
const maxNumberOfDecisionsToLog = 10

// Bouncer is a custom CrowdSec bouncer backed by an immutable radix tree
Expand All @@ -44,7 +45,7 @@ type Bouncer struct {
// New creates a new (streaming) Bouncer with a storage based on immutable radix tree
// TODO: take a configuration struct instead, because more options will be added.
func New(apiKey, apiURL, tickerInterval string, logger *zap.Logger) (*Bouncer, error) {
userAgent := "caddy-cs-bouncer/v0.3.2"
userAgent := fmt.Sprintf("caddy-cs-bouncer/%s", version)
insecureSkipVerify := false
return &Bouncer{
streamingBouncer: &csbouncer.StreamBouncer{
Expand Down

0 comments on commit 4b81e8d

Please sign in to comment.