diff --git a/x-pack/filebeat/docs/inputs/input-httpjson.asciidoc b/x-pack/filebeat/docs/inputs/input-httpjson.asciidoc index 7b5417374ec..1e928773da2 100644 --- a/x-pack/filebeat/docs/inputs/input-httpjson.asciidoc +++ b/x-pack/filebeat/docs/inputs/input-httpjson.asciidoc @@ -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"]]` diff --git a/x-pack/filebeat/input/httpjson/internal/v2/value_tpl.go b/x-pack/filebeat/input/httpjson/internal/v2/value_tpl.go index fb0c20616f4..b6c74590b9d 100644 --- a/x-pack/filebeat/input/httpjson/internal/v2/value_tpl.go +++ b/x-pack/filebeat/input/httpjson/internal/v2/value_tpl.go @@ -56,6 +56,7 @@ func (t *valueTpl) Unpack(in string) error { "div": div, "hmac": hmacString, "base64Encode": base64Encode, + "base64EncodeNoPad": base64EncodeNoPad, }). Delims(leftDelim, rightDelim). Parse(in) @@ -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 == "" {