@@ -27,6 +27,7 @@ import (
2727
2828 "github.com/crowdsecurity/crowdsec/pkg/acquisition/configuration"
2929 "github.com/crowdsecurity/crowdsec/pkg/csconfig"
30+ "github.com/crowdsecurity/crowdsec/pkg/cwhub"
3031 "github.com/crowdsecurity/crowdsec/pkg/cwversion/component"
3132 "github.com/crowdsecurity/crowdsec/pkg/exprhelpers"
3233 "github.com/crowdsecurity/crowdsec/pkg/logging"
@@ -115,6 +116,14 @@ type DSNConfigurer interface {
115116 ConfigureByDSN (ctx context.Context , dsn string , labels map [string ]string , logger * log.Entry , uniqueID string ) error
116117}
117118
119+ type LAPIClientAware interface {
120+ SetClientConfig (config * csconfig.LocalApiClientCfg )
121+ }
122+
123+ type HubAware interface {
124+ SetHub (hub * cwhub.Hub )
125+ }
126+
118127var (
119128 // We register the datasources at init time so we can tell if they are unsupported, or excluded from the build
120129 AcquisitionSources = map [string ]func () DataSource {}
@@ -157,7 +166,7 @@ func registerDataSource(dataSourceType string, dsGetter func() DataSource) {
157166// if the configuration is not valid it returns an error.
158167// If the datasource can't be run (eg. journalctl not available), it still returns an error which
159168// can be checked for the appropriate action.
160- func DataSourceConfigure (ctx context.Context , commonConfig configuration.DataSourceCommonCfg , yamlConfig []byte , metricsLevel metrics.AcquisitionMetricsLevel ) (DataSource , error ) {
169+ func DataSourceConfigure (ctx context.Context , commonConfig configuration.DataSourceCommonCfg , yamlConfig []byte , metricsLevel metrics.AcquisitionMetricsLevel , hub * cwhub. Hub ) (DataSource , error ) {
161170 dataSrc , err := GetDataSourceIface (commonConfig .Source )
162171 if err != nil {
163172 return nil , err
@@ -177,6 +186,15 @@ func DataSourceConfigure(ctx context.Context, commonConfig configuration.DataSou
177186
178187 subLogger .Info ("Configuring datasource" )
179188
189+ if hubAware , ok := dataSrc .(HubAware ); ok {
190+ hubAware .SetHub (hub )
191+ }
192+
193+ if lapiClientAware , ok := dataSrc .(LAPIClientAware ); ok {
194+ cConfig := csconfig .GetConfig ()
195+ lapiClientAware .SetClientConfig (cConfig .API .Client )
196+ }
197+
180198 /* configure the actual datasource */
181199 if err := dataSrc .Configure (ctx , yamlConfig , subLogger , metricsLevel ); err != nil {
182200 return nil , err
@@ -185,7 +203,7 @@ func DataSourceConfigure(ctx context.Context, commonConfig configuration.DataSou
185203 return dataSrc , nil
186204}
187205
188- func LoadAcquisitionFromDSN (ctx context.Context , dsn string , labels map [string ]string , transformExpr string ) (DataSource , error ) {
206+ func LoadAcquisitionFromDSN (ctx context.Context , dsn string , labels map [string ]string , transformExpr string , hub * cwhub. Hub ) (DataSource , error ) {
189207 frags := strings .Split (dsn , ":" )
190208 if len (frags ) == 1 {
191209 return nil , fmt .Errorf ("%s is not a valid dsn (no protocol)" , dsn )
@@ -207,6 +225,15 @@ func LoadAcquisitionFromDSN(ctx context.Context, dsn string, labels map[string]s
207225 transformRuntimes [uniqueID ] = vm
208226 }
209227
228+ if hubAware , ok := dataSrc .(HubAware ); ok {
229+ hubAware .SetHub (hub )
230+ }
231+
232+ if lapiClientAware , ok := dataSrc .(LAPIClientAware ); ok {
233+ cConfig := csconfig .GetConfig ()
234+ lapiClientAware .SetClientConfig (cConfig .API .Client )
235+ }
236+
210237 dsnConf , ok := dataSrc .(DSNConfigurer )
211238 if ! ok {
212239 return nil , fmt .Errorf ("%s datasource does not support command-line acquisition" , frags [0 ])
@@ -272,7 +299,7 @@ func detectType(r io.Reader) (string, error) {
272299}
273300
274301// sourcesFromFile reads and parses one acquisition file into DataSources.
275- func sourcesFromFile (ctx context.Context , acquisFile string , metricsLevel metrics.AcquisitionMetricsLevel ) ([]DataSource , error ) {
302+ func sourcesFromFile (ctx context.Context , acquisFile string , metricsLevel metrics.AcquisitionMetricsLevel , hub * cwhub. Hub ) ([]DataSource , error ) {
276303 var sources []DataSource
277304
278305 log .Infof ("loading acquisition file : %s" , acquisFile )
@@ -356,7 +383,7 @@ func sourcesFromFile(ctx context.Context, acquisFile string, metricsLevel metric
356383 uniqueID := uuid .NewString ()
357384 sub .UniqueId = uniqueID
358385
359- src , err := DataSourceConfigure (ctx , sub , yamlDoc , metricsLevel )
386+ src , err := DataSourceConfigure (ctx , sub , yamlDoc , metricsLevel , hub )
360387 if err != nil {
361388 var dserr * DataSourceUnavailableError
362389 if errors .As (err , & dserr ) {
@@ -383,13 +410,13 @@ func sourcesFromFile(ctx context.Context, acquisFile string, metricsLevel metric
383410}
384411
385412// LoadAcquisitionFromFiles unmarshals the configuration item and checks its availability
386- func LoadAcquisitionFromFiles (ctx context.Context , config * csconfig.CrowdsecServiceCfg , prom * csconfig.PrometheusCfg ) ([]DataSource , error ) {
413+ func LoadAcquisitionFromFiles (ctx context.Context , config * csconfig.CrowdsecServiceCfg , prom * csconfig.PrometheusCfg , hub * cwhub. Hub ) ([]DataSource , error ) {
387414 var allSources []DataSource
388415
389416 metricsLevel := GetMetricsLevelFromPromCfg (prom )
390417
391418 for _ , acquisFile := range config .AcquisitionFiles {
392- sources , err := sourcesFromFile (ctx , acquisFile , metricsLevel )
419+ sources , err := sourcesFromFile (ctx , acquisFile , metricsLevel , hub )
393420 if err != nil {
394421 return nil , err
395422 }
0 commit comments