Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add method to check falco payload #372

Merged
merged 1 commit into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func mainHandler(w http.ResponseWriter, r *http.Request) {
}

falcopayload, err := newFalcoPayload(r.Body)
if err != nil || len(falcopayload.Output) == 0 {
if err != nil || !falcopayload.Check() {
http.Error(w, "Please send a valid request body", http.StatusBadRequest)
stats.Requests.Add("rejected", 1)
promStats.Inputs.With(map[string]string{"source": "requests", "status": "rejected"}).Inc()
Expand Down
16 changes: 16 additions & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ func (f FalcoPayload) String() string {
return string(j)
}

func (f FalcoPayload) Check() bool {
if f.Priority.String() == "" {
return false
}
if f.Rule == "" {
return false
}
if f.Time.IsZero() {
return false
}
if len(f.OutputFields) == 0 {
return false
}
return true
}

// Configuration is a struct to store configuration
type Configuration struct {
MutualTLSFilesPath string
Expand Down