11package cmd
22
33import (
4- "bytes"
54 "context"
5+ "errors"
66 "flag"
77 "fmt"
88 "net"
99 "net/http"
1010 "os"
1111 "os/exec"
1212 "os/signal"
13+ "strings"
1314 "syscall"
1415 "time"
1516
@@ -21,6 +22,7 @@ import (
2122
2223 "github.com/crowdsecurity/crowdsec/pkg/models"
2324 csbouncer "github.com/crowdsecurity/go-cs-bouncer"
25+ "github.com/crowdsecurity/go-cs-lib/csstring"
2426 "github.com/crowdsecurity/go-cs-lib/version"
2527
2628 "github.com/crowdsecurity/cs-custom-bouncer/pkg/cfg"
@@ -44,9 +46,9 @@ func HandleSignals(ctx context.Context) error {
4446 case s := <- signalChan :
4547 switch s {
4648 case syscall .SIGTERM :
47- return fmt . Errorf ("received SIGTERM" )
49+ return errors . New ("received SIGTERM" )
4850 case os .Interrupt : // cross-platform SIGINT
49- return fmt . Errorf ("received interrupt" )
51+ return errors . New ("received interrupt" )
5052 }
5153 case <- ctx .Done ():
5254 return ctx .Err ()
@@ -111,7 +113,7 @@ func feedViaStdin(ctx context.Context, custom *custom.CustomBouncer, config *cfg
111113 log .Errorf ("Binary exited (retry %d/%d): %s" , i , config .TotalRetries , err )
112114 }
113115 }
114- return fmt . Errorf ("maximum retries exceeded for binary. Exiting" )
116+ return errors . New ("maximum retries exceeded for binary. Exiting" )
115117}
116118
117119func Execute () error {
@@ -130,20 +132,22 @@ func Execute() error {
130132 }
131133
132134 if configPath == nil || * configPath == "" {
133- return fmt . Errorf ("configuration file is required" )
135+ return errors . New ("configuration file is required" )
134136 }
135137
136- configBytes , err := cfg .MergedConfig (* configPath )
138+ configMerged , err := cfg .MergedConfig (* configPath )
137139 if err != nil {
138140 return fmt .Errorf ("unable to read config file: %w" , err )
139141 }
140142
141143 if * showConfig {
142- fmt .Println (string (configBytes ))
144+ fmt .Println (string (configMerged ))
143145 return nil
144146 }
145147
146- config , err := cfg .NewConfig (bytes .NewReader (configBytes ))
148+ configExpanded := csstring .StrictExpand (string (configMerged ), os .LookupEnv )
149+
150+ config , err := cfg .NewConfig (strings .NewReader (configExpanded ))
147151 if err != nil {
148152 return fmt .Errorf ("unable to load configuration: %w" , err )
149153 }
@@ -173,7 +177,7 @@ func Execute() error {
173177 bouncer := & csbouncer.StreamBouncer {}
174178 bouncer .UserAgent = fmt .Sprintf ("%s/%s" , name , version .String ())
175179
176- err = bouncer .ConfigReader (bytes .NewReader (configBytes ))
180+ err = bouncer .ConfigReader (strings .NewReader (configExpanded ))
177181 if err != nil {
178182 return fmt .Errorf ("unable to configure bouncer: %w" , err )
179183 }
@@ -187,7 +191,7 @@ func Execute() error {
187191
188192 g .Go (func () error {
189193 bouncer .Run (ctx )
190- return fmt . Errorf ("bouncer stream halted" )
194+ return errors . New ("bouncer stream halted" )
191195 })
192196
193197 if config .PrometheusConfig .Enabled {
0 commit comments