diff --git a/plugins/cloudtrail/go.mod b/plugins/cloudtrail/go.mod index 403cdd9d..88b3ea97 100644 --- a/plugins/cloudtrail/go.mod +++ b/plugins/cloudtrail/go.mod @@ -13,5 +13,4 @@ require ( github.com/aws/smithy-go v1.13.3 github.com/falcosecurity/plugin-sdk-go v0.6.2 github.com/valyala/fastjson v1.6.3 - github.com/xhit/go-str2duration/v2 v2.1.0 ) diff --git a/plugins/cloudtrail/go.sum b/plugins/cloudtrail/go.sum index 8b3aee8c..aa1e0725 100644 --- a/plugins/cloudtrail/go.sum +++ b/plugins/cloudtrail/go.sum @@ -73,8 +73,6 @@ github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2 github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= -github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc= -github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/plugins/cloudtrail/pkg/cloudtrail/interval.go b/plugins/cloudtrail/pkg/cloudtrail/interval.go index d4cb0d92..72a30e3f 100644 --- a/plugins/cloudtrail/pkg/cloudtrail/interval.go +++ b/plugins/cloudtrail/pkg/cloudtrail/interval.go @@ -18,9 +18,8 @@ package cloudtrail import ( "regexp" + "strconv" "time" - - "github.com/xhit/go-str2duration/v2" ) var RFC3339Simple = "2006-01-02T03:04:05Z" @@ -30,10 +29,24 @@ func parseEndpoint(endpoint string) (time.Time, error) { var endpointTime time.Time var err error - epRE := regexp.MustCompile(`^\d+[wdhms]$`) - if (epRE.MatchString(endpoint)) { - duration, err := str2duration.ParseDuration(endpoint) - if (err == nil) { + durationRE := regexp.MustCompile(`^(\d+)([wdhms])$`) + matches := durationRE.FindStringSubmatch(endpoint) + if matches != nil { + durI, err := strconv.Atoi(matches[1]) + if err == nil { + duration := time.Duration(durI) + switch matches[2] { + case "w": + duration *= time.Hour * 24 * 7 + case "d": + duration *= time.Hour * 24 + case "h": + duration *= time.Hour + case "m": + duration *= time.Minute + case "s": + duration *= time.Second + } endpointTime = utc.Add(- duration) } } else { @@ -49,12 +62,12 @@ func ParseInterval(interval string) (time.Time, time.Time, error) { var err error // First, see if we have an interval. - intervalRE := regexp.MustCompile(`(.*)(\s*-\s*)(\d+[wdhms]$|\d{4}-\d{2}\d{2}[^Z]*Z)`) + intervalRE := regexp.MustCompile(`(.*)\s*-\s*(\d+[wdhms]|\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z)$`) matches := intervalRE.FindStringSubmatch(interval) if matches != nil { startTime, err = parseEndpoint(matches[1]) if err == nil { - endTime, err = parseEndpoint(matches[3]) + endTime, err = parseEndpoint(matches[2]) } } else { startTime, err = parseEndpoint(interval)