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

Remove timeDuration #81

Merged
merged 5 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 4 additions & 1 deletion assets/templates/aws.vpcflow/schema-a/gotext.tpl
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
{{generate "Version"}} {{generate "AccountID"}} {{generate "InterfaceID"}} {{generate "SrcAddr"}} {{generate "DstAddr"}} {{generate "SrcPort"}} {{generate "DstPort"}} {{generate "Protocol"}}{{ $packets := generate "Packets" }} {{ $packets }} {{mul $packets 15 }} {{$startOffset := generate "StartOffset" }}{{$startOffsetInSecond := mul -1 1000000000 $startOffset }}{{$startOffsetDuration := timeDuration $startOffsetInSecond}}{{$end := generate "End" }}{{$start := $end.Add $startOffsetDuration}}{{$start.Format "2006-01-02T15:04:05.999999Z07:00" }} {{$end.Format "2006-01-02T15:04:05.999999Z07:00"}} {{generate "Action"}}{{ if eq $packets 0 }} NODATA {{ else }} {{generate "LogStatus"}} {{ end }}
{{- $startOffset := generate "StartOffset" }}
{{- $end := generate "End" }}
{{- $start := mul -1 $startOffset | int64 | duration | $end.Add }}
aspacca marked this conversation as resolved.
Show resolved Hide resolved
{{generate "Version"}} {{generate "AccountID"}} {{generate "InterfaceID"}} {{generate "SrcAddr"}} {{generate "DstAddr"}} {{generate "SrcPort"}} {{generate "DstPort"}} {{generate "Protocol"}}{{ $packets := generate "Packets" }} {{ $packets }} {{mul $packets 15 }} {{$start.Format "2006-01-02T15:04:05.999999Z07:00" }} {{$end.Format "2006-01-02T15:04:05.999999Z07:00"}} {{generate "Action"}}{{ if eq $packets 0 }} NODATA {{ else }} {{generate "LogStatus"}} {{ end }}
6 changes: 0 additions & 6 deletions docs/writing-templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,3 @@ This is equivalent to the following when using the `placeholder` template type:

#### sprig functions
The template loads the functions provided by sprig (https://masterminds.github.io/sprig/) with the exclusion of the functions are not guaranteed to evaluate to the same result for given input (https://github.com/Masterminds/sprig/blob/581758eb7d96ae4d113649668fa96acc74d46e7f/functions.go#L68-L95)

#### "timeDuration" function
The template provides a function named "timeDuration" that accept an int64 and return equivalent `time.Duration`, for example the following will render `5s`:
```text
{{$timeDuration := timeDuration 5000000000}}{{$timeDuration}}
```
5 changes: 0 additions & 5 deletions pkg/genlib/generator_with_text_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"io"
"math/rand"
"text/template"
"time"

"github.com/Masterminds/sprig/v3"
)
Expand Down Expand Up @@ -127,10 +126,6 @@ func NewGeneratorWithTextTemplate(tpl []byte, cfg Config, fields Fields, totSize

templateFns := sprig.TxtFuncMap()

templateFns["timeDuration"] = func(duration int64) time.Duration {
return time.Duration(duration)
}

templateFns["awsAZFromRegion"] = func(region string) string {
azs, ok := awsAZs[region]
if !ok {
Expand Down