Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 8 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"bytes"
"context"
"flag"
"fmt"
Expand All @@ -10,6 +9,7 @@ import (
"os"
"os/exec"
"os/signal"
"strings"
"syscall"
"time"

Expand All @@ -21,6 +21,7 @@ import (

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

"github.com/crowdsecurity/cs-custom-bouncer/pkg/cfg"
Expand Down Expand Up @@ -133,17 +134,19 @@ func Execute() error {
return fmt.Errorf("configuration file is required")
}

configBytes, err := cfg.MergedConfig(*configPath)
configMerged, err := cfg.MergedConfig(*configPath)
if err != nil {
return fmt.Errorf("unable to read config file: %w", err)
}

if *showConfig {
fmt.Println(string(configBytes))
fmt.Println(string(configMerged))
return nil
}

config, err := cfg.NewConfig(bytes.NewReader(configBytes))
configExpanded := csstring.StrictExpand(string(configMerged), os.LookupEnv)

config, err := cfg.NewConfig(strings.NewReader(configExpanded))
if err != nil {
return fmt.Errorf("unable to load configuration: %w", err)
}
Expand Down Expand Up @@ -173,7 +176,7 @@ func Execute() error {
bouncer := &csbouncer.StreamBouncer{}
bouncer.UserAgent = fmt.Sprintf("%s/%s", name, version.String())

err = bouncer.ConfigReader(bytes.NewReader(configBytes))
err = bouncer.ConfigReader(strings.NewReader(configExpanded))
if err != nil {
return fmt.Errorf("unable to configure bouncer: %w", err)
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"

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

Expand Down Expand Up @@ -55,9 +54,7 @@ func NewConfig(reader io.Reader) (*BouncerConfig, error) {
return &BouncerConfig{}, err
}

configBuff := csstring.StrictExpand(string(fcontent), os.LookupEnv)

err = yaml.Unmarshal([]byte(configBuff), &config)
err = yaml.Unmarshal(fcontent, &config)
if err != nil {
return &BouncerConfig{}, fmt.Errorf("failed to unmarshal: %w", err)
}
Expand Down