Skip to content

Commit

Permalink
cscli refact: package cliitem
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Aug 29, 2024
1 parent 0fb6468 commit b5d4adb
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package cliitem

import (
"fmt"
Expand All @@ -13,7 +13,7 @@ import (
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
)

func NewCLIAppsecConfig(cfg configGetter) *cliItem {
func NewAppsecConfig(cfg configGetter) *cliItem {

Check warning on line 16 in cmd/crowdsec-cli/cliitem/appsec.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec-cli/cliitem/appsec.go#L16

Added line #L16 was not covered by tests
return &cliItem{
cfg: cfg,
name: cwhub.APPSEC_CONFIGS,
Expand Down Expand Up @@ -47,7 +47,7 @@ cscli appsec-configs list crowdsecurity/vpatch`,
}
}

func NewCLIAppsecRule(cfg configGetter) *cliItem {
func NewAppsecRule(cfg configGetter) *cliItem {

Check warning on line 50 in cmd/crowdsec-cli/cliitem/appsec.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec-cli/cliitem/appsec.go#L50

Added line #L50 was not covered by tests
inspectDetail := func(item *cwhub.Item) error {
// Only show the converted rules in human mode
if cfg().Cscli.Output != "human" {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main
package cliitem

import (
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
)

func NewCLICollection(cfg configGetter) *cliItem {
func NewCollection(cfg configGetter) *cliItem {

Check warning on line 7 in cmd/crowdsec-cli/cliitem/collection.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec-cli/cliitem/collection.go#L7

Added line #L7 was not covered by tests
return &cliItem{
cfg: cfg,
name: cwhub.COLLECTIONS,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main
package cliitem

import (
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
)

func NewCLIContext(cfg configGetter) *cliItem {
func NewContext(cfg configGetter) *cliItem {

Check warning on line 7 in cmd/crowdsec-cli/cliitem/context.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec-cli/cliitem/context.go#L7

Added line #L7 was not covered by tests
return &cliItem{
cfg: cfg,
name: cwhub.CONTEXTS,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main
package cliitem

import (
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
)

func NewCLIScenario(cfg configGetter) *cliItem {
func NewScenario(cfg configGetter) *cliItem {

Check warning on line 7 in cmd/crowdsec-cli/cliitem/hubscenario.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec-cli/cliitem/hubscenario.go#L7

Added line #L7 was not covered by tests
return &cliItem{
cfg: cfg,
name: cwhub.SCENARIOS,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package cliitem

import (
"cmp"
Expand All @@ -18,6 +18,7 @@ import (
"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/clihub"
"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/reload"
"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/require"
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
)

Expand All @@ -30,6 +31,8 @@ type cliHelp struct {
example string
}

type configGetter func() *csconfig.Config

type cliItem struct {
cfg configGetter
name string // plural, as used in the hub index
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main
package cliitem

import (
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
)

func NewCLIParser(cfg configGetter) *cliItem {
func NewParser(cfg configGetter) *cliItem {

Check warning on line 7 in cmd/crowdsec-cli/cliitem/parser.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec-cli/cliitem/parser.go#L7

Added line #L7 was not covered by tests
return &cliItem{
cfg: cfg,
name: cwhub.PARSERS,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main
package cliitem

import (
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
)

func NewCLIPostOverflow(cfg configGetter) *cliItem {
func NewPostOverflow(cfg configGetter) *cliItem {

Check warning on line 7 in cmd/crowdsec-cli/cliitem/postoverflow.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec-cli/cliitem/postoverflow.go#L7

Added line #L7 was not covered by tests
return &cliItem{
cfg: cfg,
name: cwhub.POSTOVERFLOWS,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package cliitem

import (
"fmt"
Expand Down
15 changes: 8 additions & 7 deletions cmd/crowdsec-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/cliexplain"
"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/clihub"
"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/clihubtest"
"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/cliitem"
"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/clilapi"
"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/climachine"
"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/climetrics"
Expand Down Expand Up @@ -270,13 +271,13 @@ It is meant to allow you to manage bans, parsers/scenarios/etc, api and generall
cmd.AddCommand(clinotifications.New(cli.cfg).NewCommand())
cmd.AddCommand(clisupport.New(cli.cfg).NewCommand())
cmd.AddCommand(clipapi.New(cli.cfg).NewCommand())
cmd.AddCommand(NewCLICollection(cli.cfg).NewCommand())
cmd.AddCommand(NewCLIParser(cli.cfg).NewCommand())
cmd.AddCommand(NewCLIScenario(cli.cfg).NewCommand())
cmd.AddCommand(NewCLIPostOverflow(cli.cfg).NewCommand())
cmd.AddCommand(NewCLIContext(cli.cfg).NewCommand())
cmd.AddCommand(NewCLIAppsecConfig(cli.cfg).NewCommand())
cmd.AddCommand(NewCLIAppsecRule(cli.cfg).NewCommand())
cmd.AddCommand(cliitem.NewCollection(cli.cfg).NewCommand())
cmd.AddCommand(cliitem.NewParser(cli.cfg).NewCommand())
cmd.AddCommand(cliitem.NewScenario(cli.cfg).NewCommand())
cmd.AddCommand(cliitem.NewPostOverflow(cli.cfg).NewCommand())
cmd.AddCommand(cliitem.NewContext(cli.cfg).NewCommand())
cmd.AddCommand(cliitem.NewAppsecConfig(cli.cfg).NewCommand())
cmd.AddCommand(cliitem.NewAppsecRule(cli.cfg).NewCommand())

Check warning on line 280 in cmd/crowdsec-cli/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec-cli/main.go#L274-L280

Added lines #L274 - L280 were not covered by tests

if fflag.CscliSetup.IsEnabled() {
cmd.AddCommand(clisetup.New(cli.cfg).NewCommand())
Expand Down

0 comments on commit b5d4adb

Please sign in to comment.