Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Sep 20, 2024
1 parent d19761b commit e3d68a8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cmd/crowdsec-cli/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ package main
import (
"github.com/spf13/cobra"

"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/clisetup"
"github.com/crowdsecurity/crowdsec/pkg/cwversion/component"
"github.com/crowdsecurity/crowdsec/pkg/fflag"
"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/clisetup"
)

func (cli *cliRoot) addSetup(cmd *cobra.Command) {
if fflag.CscliSetup.IsEnabled() {
cmd.AddCommand(clisetup.New(cli.cfg).NewCommand())
}

Check warning on line 15 in cmd/crowdsec-cli/setup.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec-cli/setup.go#L15

Added line #L15 was not covered by tests

component.Register("cscli_setup")
}
17 changes: 15 additions & 2 deletions pkg/acquisition/acquisition.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type DataSource interface {
var (
// We declare everything here so we can tell if they are unsupported, or excluded from the build
AcquisitionSources = map[string]func() DataSource{}
transformRuntimes = map[string]*vm.Program{}
transformRuntimes = map[string]*vm.Program{}
)

func GetDataSourceIface(dataSourceType string) (DataSource, error) {
Expand All @@ -82,7 +82,8 @@ func GetDataSourceIface(dataSourceType string) (DataSource, error) {
// It must be called in the init() function of the datasource package, and the datasource name
// must be declared with a nil value in the map, to allow for conditional compilation.
func registerDataSource(dataSourceType string, dsGetter func() DataSource) {
component.Register("datasource_"+dataSourceType)
component.Register("datasource_" + dataSourceType)

AcquisitionSources[dataSourceType] = dsGetter
}

Expand Down Expand Up @@ -204,16 +205,19 @@ func GetMetricsLevelFromPromCfg(prom *csconfig.PrometheusCfg) int {
if prom == nil {
return configuration.METRICS_FULL
}

if !prom.Enabled {
return configuration.METRICS_NONE
}

if prom.Level == configuration.CFG_METRICS_AGGREGATE {
return configuration.METRICS_AGGREGATE
}

if prom.Level == configuration.CFG_METRICS_FULL {
return configuration.METRICS_FULL
}

return configuration.METRICS_FULL
}

Expand All @@ -222,15 +226,20 @@ func LoadAcquisitionFromFile(config *csconfig.CrowdsecServiceCfg, prom *csconfig
var sources []DataSource

metrics_level := GetMetricsLevelFromPromCfg(prom)

for _, acquisFile := range config.AcquisitionFiles {
log.Infof("loading acquisition file : %s", acquisFile)

yamlFile, err := os.Open(acquisFile)
if err != nil {
return nil, err
}

dec := yaml.NewDecoder(yamlFile)
dec.SetStrict(true)

idx := -1

for {
var sub configuration.DataSourceCommonCfg
err = dec.Decode(&sub)
Expand All @@ -239,7 +248,9 @@ func LoadAcquisitionFromFile(config *csconfig.CrowdsecServiceCfg, prom *csconfig
if !errors.Is(err, io.EOF) {
return nil, fmt.Errorf("failed to yaml decode %s: %w", acquisFile, err)
}

log.Tracef("End of yaml file")

break
}

Expand All @@ -253,11 +264,13 @@ func LoadAcquisitionFromFile(config *csconfig.CrowdsecServiceCfg, prom *csconfig
log.Debugf("skipping empty item in %s", acquisFile)
continue
}

if sub.Source != "docker" {
// docker is the only source that can be empty
return nil, fmt.Errorf("missing labels in %s (position: %d)", acquisFile, idx)
}
}

if sub.Source == "" {
return nil, fmt.Errorf("data source type is empty ('source') in %s (position: %d)", acquisFile, idx)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cwversion/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Register(name string) {
if _, ok := Built[name]; !ok {
// having a list of the disabled components is essential
// to debug users' issues
panic("cannot register unknown compile-time component: "+name)
panic("cannot register unknown compile-time component: " + name)

Check warning on line 30 in pkg/cwversion/component/component.go

View check run for this annotation

Codecov / codecov/patch

pkg/cwversion/component/component.go#L28-L30

Added lines #L28 - L30 were not covered by tests
}

Built[name] = true
Expand Down

0 comments on commit e3d68a8

Please sign in to comment.