mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-10 20:05:55 +02:00
lint
This commit is contained in:
parent
531af79861
commit
b87a5e56e6
8 changed files with 48 additions and 37 deletions
|
@ -104,15 +104,15 @@ func (cli *cliAlerts) alertsToTable(alerts *models.GetAlertsResponse, printMachi
|
|||
if *alerts == nil {
|
||||
// avoid returning "null" in json
|
||||
// could be cleaner if we used slice of alerts directly
|
||||
fmt.Println("[]")
|
||||
fmt.Fprintln(os.Stdout, "[]")
|
||||
return nil
|
||||
}
|
||||
|
||||
x, _ := json.MarshalIndent(alerts, "", " ")
|
||||
fmt.Print(string(x))
|
||||
fmt.Fprint(os.Stdout, string(x))
|
||||
case "human":
|
||||
if len(*alerts) == 0 {
|
||||
fmt.Println("No active alerts")
|
||||
fmt.Fprintln(os.Stdout, "No active alerts")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ func (cli *cliAlerts) displayOneAlert(alert *models.Alert, withDetail bool) erro
|
|||
alertDecisionsTable(color.Output, cfg.Cscli.Color, alert)
|
||||
|
||||
if len(alert.Meta) > 0 {
|
||||
fmt.Printf("\n - Context :\n")
|
||||
fmt.Fprintf(os.Stdout, "\n - Context :\n")
|
||||
sort.Slice(alert.Meta, func(i, j int) bool {
|
||||
return alert.Meta[i].Key < alert.Meta[j].Key
|
||||
})
|
||||
|
@ -183,7 +183,7 @@ func (cli *cliAlerts) displayOneAlert(alert *models.Alert, withDetail bool) erro
|
|||
}
|
||||
|
||||
if withDetail {
|
||||
fmt.Printf("\n - Events :\n")
|
||||
fmt.Fprintf(os.Stdout, "\n - Events :\n")
|
||||
|
||||
for _, event := range alert.Events {
|
||||
alertEventTable(color.Output, cfg.Cscli.Color, event)
|
||||
|
@ -451,14 +451,14 @@ func (cli *cliAlerts) inspect(ctx context.Context, details bool, alertIDs ...str
|
|||
return fmt.Errorf("unable to serialize alert with id %s: %w", alertID, err)
|
||||
}
|
||||
|
||||
fmt.Printf("%s\n", string(data))
|
||||
fmt.Fprintln(os.Stdout, string(data))
|
||||
case "raw":
|
||||
data, err := yaml.Marshal(alert)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to serialize alert with id %s: %w", alertID, err)
|
||||
}
|
||||
|
||||
fmt.Println(string(data))
|
||||
fmt.Fprintln(os.Stdout, string(data))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -488,7 +488,7 @@ func (cli *cliAlerts) newInspectCmd() *cobra.Command {
|
|||
func (cli *cliAlerts) newFlushCmd() *cobra.Command {
|
||||
var maxItems int
|
||||
|
||||
maxAge := cstime.DurationWithDays(7*24*time.Hour)
|
||||
maxAge := cstime.DurationWithDays(7 * 24 * time.Hour)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: `flush`,
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"os"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -283,7 +284,7 @@ func (cli *cliAllowLists) create(ctx context.Context, db *database.Client, name
|
|||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("allowlist '%s' created successfully\n", name)
|
||||
fmt.Fprintf(os.Stdout, "allowlist '%s' created successfully\n", name)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -392,7 +393,7 @@ func (cli *cliAllowLists) delete(ctx context.Context, db *database.Client, name
|
|||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("allowlist '%s' deleted successfully\n", name)
|
||||
fmt.Fprintf(os.Stdout, "allowlist '%s' deleted successfully\n", name)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -475,7 +476,7 @@ func (cli *cliAllowLists) add(ctx context.Context, db *database.Client, name str
|
|||
}
|
||||
|
||||
if len(toAdd) == 0 {
|
||||
fmt.Println("no new values for allowlist")
|
||||
fmt.Fprintln(os.Stdout, "no new values for allowlist")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -485,7 +486,7 @@ func (cli *cliAllowLists) add(ctx context.Context, db *database.Client, name str
|
|||
}
|
||||
|
||||
if added > 0 {
|
||||
fmt.Printf("added %d values to allowlist %s\n", added, name)
|
||||
fmt.Fprintf(os.Stdout, "added %d values to allowlist %s\n", added, name)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -614,7 +615,7 @@ func (cli *cliAllowLists) remove(ctx context.Context, db *database.Client, name
|
|||
}
|
||||
|
||||
if len(toRemove) == 0 {
|
||||
fmt.Println("no value to remove from allowlist")
|
||||
fmt.Fprintln(os.Stdout, "no value to remove from allowlist")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -624,7 +625,7 @@ func (cli *cliAllowLists) remove(ctx context.Context, db *database.Client, name
|
|||
}
|
||||
|
||||
if deleted > 0 {
|
||||
fmt.Printf("removed %d values from allowlist %s", deleted, name)
|
||||
fmt.Fprintf(os.Stdout, "removed %d values from allowlist %s", deleted, name)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -103,22 +103,22 @@ func (cli *cliDecisions) decisionsToTable(alerts *models.GetAlertsResponse, prin
|
|||
if *alerts == nil {
|
||||
// avoid returning "null" in `json"
|
||||
// could be cleaner if we used slice of alerts directly
|
||||
fmt.Println("[]")
|
||||
fmt.Fprintln(os.Stdout, "[]")
|
||||
return nil
|
||||
}
|
||||
|
||||
x, _ := json.MarshalIndent(alerts, "", " ")
|
||||
fmt.Printf("%s", string(x))
|
||||
fmt.Fprintln(os.Stdout, string(x))
|
||||
case "human":
|
||||
if len(*alerts) == 0 {
|
||||
fmt.Println("No active decisions")
|
||||
fmt.Fprintln(os.Stdout, "No active decisions")
|
||||
return nil
|
||||
}
|
||||
|
||||
cli.decisionsTable(color.Output, alerts, printMachine)
|
||||
|
||||
if skipped > 0 {
|
||||
fmt.Printf("%d duplicated entries skipped\n", skipped)
|
||||
fmt.Fprintf(os.Stdout, "%d duplicated entries skipped\n", skipped)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,14 +15,14 @@ import (
|
|||
type AlertsService service
|
||||
|
||||
type AlertsListOpts struct {
|
||||
ScopeEquals string `url:"scope,omitempty"`
|
||||
ValueEquals string `url:"value,omitempty"`
|
||||
ScenarioEquals string `url:"scenario,omitempty"`
|
||||
IPEquals string `url:"ip,omitempty"`
|
||||
RangeEquals string `url:"range,omitempty"`
|
||||
OriginEquals string `url:"origin,omitempty"`
|
||||
ScopeEquals string `url:"scope,omitempty"`
|
||||
ValueEquals string `url:"value,omitempty"`
|
||||
ScenarioEquals string `url:"scenario,omitempty"`
|
||||
IPEquals string `url:"ip,omitempty"`
|
||||
RangeEquals string `url:"range,omitempty"`
|
||||
OriginEquals string `url:"origin,omitempty"`
|
||||
Since cstime.DurationWithDays `url:"since,omitempty"`
|
||||
TypeEquals string `url:"decision_type,omitempty"`
|
||||
TypeEquals string `url:"decision_type,omitempty"`
|
||||
Until cstime.DurationWithDays `url:"until,omitempty"`
|
||||
IncludeSimulated *bool `url:"simulated,omitempty"`
|
||||
ActiveDecisionEquals *bool `url:"has_active_decision,omitempty"`
|
||||
|
@ -33,16 +33,16 @@ type AlertsListOpts struct {
|
|||
}
|
||||
|
||||
type AlertsDeleteOpts struct {
|
||||
ScopeEquals string `url:"scope,omitempty"`
|
||||
ValueEquals string `url:"value,omitempty"`
|
||||
ScenarioEquals string `url:"scenario,omitempty"`
|
||||
IPEquals string `url:"ip,omitempty"`
|
||||
RangeEquals string `url:"range,omitempty"`
|
||||
ScopeEquals string `url:"scope,omitempty"`
|
||||
ValueEquals string `url:"value,omitempty"`
|
||||
ScenarioEquals string `url:"scenario,omitempty"`
|
||||
IPEquals string `url:"ip,omitempty"`
|
||||
RangeEquals string `url:"range,omitempty"`
|
||||
Since cstime.DurationWithDays `url:"since,omitempty"`
|
||||
Until cstime.DurationWithDays `url:"until,omitempty"`
|
||||
OriginEquals string `url:"origin,omitempty"`
|
||||
OriginEquals string `url:"origin,omitempty"`
|
||||
ActiveDecisionEquals *bool `url:"has_active_decision,omitempty"`
|
||||
SourceEquals string `url:"alert_source,omitempty"`
|
||||
SourceEquals string `url:"alert_source,omitempty"`
|
||||
Contains *bool `url:"contains,omitempty"`
|
||||
Limit *int `url:"limit,omitempty"`
|
||||
ListOpts
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
|
||||
func TestAlertsListAsMachine(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
|
||||
log.SetLevel(log.DebugLevel)
|
||||
|
||||
mux, urlx, teardown := setup()
|
||||
|
@ -199,6 +200,7 @@ func TestAlertsListAsMachine(t *testing.T) {
|
|||
|
||||
func TestAlertsGetAsMachine(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
|
||||
log.SetLevel(log.DebugLevel)
|
||||
|
||||
mux, urlx, teardown := setup()
|
||||
|
@ -367,6 +369,7 @@ func TestAlertsGetAsMachine(t *testing.T) {
|
|||
|
||||
func TestAlertsCreateAsMachine(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
|
||||
log.SetLevel(log.DebugLevel)
|
||||
|
||||
mux, urlx, teardown := setup()
|
||||
|
@ -410,6 +413,7 @@ func TestAlertsCreateAsMachine(t *testing.T) {
|
|||
|
||||
func TestAlertsDeleteAsMachine(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
|
||||
log.SetLevel(log.DebugLevel)
|
||||
|
||||
mux, urlx, teardown := setup()
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
|
||||
func TestApiAuth(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
|
||||
log.SetLevel(log.TraceLevel)
|
||||
|
||||
mux, urlx, teardown := setup()
|
||||
|
@ -39,7 +40,7 @@ func TestApiAuth(t *testing.T) {
|
|||
|
||||
defer teardown()
|
||||
|
||||
//ok no answer
|
||||
// ok no answer
|
||||
auth := &APIKeyTransport{
|
||||
APIKey: "ixu",
|
||||
}
|
||||
|
@ -52,7 +53,7 @@ func TestApiAuth(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, resp.Response.StatusCode)
|
||||
|
||||
//ko bad token
|
||||
// ko bad token
|
||||
auth = &APIKeyTransport{
|
||||
APIKey: "bad",
|
||||
}
|
||||
|
@ -68,7 +69,7 @@ func TestApiAuth(t *testing.T) {
|
|||
|
||||
cstest.RequireErrorMessage(t, err, "API error: access forbidden")
|
||||
|
||||
//ko empty token
|
||||
// ko empty token
|
||||
auth = &APIKeyTransport{}
|
||||
|
||||
newcli, err = NewDefaultClient(apiURL, "v1", "toto", auth.Client())
|
||||
|
|
|
@ -25,7 +25,7 @@ type DecisionsListOpts struct {
|
|||
TypeEquals string `url:"type,omitempty"`
|
||||
IPEquals string `url:"ip,omitempty"`
|
||||
RangeEquals string `url:"range,omitempty"`
|
||||
Contains *bool `url:"contains,omitempty"`
|
||||
Contains *bool `url:"contains,omitempty"`
|
||||
ListOpts
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ type DecisionsDeleteOpts struct {
|
|||
TypeEquals string `url:"type,omitempty"`
|
||||
IPEquals string `url:"ip,omitempty"`
|
||||
RangeEquals string `url:"range,omitempty"`
|
||||
Contains *bool `url:"contains,omitempty"`
|
||||
Contains *bool `url:"contains,omitempty"`
|
||||
OriginEquals string `url:"origin,omitempty"`
|
||||
//
|
||||
ScenarioEquals string `url:"scenario,omitempty"`
|
||||
|
|
|
@ -19,6 +19,7 @@ import (
|
|||
|
||||
func TestDecisionsList(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
|
||||
log.SetLevel(log.DebugLevel)
|
||||
|
||||
mux, urlx, teardown := setup()
|
||||
|
@ -78,6 +79,7 @@ func TestDecisionsList(t *testing.T) {
|
|||
|
||||
func TestDecisionsStream(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
|
||||
log.SetLevel(log.DebugLevel)
|
||||
|
||||
mux, urlx, teardown := setup()
|
||||
|
@ -154,6 +156,7 @@ func TestDecisionsStream(t *testing.T) {
|
|||
|
||||
func TestDecisionsStreamV3Compatibility(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
|
||||
log.SetLevel(log.DebugLevel)
|
||||
|
||||
mux, urlx, teardown := setupWithPrefix("v3")
|
||||
|
@ -222,6 +225,7 @@ func TestDecisionsStreamV3Compatibility(t *testing.T) {
|
|||
|
||||
func TestDecisionsStreamV3(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
|
||||
log.SetLevel(log.DebugLevel)
|
||||
|
||||
mux, urlx, teardown := setupWithPrefix("v3")
|
||||
|
@ -295,6 +299,7 @@ func TestDecisionsStreamV3(t *testing.T) {
|
|||
|
||||
func TestDecisionsFromBlocklist(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
|
||||
log.SetLevel(log.DebugLevel)
|
||||
|
||||
mux, urlx, teardown := setupWithPrefix("v3")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue