diff --git a/cmd/crowdsec-cli/clialert/alerts.go b/cmd/crowdsec-cli/clialert/alerts.go index 39b8bb376..cd9e636ee 100644 --- a/cmd/crowdsec-cli/clialert/alerts.go +++ b/cmd/crowdsec-cli/clialert/alerts.go @@ -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`, diff --git a/cmd/crowdsec-cli/cliallowlists/allowlists.go b/cmd/crowdsec-cli/cliallowlists/allowlists.go index 972ee1b47..7dabbde07 100644 --- a/cmd/crowdsec-cli/cliallowlists/allowlists.go +++ b/cmd/crowdsec-cli/cliallowlists/allowlists.go @@ -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 diff --git a/cmd/crowdsec-cli/clidecision/decisions.go b/cmd/crowdsec-cli/clidecision/decisions.go index ed0ce6078..c5a67582d 100644 --- a/cmd/crowdsec-cli/clidecision/decisions.go +++ b/cmd/crowdsec-cli/clidecision/decisions.go @@ -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) } } diff --git a/pkg/apiclient/alerts_service.go b/pkg/apiclient/alerts_service.go index 14a3564be..4d30e5976 100644 --- a/pkg/apiclient/alerts_service.go +++ b/pkg/apiclient/alerts_service.go @@ -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 diff --git a/pkg/apiclient/alerts_service_test.go b/pkg/apiclient/alerts_service_test.go index 236fb66da..eed1598c8 100644 --- a/pkg/apiclient/alerts_service_test.go +++ b/pkg/apiclient/alerts_service_test.go @@ -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() diff --git a/pkg/apiclient/auth_key_test.go b/pkg/apiclient/auth_key_test.go index 3c70873c1..1e5f95acc 100644 --- a/pkg/apiclient/auth_key_test.go +++ b/pkg/apiclient/auth_key_test.go @@ -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()) diff --git a/pkg/apiclient/decisions_service.go b/pkg/apiclient/decisions_service.go index e579645ea..c222e2ddb 100644 --- a/pkg/apiclient/decisions_service.go +++ b/pkg/apiclient/decisions_service.go @@ -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"` diff --git a/pkg/apiclient/decisions_service_test.go b/pkg/apiclient/decisions_service_test.go index 7ac609a88..c9e555e92 100644 --- a/pkg/apiclient/decisions_service_test.go +++ b/pkg/apiclient/decisions_service_test.go @@ -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")