Skip to content

Commit

Permalink
adding comments from PR
Browse files Browse the repository at this point in the history
  • Loading branch information
P1llus committed Sep 2, 2021
1 parent c910162 commit f5be1a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions x-pack/filebeat/docs/inputs/input-httpjson.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ Some built-in helper functions are provided to work with the input state inside
- `div`: does the integer division of two integer values.
- `hmac`: calculates the hmac signature of a list of strings concatenated together. Supports sha1 or sha256. Example `[[hmac "sha256" "secret" "string1" "string2" (formatDate (now) "RFC1123")]]`
- `base64Encode`: Joins and base64 encodes all supplied strings. Example `[[base64Encode "string1" "string2"]]`
- `base64EncodeNoPad`: Joins and base64 encodes all supplied strings without padding. Example `[[base64EncodeNoPad "string1" "string2"]]`

In addition to the provided functions, any of the native functions for https://golang.org/pkg/time/#Time[`time.Time`], https://golang.org/pkg/net/http/#Header[`http.Header`], and https://golang.org/pkg/net/url/#Values[`url.Values`] types can be used on the corresponding objects. Examples: `[[(now).Day]]`, `[[.last_response.header.Get "key"]]`

Expand Down
10 changes: 10 additions & 0 deletions x-pack/filebeat/input/httpjson/internal/v2/value_tpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (t *valueTpl) Unpack(in string) error {
"div": div,
"hmac": hmacString,
"base64Encode": base64Encode,
"base64EncodeNoPad": base64EncodeNoPad,
}).
Delims(leftDelim, rightDelim).
Parse(in)
Expand Down Expand Up @@ -254,6 +255,15 @@ func base64Encode(values ...string) string {
return base64.StdEncoding.EncodeToString([]byte(data))
}

func base64EncodeNoPad(values ...string) string {
data := strings.Join(values, "")
if data == "" {
return ""
}

return base64.RawStdEncoding.EncodeToString([]byte(data))
}

func hmacString(hmacType string, hmacKey string, values ...string) string {
data := strings.Join(values[:], "")
if data == "" {
Expand Down

0 comments on commit f5be1a9

Please sign in to comment.