Skip to content

Commit f0395c9

Browse files
committed
get client in StreamingAcquisition(), not Configure()
1 parent 8f24875 commit f0395c9

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

pkg/acquisition/modules/appsec/config.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
log "github.com/sirupsen/logrus"
1818

1919
"github.com/crowdsecurity/crowdsec/pkg/acquisition/configuration"
20-
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
2120
"github.com/crowdsecurity/crowdsec/pkg/apiclient/useragent"
2221
"github.com/crowdsecurity/crowdsec/pkg/appsec"
2322
"github.com/crowdsecurity/crowdsec/pkg/appsec/allowlists"
@@ -125,13 +124,6 @@ func (w *Source) Configure(_ context.Context, yamlConfig []byte, logger *log.Ent
125124
return errors.New("appsec datasource requires a lapi client configuration. this is a bug, please report")
126125
}
127126

128-
client, err := apiclient.GetLAPIClient()
129-
if err != nil {
130-
return fmt.Errorf("unable to get authenticated LAPI client: %w", err)
131-
}
132-
133-
w.lapiClient = client
134-
135127
if err := w.UnmarshalConfig(yamlConfig); err != nil {
136128
return fmt.Errorf("unable to parse appsec configuration: %w", err)
137129
}
@@ -167,16 +159,16 @@ func (w *Source) Configure(_ context.Context, yamlConfig []byte, logger *log.Ent
167159

168160
// let's load the associated appsec_config:
169161
if w.config.AppsecConfigPath != "" {
170-
if err = appsecCfg.LoadByPath(w.config.AppsecConfigPath); err != nil {
162+
if err := appsecCfg.LoadByPath(w.config.AppsecConfigPath); err != nil {
171163
return fmt.Errorf("unable to load appsec_config: %w", err)
172164
}
173165
} else if w.config.AppsecConfig != "" {
174-
if err = appsecCfg.Load(w.config.AppsecConfig, w.hub); err != nil {
166+
if err := appsecCfg.Load(w.config.AppsecConfig, w.hub); err != nil {
175167
return fmt.Errorf("unable to load appsec_config: %w", err)
176168
}
177169
} else if len(w.config.AppsecConfigs) > 0 {
178170
for _, appsecConfig := range w.config.AppsecConfigs {
179-
if err = appsecCfg.Load(appsecConfig, w.hub); err != nil {
171+
if err := appsecCfg.Load(appsecConfig, w.hub); err != nil {
180172
return fmt.Errorf("unable to load appsec_config: %w", err)
181173
}
182174
}
@@ -187,11 +179,13 @@ func (w *Source) Configure(_ context.Context, yamlConfig []byte, logger *log.Ent
187179
// Now we can set up the logger
188180
appsecCfg.SetUpLogger()
189181

190-
w.AppsecRuntime, err = appsecCfg.Build(w.hub)
182+
appsecRuntime, err := appsecCfg.Build(w.hub)
191183
if err != nil {
192184
return fmt.Errorf("unable to build appsec_config: %w", err)
193185
}
194186

187+
w.AppsecRuntime = appsecRuntime
188+
195189
err = w.AppsecRuntime.ProcessOnLoadRules()
196190
if err != nil {
197191
return fmt.Errorf("unable to process on load rules: %w", err)

pkg/acquisition/modules/appsec/run.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/crowdsecurity/go-cs-lib/trace"
1515

16+
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
1617
"github.com/crowdsecurity/crowdsec/pkg/appsec"
1718
"github.com/crowdsecurity/crowdsec/pkg/csnet"
1819
"github.com/crowdsecurity/crowdsec/pkg/pipeline"
@@ -119,7 +120,12 @@ func (w *Source) listenAndServe(ctx context.Context, t *tomb.Tomb) error {
119120
}
120121

121122
func (w *Source) StreamingAcquisition(ctx context.Context, out chan pipeline.Event, t *tomb.Tomb) error {
122-
err := w.appsecAllowlistClient.Start(ctx, w.lapiClient)
123+
lapiClient, err := apiclient.GetLAPIClient()
124+
if err != nil {
125+
return fmt.Errorf("unable to get authenticated LAPI client: %w", err)
126+
}
127+
128+
err = w.appsecAllowlistClient.Start(ctx, lapiClient)
123129
if err != nil {
124130
w.logger.Errorf("failed to fetch allowlists for appsec, disabling them: %s", err)
125131
} else {

pkg/acquisition/modules/appsec/source.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
log "github.com/sirupsen/logrus"
1010

11-
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
1211
"github.com/crowdsecurity/crowdsec/pkg/appsec"
1312
"github.com/crowdsecurity/crowdsec/pkg/appsec/allowlists"
1413
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
@@ -18,7 +17,6 @@ import (
1817
type Source struct {
1918
config Configuration
2019
hub *cwhub.Hub
21-
lapiClient *apiclient.ApiClient
2220
lapiClientConfig *csconfig.LocalApiClientCfg
2321
logger *log.Entry
2422
mux *http.ServeMux

test/bats/crowdsec-acquisition.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ teardown() {
138138
type: appsec
139139
EOT
140140

141-
config_set '.common.log_level="debug" | .common.log_media="stdout"'
141+
config_set '.common.log_media="stdout"'
142142

143143
rune -0 "$CROWDSEC" -t --trace
144144

0 commit comments

Comments
 (0)