Skip to content

Commit

Permalink
[Filebeat][httpjson] Fix date_cursor validation (elastic#21756) (elas…
Browse files Browse the repository at this point in the history
…tic#21982)

* Fix date_cursor validation

* Only check for parse errors

(cherry picked from commit 15251d4)
  • Loading branch information
marc-gr authored Oct 19, 2020
1 parent a403fe4 commit 330ae55
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions x-pack/filebeat/input/httpjson/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,15 @@ func (dc *DateCursor) Validate() error {
if dc.DateFormat == "" {
return nil
}
now := time.Now().Format(dc.DateFormat)
if _, err := time.Parse(dc.DateFormat, now); err != nil {

const knownTimestamp = 1602601228 // 2020-10-13T15:00:28+00:00 RFC3339
knownDate := time.Unix(knownTimestamp, 0).UTC()

dateStr := knownDate.Format(dc.DateFormat)
if _, err := time.Parse(dc.DateFormat, dateStr); err != nil {
return errors.New("invalid configuration: date_format is not a valid date layout")
}

return nil
}

Expand Down

0 comments on commit 330ae55

Please sign in to comment.