Skip to content

Commit

Permalink
docs(vrl): Add documentation for parse_proto and encode_proto (#20139)
Browse files Browse the repository at this point in the history
* docs(vrl): Add documentation for parse_proto and encode_proto (vectordotdev/vrl#739)

* Add spellcheck exception

Signed-off-by: Jesse Szwedko <[email protected]>

* Add ignore pattern for base64

Signed-off-by: Jesse Szwedko <[email protected]>

* Update pattern

Signed-off-by: Jesse Szwedko <[email protected]>

* Fix pattern

Signed-off-by: Jesse Szwedko <[email protected]>

* another try

Signed-off-by: Jesse Szwedko <[email protected]>

* cue formatting

Signed-off-by: Jesse Szwedko <[email protected]>

* update tests

Signed-off-by: Jesse Szwedko <[email protected]>

* Ignore desc files in syntax check

Signed-off-by: Jesse Szwedko <[email protected]>

---------

Signed-off-by: Jesse Szwedko <[email protected]>
Co-authored-by: Jesse Szwedko <[email protected]>
  • Loading branch information
flavioc and jszwedko committed Mar 25, 2024
1 parent 4d23e66 commit 4279bf0
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/actions/spelling/patterns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ user:P@ssw0rd
# Ignore base64 encoded values in Prometheus Pushgateway URL paths
/.+@base64/.+

# Ignore base64 encoded values in VRL examples (requires padding to avoid false positives)
"[A-Za-z0-9]*=="

# Ignore punycode
\bxn--[-0-9a-z]+

Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions scripts/check-style.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ for FILE in $(git ls-files); do
*ico) continue;;
*sig) continue;;
*html) continue;;
*desc) continue;;
tests/data*) continue;;
lib/codecs/tests/data*) continue;;
lib/vector-core/tests/data*) continue;;
Expand Down
52 changes: 52 additions & 0 deletions website/cue/reference/remap/functions/encode_proto.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package metadata

remap: functions: encode_proto: {
category: "Codec"
description: """
Encodes the `value` into a protocol buffer payload.
"""

arguments: [
{
name: "value"
description: "The object to convert to a protocol buffer payload."
required: true
type: ["object"]
},
{
name: "desc_file"
description: """
The path to the protobuf descriptor set file. Must be a literal string.
This file is the output of protoc -o <path> ...
"""
required: true
type: ["string"]
},
{
name: "message_type"
description: """
The name of the message type to use for serializing.
Must be a literal string.
"""
required: true
type: ["string"]
},
]
internal_failure_reasons: [
"`desc_file` file does not exist.",
"`message_type` message type does not exist in the descriptor file.",
]
return: types: ["string"]

examples: [
{
title: "Encode to proto"
source: #"""
.payload = encode_base64(encode_proto!({"name": "someone", "phones": [{"number": "123456"}]}, "resources/protobuf_descriptor_set.desc", "test_protobuf.Person"))
"""#
return: #"Cgdzb21lb25lIggKBjEyMzQ1Ng=="#
},
]
}
65 changes: 65 additions & 0 deletions website/cue/reference/remap/functions/parse_proto.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package metadata

remap: functions: parse_proto: {
category: "Parse"
description: """
Parses the `value` as a protocol buffer payload.
"""
notices: [
"""
Only proto messages are parsed and returned.
""",
]

arguments: [
{
name: "value"
description: "The protocol buffer payload to parse."
required: true
type: ["string"]
},
{
name: "desc_file"
description: """
The path to the protobuf descriptor set file. Must be a literal string.
This file is the output of protoc -o <path> ...
"""
required: true
type: ["string"]
},
{
name: "message_type"
description: """
The name of the message type to use for serializing.
Must be a literal string.
"""
required: true
type: ["string"]
},
]
internal_failure_reasons: [
"`value` is not a valid proto payload.",
"`desc_file` file does not exist.",
"`message_type` message type does not exist in the descriptor file.",
]
return: types: ["object"]

examples: [
{
title: "Parse proto"
source: #"""
parse_proto!(decode_base64!("Cgdzb21lb25lIggKBjEyMzQ1Ng=="), "resources/protobuf_descriptor_set.desc", "test_protobuf.Person")
"""#
return: {
name: "someone"
phones: [
{
number: "123456"
},
]
}
},
]
}

0 comments on commit 4279bf0

Please sign in to comment.