Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Sep 3, 2024
1 parent 07febf0 commit d49cdb2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
3 changes: 1 addition & 2 deletions cmd/crowdsec-cli/clialert/sanitize.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
"github.com/crowdsecurity/crowdsec/pkg/types"
)

// SanitizeScope validates ip and range and sets the scope accordingly if it's not already set.
// The return value has consistent case.
// SanitizeScope validates ip and range and sets the scope accordingly to our case convention.
func SanitizeScope(scope, ip, ipRange string) (string, error) {
if ipRange != "" {
_, _, err := net.ParseCIDR(ipRange)
Expand Down
4 changes: 2 additions & 2 deletions cmd/crowdsec-cli/clidecision/decisions_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ func (cli *cliDecisions) runImport(cmd *cobra.Command, args []string) error {
}

var (
content []byte
fin *os.File
content []byte
fin *os.File
)

// set format if the file has a json or csv extension
Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/controllers/v1/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ func (c *Controller) FindAlerts(gctx *gin.Context) {
// FindAlertByID returns the alert associated with the ID
func (c *Controller) FindAlertByID(gctx *gin.Context) {
alertIDStr := gctx.Param("alert_id")
alertID, err := strconv.Atoi(alertIDStr)

alertID, err := strconv.Atoi(alertIDStr)
if err != nil {
gctx.JSON(http.StatusBadRequest, gin.H{"message": "alert_id must be valid integer"})
return
Expand Down
23 changes: 15 additions & 8 deletions pkg/types/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ const (
// Event is the structure representing a runtime event (log or overflow)
type Event struct {
/* is it a log or an overflow */
Type int `yaml:"Type,omitempty" json:"Type,omitempty"` //Can be types.LOG (0) or types.OVFLOW (1)
ExpectMode int `yaml:"ExpectMode,omitempty" json:"ExpectMode,omitempty"` //how to buckets should handle event : types.TIMEMACHINE or types.LIVE
Type int `yaml:"Type,omitempty" json:"Type,omitempty"` // Can be types.LOG (0) or types.OVFLOW (1)
ExpectMode int `yaml:"ExpectMode,omitempty" json:"ExpectMode,omitempty"` // how to buckets should handle event : types.TIMEMACHINE or types.LIVE
Whitelisted bool `yaml:"Whitelisted,omitempty" json:"Whitelisted,omitempty"`
WhitelistReason string `yaml:"WhitelistReason,omitempty" json:"whitelist_reason,omitempty"`
//should add whitelist reason ?
// should add whitelist reason ?
/* the current stage of the line being parsed */
Stage string `yaml:"Stage,omitempty" json:"Stage,omitempty"`
/* original line (produced by acquisition) */
Expand All @@ -37,11 +37,11 @@ type Event struct {
Unmarshaled map[string]interface{} `yaml:"Unmarshaled,omitempty" json:"Unmarshaled,omitempty"`
/* Overflow */
Overflow RuntimeAlert `yaml:"Overflow,omitempty" json:"Alert,omitempty"`
Time time.Time `yaml:"Time,omitempty" json:"Time,omitempty"` //parsed time `json:"-"` ``
Time time.Time `yaml:"Time,omitempty" json:"Time,omitempty"` // parsed time `json:"-"` ``
StrTime string `yaml:"StrTime,omitempty" json:"StrTime,omitempty"`
StrTimeFormat string `yaml:"StrTimeFormat,omitempty" json:"StrTimeFormat,omitempty"`
MarshaledTime string `yaml:"MarshaledTime,omitempty" json:"MarshaledTime,omitempty"`
Process bool `yaml:"Process,omitempty" json:"Process,omitempty"` //can be set to false to avoid processing line
Process bool `yaml:"Process,omitempty" json:"Process,omitempty"` // can be set to false to avoid processing line
Appsec AppsecEvent `yaml:"Appsec,omitempty" json:"Appsec,omitempty"`
/* Meta is the only part that will make it to the API - it should be normalized */
Meta map[string]string `yaml:"Meta,omitempty" json:"Meta,omitempty"`
Expand All @@ -51,15 +51,19 @@ func (e *Event) SetMeta(key string, value string) bool {
if e.Meta == nil {
e.Meta = make(map[string]string)
}

e.Meta[key] = value

return true
}

func (e *Event) SetParsed(key string, value string) bool {
if e.Parsed == nil {
e.Parsed = make(map[string]string)
}

e.Parsed[key] = value

return true
}

Expand Down Expand Up @@ -91,11 +95,13 @@ func (e *Event) GetMeta(key string) string {
}
}
}

return ""
}

func (e *Event) ParseIPSources() []net.IP {
var srcs []net.IP

switch e.Type {
case LOG:
if _, ok := e.Meta["source_ip"]; ok {
Expand All @@ -106,6 +112,7 @@ func (e *Event) ParseIPSources() []net.IP {
srcs = append(srcs, net.ParseIP(k))
}
}

return srcs
}

Expand All @@ -132,8 +139,8 @@ type RuntimeAlert struct {
Whitelisted bool `yaml:"Whitelisted,omitempty" json:"Whitelisted,omitempty"`
Reprocess bool `yaml:"Reprocess,omitempty" json:"Reprocess,omitempty"`
Sources map[string]models.Source `yaml:"Sources,omitempty" json:"Sources,omitempty"`
Alert *models.Alert `yaml:"Alert,omitempty" json:"Alert,omitempty"` //this one is a pointer to APIAlerts[0] for convenience.
//APIAlerts will be populated at the end when there is more than one source
Alert *models.Alert `yaml:"Alert,omitempty" json:"Alert,omitempty"` // this one is a pointer to APIAlerts[0] for convenience.
// APIAlerts will be populated at the end when there is more than one source
APIAlerts []models.Alert `yaml:"APIAlerts,omitempty" json:"APIAlerts,omitempty"`
}

Expand All @@ -142,6 +149,7 @@ func (r RuntimeAlert) GetSources() []string {
for key := range r.Sources {
ret = append(ret, key)
}

return ret
}

Expand All @@ -159,4 +167,3 @@ func NormalizeScope(scope string) string {
return scope
}
}

0 comments on commit d49cdb2

Please sign in to comment.