Skip to content

Commit

Permalink
remove dependencies on enescakir/emoji, gotest.tools (#2837)
Browse files Browse the repository at this point in the history
* wrap emoji package in pkg/emoji
* remove dependency on enescakir/emoji
* remove dependency on gotest.tools
* lint (whitespace)
  • Loading branch information
mmetc authored Feb 23, 2024
1 parent 4bf640c commit a23fe06
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 67 deletions.
10 changes: 4 additions & 6 deletions cmd/crowdsec-cli/bouncers_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"time"

"github.com/aquasecurity/table"
"github.com/enescakir/emoji"

"github.com/crowdsecurity/crowdsec/pkg/database/ent"
"github.com/crowdsecurity/crowdsec/pkg/emoji"
)

func getBouncersTable(out io.Writer, bouncers []*ent.Bouncer) {
Expand All @@ -17,11 +17,9 @@ func getBouncersTable(out io.Writer, bouncers []*ent.Bouncer) {
t.SetAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft, table.AlignLeft, table.AlignLeft, table.AlignLeft)

for _, b := range bouncers {
var revoked string
if !b.Revoked {
revoked = emoji.CheckMark.String()
} else {
revoked = emoji.Prohibited.String()
revoked := emoji.CheckMark
if b.Revoked {
revoked = emoji.Prohibited
}

t.AddRow(b.Name, b.IPAddress, revoked, b.LastPull.Format(time.RFC3339), b.Type, b.Version, b.AuthType)
Expand Down
14 changes: 7 additions & 7 deletions cmd/crowdsec-cli/console_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"io"

"github.com/aquasecurity/table"
"github.com/enescakir/emoji"

"github.com/crowdsecurity/crowdsec/pkg/csconfig"
"github.com/crowdsecurity/crowdsec/pkg/emoji"
)

func cmdConsoleStatusTable(out io.Writer, consoleCfg csconfig.ConsoleConfig) {
Expand All @@ -17,28 +17,28 @@ func cmdConsoleStatusTable(out io.Writer, consoleCfg csconfig.ConsoleConfig) {
t.SetHeaderAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft)

for _, option := range csconfig.CONSOLE_CONFIGS {
activated := string(emoji.CrossMark)
activated := emoji.CrossMark

switch option {
case csconfig.SEND_CUSTOM_SCENARIOS:
if *consoleCfg.ShareCustomScenarios {
activated = string(emoji.CheckMarkButton)
activated = emoji.CheckMarkButton
}
case csconfig.SEND_MANUAL_SCENARIOS:
if *consoleCfg.ShareManualDecisions {
activated = string(emoji.CheckMarkButton)
activated = emoji.CheckMarkButton
}
case csconfig.SEND_TAINTED_SCENARIOS:
if *consoleCfg.ShareTaintedScenarios {
activated = string(emoji.CheckMarkButton)
activated = emoji.CheckMarkButton
}
case csconfig.SEND_CONTEXT:
if *consoleCfg.ShareContext {
activated = string(emoji.CheckMarkButton)
activated = emoji.CheckMarkButton
}
case csconfig.CONSOLE_MANAGEMENT:
if *consoleCfg.ConsoleManagement {
activated = string(emoji.CheckMarkButton)
activated = emoji.CheckMarkButton
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/crowdsec-cli/hubtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
"text/template"

"github.com/AlecAivazis/survey/v2"
"github.com/enescakir/emoji"
"github.com/fatih/color"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"

"github.com/crowdsecurity/crowdsec/pkg/dumps"
"github.com/crowdsecurity/crowdsec/pkg/emoji"
"github.com/crowdsecurity/crowdsec/pkg/hubtest"
)

Expand Down
21 changes: 12 additions & 9 deletions cmd/crowdsec-cli/hubtest_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"io"

"github.com/aquasecurity/table"
"github.com/enescakir/emoji"

"github.com/crowdsecurity/crowdsec/pkg/emoji"
"github.com/crowdsecurity/crowdsec/pkg/hubtest"
)

Expand All @@ -17,9 +17,9 @@ func hubTestResultTable(out io.Writer, testResult map[string]bool) {
t.SetAlignment(table.AlignLeft)

for testName, success := range testResult {
status := emoji.CheckMarkButton.String()
status := emoji.CheckMarkButton
if !success {
status = emoji.CrossMark.String()
status = emoji.CrossMark
}

t.AddRow(testName, status)
Expand Down Expand Up @@ -50,11 +50,12 @@ func hubTestParserCoverageTable(out io.Writer, coverage []hubtest.Coverage) {
parserTested := 0

for _, test := range coverage {
status := emoji.RedCircle.String()
status := emoji.RedCircle
if test.TestsCount > 0 {
status = emoji.GreenCircle.String()
status = emoji.GreenCircle
parserTested++
}

t.AddRow(test.Name, status, fmt.Sprintf("%d times (across %d tests)", test.TestsCount, len(test.PresentIn)))
}

Expand All @@ -70,11 +71,12 @@ func hubTestAppsecRuleCoverageTable(out io.Writer, coverage []hubtest.Coverage)
parserTested := 0

for _, test := range coverage {
status := emoji.RedCircle.String()
status := emoji.RedCircle
if test.TestsCount > 0 {
status = emoji.GreenCircle.String()
status = emoji.GreenCircle
parserTested++
}

t.AddRow(test.Name, status, fmt.Sprintf("%d times (across %d tests)", test.TestsCount, len(test.PresentIn)))
}

Expand All @@ -90,11 +92,12 @@ func hubTestScenarioCoverageTable(out io.Writer, coverage []hubtest.Coverage) {
parserTested := 0

for _, test := range coverage {
status := emoji.RedCircle.String()
status := emoji.RedCircle
if test.TestsCount > 0 {
status = emoji.GreenCircle.String()
status = emoji.GreenCircle
parserTested++
}

t.AddRow(test.Name, status, fmt.Sprintf("%d times (across %d tests)", test.TestsCount, len(test.PresentIn)))
}

Expand Down
11 changes: 5 additions & 6 deletions cmd/crowdsec-cli/machines_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"time"

"github.com/aquasecurity/table"
"github.com/enescakir/emoji"

"github.com/crowdsecurity/crowdsec/pkg/database/ent"
"github.com/crowdsecurity/crowdsec/pkg/emoji"
)

func getAgentsTable(out io.Writer, machines []*ent.Machine) {
Expand All @@ -17,17 +17,16 @@ func getAgentsTable(out io.Writer, machines []*ent.Machine) {
t.SetAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft, table.AlignLeft, table.AlignLeft, table.AlignLeft, table.AlignLeft)

for _, m := range machines {
var validated string
validated := emoji.Prohibited
if m.IsValidated {
validated = emoji.CheckMark.String()
} else {
validated = emoji.Prohibited.String()
validated = emoji.CheckMark
}

hb, active := getLastHeartbeat(m)
if !active {
hb = emoji.Warning.String() + " " + hb
hb = emoji.Warning + " " + hb
}

t.AddRow(m.MachineId, m.IpAddress, m.UpdatedAt.Format(time.RFC3339), validated, m.Version, m.AuthType, hb)
}

Expand Down
14 changes: 11 additions & 3 deletions cmd/crowdsec-cli/notifications_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,40 @@ import (
"strings"

"github.com/aquasecurity/table"
"github.com/enescakir/emoji"

"github.com/crowdsecurity/crowdsec/pkg/emoji"
)

func notificationListTable(out io.Writer, ncfgs map[string]NotificationsCfg) {
t := newLightTable(out)
t.SetHeaders("Active", "Name", "Type", "Profile name")
t.SetHeaderAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft, table.AlignLeft)
t.SetAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft, table.AlignLeft)

keys := make([]string, 0, len(ncfgs))
for k := range ncfgs {
keys = append(keys, k)
}

sort.Slice(keys, func(i, j int) bool {
return len(ncfgs[keys[i]].Profiles) > len(ncfgs[keys[j]].Profiles)
})

for _, k := range keys {
b := ncfgs[k]
profilesList := []string{}

for _, p := range b.Profiles {
profilesList = append(profilesList, p.Name)
}
active := emoji.CheckMark.String()

active := emoji.CheckMark
if len(profilesList) == 0 {
active = emoji.Prohibited.String()
active = emoji.Prohibited
}

t.AddRow(active, b.Config.Name, b.Config.Type, strings.Join(profilesList, ", "))
}

t.Render()
}
5 changes: 4 additions & 1 deletion cmd/crowdsec-cli/utils_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"strconv"

"github.com/aquasecurity/table"
"github.com/enescakir/emoji"

"github.com/crowdsecurity/crowdsec/pkg/cwhub"
"github.com/crowdsecurity/crowdsec/pkg/emoji"
)

func listHubItemTable(out io.Writer, title string, items []*cwhub.Item) {
Expand All @@ -21,6 +21,7 @@ func listHubItemTable(out io.Writer, title string, items []*cwhub.Item) {
status := fmt.Sprintf("%v %s", item.State.Emoji(), item.State.Text())
t.AddRow(item.Name, status, item.State.LocalVersion, item.State.LocalPath)
}

renderTableTitle(out, title)
t.Render()
}
Expand All @@ -42,6 +43,7 @@ func scenarioMetricsTable(out io.Writer, itemName string, metrics map[string]int
if metrics["instantiation"] == 0 {
return
}

t := newTable(out)
t.SetHeaders("Current Count", "Overflows", "Instantiated", "Poured", "Expired")

Expand Down Expand Up @@ -72,6 +74,7 @@ func parserMetricsTable(out io.Writer, itemName string, metrics map[string]map[s
strconv.Itoa(stats["parsed"]),
strconv.Itoa(stats["unparsed"]),
)

showTable = true
}
}
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ require (
github.com/dghubble/sling v1.3.0
github.com/docker/docker v24.0.7+incompatible
github.com/docker/go-connections v0.4.0
github.com/enescakir/emoji v1.0.0
github.com/fatih/color v1.15.0
github.com/fsnotify/fsnotify v1.6.0
github.com/gin-gonic/gin v1.9.1
Expand Down Expand Up @@ -92,7 +91,6 @@ require (
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
gotest.tools/v3 v3.5.0
k8s.io/apiserver v0.28.4
)

Expand Down Expand Up @@ -210,6 +208,7 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gotest.tools/v3 v3.5.0 // indirect
k8s.io/api v0.28.4 // indirect
k8s.io/apimachinery v0.28.4 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDD
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/enescakir/emoji v1.0.0 h1:W+HsNql8swfCQFtioDGDHCHri8nudlK1n5p2rHCJoog=
github.com/enescakir/emoji v1.0.0/go.mod h1:Bt1EKuLnKDTYpLALApstIkAjdDrS/8IAgTkKp+WKFD0=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
Expand Down
Loading

0 comments on commit a23fe06

Please sign in to comment.